diff options
Diffstat (limited to 'include/distortos/internal/scheduler/SoftwareTimerControlBlock.hpp')
-rw-r--r-- | include/distortos/internal/scheduler/SoftwareTimerControlBlock.hpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/include/distortos/internal/scheduler/SoftwareTimerControlBlock.hpp b/include/distortos/internal/scheduler/SoftwareTimerControlBlock.hpp new file mode 100644 index 0000000..c020d35 --- /dev/null +++ b/include/distortos/internal/scheduler/SoftwareTimerControlBlock.hpp @@ -0,0 +1,111 @@ +/** + * \file + * \brief SoftwareTimerControlBlock class header + * + * \author Copyright (C) 2014-2015 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info + * + * \par License + * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not + * distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_SOFTWARETIMERCONTROLBLOCK_HPP_ +#define INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_SOFTWARETIMERCONTROLBLOCK_HPP_ + +#include "distortos/internal/scheduler/SoftwareTimerListNode.hpp" + +namespace distortos +{ + +class SoftwareTimer; + +namespace internal +{ + +/// SoftwareTimerControlBlock class is a control block of software timer +class SoftwareTimerControlBlock : public SoftwareTimerListNode +{ +public: + + /// type of runner for software timer's function + using FunctionRunner = void(SoftwareTimer&); + + /** + * \brief SoftwareTimerControlBlock's constructor + * + * \param [in] functionRunner is a reference to runner for software timer's function + * \param [in] owner is a reference to SoftwareTimer object that owns this SoftwareTimerControlBlock + */ + + constexpr SoftwareTimerControlBlock(FunctionRunner& functionRunner, SoftwareTimer& owner) : + SoftwareTimerListNode{}, + functionRunner_{functionRunner}, + owner_{owner} + { + + } + + /** + * \brief SoftwareTimerControlBlock's destructor + * + * If the timer is running it is stopped. + */ + + ~SoftwareTimerControlBlock() + { + stop(); + } + + /** + * \return true if the timer is running, false otherwise + */ + + bool isRunning() const + { + return node.isLinked(); + } + + /** + * \brief Runs software timer's function. + * + * \note this should only be called by SoftwareTimerSupervisor::tickInterruptHandler() + */ + + void run() const + { + functionRunner_(owner_); + } + + /** + * \brief Starts the timer. + * + * \param [in] timePoint is the time point at which the function will be executed + */ + + void start(TickClock::time_point timePoint); + + /** + * \brief Stops the timer. + */ + + void stop(); + + SoftwareTimerControlBlock(const SoftwareTimerControlBlock&) = delete; + SoftwareTimerControlBlock(SoftwareTimerControlBlock&&) = default; + const SoftwareTimerControlBlock& operator=(const SoftwareTimerControlBlock&) = delete; + SoftwareTimerControlBlock& operator=(SoftwareTimerControlBlock&&) = delete; + +private: + + /// reference to runner for software timer's function + FunctionRunner& functionRunner_; + + /// reference to SoftwareTimer object that owns this SoftwareTimerControlBlock + SoftwareTimer& owner_; +}; + +} // namespace internal + +} // namespace distortos + +#endif // INCLUDE_DISTORTOS_INTERNAL_SCHEDULER_SOFTWARETIMERCONTROLBLOCK_HPP_ |