ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MessageBus.hpp
Go to the documentation of this file.
1 
5 #ifndef IFW_CTD_MPTK_MESSAGE_BUS_HPP_
6 #define IFW_CTD_MPTK_MESSAGE_BUS_HPP_
7 
8 #include <string>
9 #include <queue>
10 #include <iostream>
11 
12 #include "ctd/defines/defines.hpp"
13 
14 #include "ctd/mptk/Message.hpp"
15 #include "ctd/mptk/Response.hpp"
16 
17 namespace ctd {
18 namespace mptk {
19 
20 
22 class MessageBus {
23 public:
24 
25  MessageBus();
26 
27  ~MessageBus();
28 
30  MessageBus& RegisterThread(const std::string& thread_id);
31 
33  void SendMessage(const Message& message);
34 
43  bool ReceiveMessage(const std::string& receiver_thread_id,
44  const double time_out,
45  bool& timed_out,
46  Message& message);
47 
49  void SendResponse(Response& response);
50 
53  bool ReceiveResponse(const std::string& receiver_thread_id,
54  const double time_out,
55  bool& timed_out,
56  Response& response);
57 
59  std::string Print() const;
60 
61 private:
62  std::string m_id; // Message Bus ID.
63 
64  // Message receiver Thread ID to message objects list.
65  std::map<std::string, std::list<Message> > m_message_registry;
66 
67  // Response receiver Thread ID to response objects list.
68  std::map<std::string, std::list<Response> > m_response_registry;
69 
71 };
72 
73 } // namespace mptk
74 } // namespace ctd
75 
76 #endif // IFW_CTD_MPTK_MESSAGE_BUS_HPP_
77 
bool ReceiveMessage(const std::string &receiver_thread_id, const double time_out, bool &timed_out, Message &message)
Check for a message for this thread. Returns true if message available.
Definition: MessageBus.cpp:47
MessageBus()
Definition: MessageBus.cpp:15
void SendResponse(Response &response)
Send a response to a message received on the Message Bus.
Definition: MessageBus.cpp:77
~MessageBus()
Definition: MessageBus.cpp:23
MessageBus & RegisterThread(const std::string &thread_id)
Register thread which will send/receive messages on the Message Bus.
Definition: MessageBus.cpp:27
void SendMessage(const Message &message)
Send a message on the Message Bus.
Definition: MessageBus.cpp:39
bool ReceiveResponse(const std::string &receiver_thread_id, const double time_out, bool &timed_out, Response &response)
Check for a message for this thread. Returns true if message available.
Definition: MessageBus.cpp:85
std::string Print() const
Generate ASCII output providing a status of the object (to the extend possible).