TACOS/include/sta/tacos/manager.hpp
2024-02-07 19:19:13 +01:00

125 lines
2.4 KiB
C++

/*
* manager.hpp
*
* Created on: Sep 19, 2023
* Author: Dario
*/
#ifndef INCLUDE_STA_TACOS_MANAGER_HPP_
#define INCLUDE_STA_TACOS_MANAGER_HPP_
#include <sta/config.hpp>
#if !defined(STA_TACOS_MANAGER_PRIORITY) && !defined(DOXYGEN)
# error "Manger task priority not specified in config.hpp"
#else
#include <set>
#include <list>
#include <vector>
#include <memory>
#include <sta/tacos/thread.hpp>
/**
* @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<TacosThread> thread, std::set<uint16_t> states);
/**
* @brief Get the Active Threads object
*
* @return std::vector<std::shared_ptr<TacosThread>>
*/
std::vector<std::shared_ptr<TacosThread>> getActiveThreads();
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::vector<std::shared_ptr<TacosThread>> threads_[STA_TACOS_NUM_STATES];
};
} // namespace tacos
} // namespace sta
#endif // STA_TACOS_MANAGER_PRIORITY
#endif /* INCLUDE_STA_TACOS_MANAGER_HPP_ */