ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Manager.hpp
Go to the documentation of this file.
1 
5 #ifndef IFW_CTD_MPTK_MANAGER_HPP_
6 #define IFW_CTD_MPTK_MANAGER_HPP_
7 
8 #include "ctd/mptk/Message.hpp"
9 #include "ctd/mptk/Thread.hpp"
10 
11 namespace ctd {
12 namespace mptk {
13 
15 class Manager {
16 public:
17 
18  Manager();
19 
20  ~Manager();
21 
23  void StartThreads();
24 
26  void PauseThreads();
27 
29  void StopThreads();
30 
33  int16_t WaitForThreadTerm(const double time_out = ctd::defines::NO_TIMEOUT);
34 
36  int16_t NbOfThreadsRunning() const;
37 
39  MessageBus& MsgBus();
40 
42  std::string Print() const;
43 
46  template <class THREAD_TYPE> void CreateThread(const std::string& thread_id,
47  MessageBus& message_bus,
48  const double period = 0.1) {
49  THREAD_TYPE* thread_ptr = new THREAD_TYPE(thread_id, message_bus, period);
50  m_threads[thread_id] = thread_ptr;
51  MsgBus().RegisterThread(thread_id);
52  }
53 
54 private:
55  MessageBus m_message_bus;
56  std::map<std::string, Thread*> m_threads;
57 };
58 
59 } // namespace mptk
60 } // namespace ctd
61 
62 #endif // IFW_CTD_MPTK_MANAGER_HPP_
63 
~Manager()
Definition: Manager.cpp:16
void StartThreads()
Execute all threads registered.
Definition: Manager.cpp:24
MessageBus & MsgBus()
Get reference to Message Bus.
Definition: Manager.cpp:75
IFW CTD Multiprocessing Toolkit Message Bus.
Definition: MessageBus.hpp:22
void PauseThreads()
Pause the threads.
Definition: Manager.cpp:59
std::string Print() const
Generate ASCII output providing a status of the object.
int16_t WaitForThreadTerm(const double time_out=ctd::defines::NO_TIMEOUT)
Wait for threads to terminate execution. Returns the number of threads running.
Definition: Manager.cpp:32
MessageBus & RegisterThread(const std::string &thread_id)
Register thread which will send/receive messages on the Message Bus.
Definition: MessageBus.cpp:27
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:49
void StopThreads()
Request threads to end execution.
Definition: Manager.cpp:67
void CreateThread(const std::string &thread_id, MessageBus &message_bus, const double period=0.1)
Allocate new MPTK thread object of the given type. The allocated thread object is handled internally ...
Definition: Manager.hpp:46
const int64_t NO_TIMEOUT
Definition: defines.hpp:206