5#ifndef CCF_MPTK_MANAGER_HPP_
6#define CCF_MPTK_MANAGER_HPP_
8#include <ifw/core/utils/system/system.hpp>
42 int16_t
WaitForThreadTerm(
const double time_out = ifw::core::utils::base::NO_TIMEOUT);
55 template <
class THREAD_TYPE>
57 const double period = 0.1,
58 THREAD_TYPE** thread_obj =
nullptr) {
61 BEGIN_CRIT_SEC(m_mgr_id) {
62 m_threads[thread_name] = std::make_shared<THREAD_TYPE>(thread_name,
MsgBus(), period);
63 if (m_threads[thread_name].get() ==
nullptr) {
64 throw rad::Exception(fmt::format(
"Could not create thread with ID: %s in MPTK instance",
65 thread_name.c_str()));
69 if (thread_obj !=
nullptr) {
70 *thread_obj =
static_cast<THREAD_TYPE*
>(m_threads[thread_name].get());
76 template <
class THREAD_TYPE>
78 const std::string& thread_name,
79 const double period = 0.1,
80 THREAD_TYPE** thread_obj =
nullptr) {
83 BEGIN_CRIT_SEC(m_mgr_id) {
84 m_threads[thread_name] = std::make_shared<THREAD_TYPE>(thread_name,
MsgBus(), period);
85 if (m_threads[thread_name].get() ==
nullptr) {
86 throw rad::Exception(fmt::format(
"Could not create thread with ID: %s in MPTK instance",
87 thread_name.c_str()));
91 if (thread_obj !=
nullptr) {
92 *thread_obj =
static_cast<THREAD_TYPE*
>(m_threads[thread_name].get());
97 template <
class THREAD_TYPE>
99 THREAD_TYPE** thread_obj) {
102 ifw::core::utils::system::Mutex tmp_mutex(m_mgr_id); {
103 auto thr_obj_it = m_threads.find(thread_name);
104 if (thr_obj_it == m_threads.end()) {
105 throw rad::Exception(fmt::format(
"%s: Undefined Thread Name: %s",
106 m_mgr_id.c_str(), thread_name.c_str()));
108 *thread_obj =
static_cast<THREAD_TYPE*
>(thr_obj_it->second.get());
117 std::string m_mgr_id;
119 std::map<std::string, std::shared_ptr<Thread>> m_threads;
IFW CTD Multiprocessing Toolkit Manager class.
Definition manager.hpp:21
void StartThreads()
Execute all threads registered.
Definition manager.cpp:30
void StopThreads()
Request threads to end execution.
Definition manager.cpp:69
MessageBus & MsgBus()
Get reference to Message Bus.
Definition manager.cpp:76
~Manager()
Definition manager.cpp:17
void GetThread(const std::string &thread_name, THREAD_TYPE **thread_obj)
Get reference to MPTK thread, registered in the Thread Registry.
Definition manager.hpp:98
void GetThreadNames(std::list< std::string > &thread_names) const
Return list with names of threads registered.
Definition manager.cpp:81
void PauseThreads()
Pause the threads.
Definition manager.cpp:62
void CreateThread(const THREAD_TYPE &factory_object, const std::string &thread_name, const double period=0.1, THREAD_TYPE **thread_obj=nullptr)
Allocate new MPTK thread object of the given type. The allocated thread object is handled internally ...
Definition manager.hpp:77
Manager()
Definition manager.cpp:12
int16_t NbOfThreadsRunning() const
Returns the number of threads running; this includes the ones that may be paused.
Definition manager.cpp:53
void CreateThread(const std::string &thread_name, const double period=0.1, THREAD_TYPE **thread_obj=nullptr)
Allocate new MPTK thread object of the given type. The allocated thread object is handled internally ...
Definition manager.hpp:56
std::string ToString() const
Generate ASCII output providing a status of the object.
int16_t WaitForThreadTerm(const double time_out=ifw::core::utils::base::NO_TIMEOUT)
Wait for threads to terminate execution. Returns the number of threads running.
Definition manager.cpp:37
void Reset()
Reset the object. This includes stopping the possible running threads and deleting all thread objects...
Definition manager.cpp:22
IFW CTD Multiprocessing Toolkit Message Bus.
Definition messageBus.hpp:91
MessageBus & RegisterThread(const std::string &thread_name)
Register thread which will send/receive messages on the Message Bus.
Definition messageBus.cpp:64
Definition manager.hpp:15