TACOS/Tacos/include/sta/tacos/manager.hpp

87 lines
1.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>
#ifndef STA_TACOS_MANAGER_PRIORITY
# error "Manger task priority not specified in config.hpp"
#else
#include <list>
#include <set>
#include <sta/tacos/thread.hpp>
namespace sta
{
namespace tacos
{
class Manager : public TacosThread
{
public:
static Manager* instance()
{
static CGuard g;
if (!_instance)
{
// Create a the manager singleton instance.
Manager::_instance = new Manager();
// Start the manager task as a tacos task.
Manager::_instance->start();
}
return _instance;
}
void registerThread(TacosThread thread, std::list<uint16_t> states);
void init() override;
void func() override;
private:
class CGuard
{
public:
~CGuard()
{
if( NULL != Manager::_instance )
{
delete Manager::_instance;
Manager::_instance = NULL;
}
}
};
static Manager* _instance;
Manager();
Manager(const Manager&);
~Manager() {}
void updateThreads();
void startThreads(uint16_t state);
void stopThreads(uint16_t state);
std::set<TacosThread> threads_[STA_TACOS_NUM_STATES];
};
} // namespace tacos
} // namespace sta
#endif // STA_TACOS_MANAGER_PRIORITY
#endif /* INCLUDE_STA_TACOS_MANAGER_HPP_ */