mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-10 00:25:59 +00:00
118 lines
2.2 KiB
C++
118 lines
2.2 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 <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::list<uint16_t> 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<std::shared_ptr<TacosThread>> threads_[STA_TACOS_NUM_STATES];
|
|
};
|
|
} // namespace tacos
|
|
} // namespace sta
|
|
|
|
#endif // STA_TACOS_MANAGER_PRIORITY
|
|
|
|
#endif /* INCLUDE_STA_TACOS_MANAGER_HPP_ */
|