/* * manager.hpp * * Created on: Sep 19, 2023 * Author: Dario */ #ifndef INCLUDE_STA_TACOS_MANAGER_HPP_ #define INCLUDE_STA_TACOS_MANAGER_HPP_ #include #if !defined(STA_TACOS_MANAGER_PRIORITY) && !defined(DOXYGEN) # error "Manger task priority not specified in config.hpp" #else #include #include #include #include /** * @defgroup tacos_manager Manager Task * @ingroup tacos * @brief Manager task for TACOS. */ namespace sta { namespace tacos { /** * @brief Manager class for Tacos. * * @ingroup tacos_manager */ class Manager : public TacosThread { public: /** * @brief Get the singleton instance of the manager. * * @ingroup tacos_manager */ static Manager* instance() { static CGuard g; if (!_instance) { // Create a the manager singleton instance. Manager::_instance = new Manager(); } return _instance; } /** * @brief Register a thread to be managed by the manager. */ void registerThread(std::shared_ptr thread, std::list states); void init() override; void func() override; private: static Manager* _instance; class CGuard { public: ~CGuard() { if( NULL != Manager::_instance ) { delete Manager::_instance; Manager::_instance = NULL; } } }; Manager(); Manager(const Manager&); //~Manager(); /** * @brief Forces only threads of current state to run. */ void updateThreads(); /** * @brief Starts all threads which should be running in the given state. Does nothing if the state is already running. */ void startThreads(uint16_t state); /** * @brief Stops all threads which should not be running in the given state. */ void stopThreads(uint16_t state); /** * @brief Pointers to all threads which are managed by the manager. * * @ingroup tacos_manager */ std::set> threads_[STA_TACOS_NUM_STATES]; }; } // namespace tacos } // namespace sta #endif // STA_TACOS_MANAGER_PRIORITY #endif /* INCLUDE_STA_TACOS_MANAGER_HPP_ */