DDS  ver. 3.5.3.8.g5fe284b
Intercom.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef DDS_INTERCOM_H_
6 #define DDS_INTERCOM_H_
7 // DDS
8 #include "IntercomErrorCodes.h"
9 // STD
10 #include <ostream>
11 #include <string>
12 // BOOST
13 #include <boost/property_tree/json_parser.hpp>
14 #include <boost/signals2/signal.hpp>
15 
16 namespace dds
17 {
18  namespace internal_api
19  {
20  class CIntercomServiceCore;
21  }
22 
34  namespace intercom_api
35  {
37  // DDS intercom service
40  {
41  public:
43  typedef boost::signals2::signal<void(uint64_t /*_taskID*/, uint32_t /*_exitCode*/)> taskDoneSignal_t;
44 
45  public:
48 
50  void subscribeOnError(errorSignal_t::slot_function_type _subscriber);
52  void subscribeOnTaskDone(taskDoneSignal_t::slot_function_type _subscriber);
54  void start(const std::string& _sessionID = "");
55 
56  // TODO: FIXME: workaround for old functionality. This functions will be removed in the future releases.
57  void waitCondition();
58  void stopCondition();
59 
60  private:
61  friend class CKeyValue;
62  friend class CCustomCmd;
63  std::shared_ptr<internal_api::CIntercomServiceCore> m_impl;
64  };
65 
67  // DDS key-value
69  class CKeyValue
70  {
71  public:
73  typedef boost::signals2::signal<void(
74  const std::string& /*_propertyName*/, const std::string& /*_value*/, uint64_t /*_senderTaskID*/)>
76 
77  public:
78  CKeyValue(CIntercomService& _service);
79  ~CKeyValue();
80 
81  public:
82  void putValue(const std::string& _key, const std::string& _value);
83  void subscribe(signal_t::slot_function_type _subscriber);
84  void unsubscribe();
85 
86  private:
87  CIntercomService& m_service;
88  };
89 
91  // DDS custom commands
93  class CCustomCmd
94  {
95  public:
97  typedef boost::signals2::signal<void(
98  const std::string& /*_command*/, const std::string& /*_condition*/, uint64_t /*_senderID*/)>
100  typedef boost::signals2::signal<void(const std::string&)> replySignal_t;
101 
102  public:
103  CCustomCmd(CIntercomService& _service);
104  ~CCustomCmd();
105 
106  public:
107  void send(const std::string& _command, const std::string& _condition);
108  void subscribe(signal_t::slot_function_type _subscriber);
109  void subscribeOnReply(replySignal_t::slot_function_type _subscriber);
110  void unsubscribe();
111 
112  private:
113  CIntercomService& m_service;
114  };
115 
117  // DDS RMS plugins
119 
121  const std::string g_sRmsAgentSign = "rms_agent_sign";
123  const std::string g_sToolsAPISign = "tools_api_sign";
124 
126  enum class EMsgSeverity
127  {
128  info,
129  error
130  };
131 
133  inline std::ostream& operator<<(std::ostream& _os, EMsgSeverity _severity)
134  {
135  switch (_severity)
136  {
137  case EMsgSeverity::info:
138  return _os << "info";
139  case EMsgSeverity::error:
140  default:
141  return _os << "error";
142  }
143  }
144 
146  struct SSubmit
147  {
149  SSubmit();
150 
153  std::string toJSON();
154 
157  void fromJSON(const std::string& _json);
158 
161  void fromPT(const boost::property_tree::ptree& _pt);
162 
164  bool operator==(const SSubmit& _val) const;
165 
166  uint32_t m_nInstances;
167  uint32_t m_slots;
168  std::string m_cfgFilePath;
169  std::string m_id;
170  std::string m_wrkPackagePath;
171  };
172 
174  struct SMessage
175  {
177  SMessage();
178 
181  std::string toJSON();
182 
185  void fromJSON(const std::string& _json);
186 
189  void fromPT(const boost::property_tree::ptree& _pt);
190 
192  bool operator==(const SMessage& _val) const;
193 
195  std::string m_msg;
196  std::string m_id;
197  };
198 
200  struct SInit
201  {
203  SInit();
204 
207  std::string toJSON();
208 
211  void fromJSON(const std::string& _json);
212 
215  void fromPT(const boost::property_tree::ptree& _pt);
216 
218  bool operator==(const SInit& _val) const;
219 
220  std::string m_id;
221  };
222 
252  {
253  public:
255  typedef boost::signals2::signal<void(const SSubmit&)> signalSubmit_t;
256 
258  typedef boost::signals2::signal<void(const SMessage&)> signalMessage_t;
259 
260  public:
263  CRMSPluginProtocol(const std::string& _id);
264 
267 
268  public:
271  void onSubmit(signalSubmit_t::slot_function_type _subscriber);
272 
275  void onMessage(signalMessage_t::slot_function_type _subscriber);
276 
280  void sendMessage(EMsgSeverity _severity, const std::string& _msg);
281 
291  void start(bool _block = true);
292 
294  void stop();
295 
296  protected:
299  void notify(std::istream& _stream);
300 
301  private:
303  void unsubscribe();
304 
305  signalSubmit_t m_signalSubmit;
306  signalMessage_t m_signalMessage;
307 
308  std::string m_id;
309 
310  CIntercomService m_service;
311  CCustomCmd m_customCmd;
312  };
313  } // namespace intercom_api
314 } // namespace dds
315 
316 #endif /* DDS_INTERCOM_H_ */
std::string m_cfgFilePath
Path to the configuration file.
Definition: Intercom.h:168
Structure holds information of submit notification.
Definition: Intercom.h:146
bool operator==(const SSubmit &_val) const
Equality operator.
Definition: dds_rms_plugin_protocol.cpp:86
void fromPT(const boost::property_tree::ptree &_pt)
Init structure from boost's property tree.
Definition: dds_rms_plugin_protocol.cpp:167
~CKeyValue()
Definition: Intercom.cpp:61
void fromJSON(const std::string &_json)
Init structure from JSON.
Definition: dds_rms_plugin_protocol.cpp:159
std::string m_id
ID for communication with DDS commander.
Definition: Intercom.h:220
Structure holds information of message notification.
Definition: Intercom.h:174
Definition: Intercom.h:93
void fromPT(const boost::property_tree::ptree &_pt)
Init structure from boost's property tree.
Definition: dds_rms_plugin_protocol.cpp:125
boost::signals2::signal< void(const std::string &, const std::string &, uint64_t)> signal_t
Definition: Intercom.h:75
bool operator==(const SInit &_val) const
Equality operator.
Definition: dds_rms_plugin_protocol.cpp:173
SSubmit()
Default constructor.
Definition: dds_rms_plugin_protocol.cpp:41
uint32_t m_nInstances
A number of instances.
Definition: Intercom.h:166
boost::signals2::signal< void(const std::string &, const std::string &, uint64_t)> signal_t
Definition: Intercom.h:99
void start(bool _block=true)
Send initial request to the commander and start listening for notifications.
Definition: dds_rms_plugin_protocol.cpp:218
EMsgSeverity m_msgSeverity
Message severity.
Definition: Intercom.h:194
std::string m_id
ID for communication with DDS commander.
Definition: Intercom.h:196
uint32_t m_slots
A number of task slots.
Definition: Intercom.h:167
void start(const std::string &_sessionID="")
Start DDS service, i.e. receiving and sending messages.
Definition: Intercom.cpp:37
boost::signals2::signal< void(const SMessage &)> signalMessage_t
Callback function for message notifications.
Definition: Intercom.h:258
const std::string g_sRmsAgentSign
Sign that is send to commander if RMS plug-in is connecting to it.
Definition: Intercom.h:121
void send(const std::string &_command, const std::string &_condition)
Definition: Intercom.cpp:97
CKeyValue(CIntercomService &_service)
Definition: Intercom.cpp:56
void fromJSON(const std::string &_json)
Init structure from JSON.
Definition: dds_rms_plugin_protocol.cpp:68
boost::signals2::signal< void(const SSubmit &)> signalSubmit_t
Callback function for submit notifications.
Definition: Intercom.h:255
void unsubscribe()
Definition: Intercom.cpp:77
void onMessage(signalMessage_t::slot_function_type _subscriber)
Subscribe for message notifications.
Definition: dds_rms_plugin_protocol.cpp:207
Definition: AgentConnectionManager.h:13
Definition: Intercom.h:39
const std::string g_sToolsAPISign
Sign that is send to commander if Tools-API is connecting to it.
Definition: Intercom.h:123
void subscribeOnReply(replySignal_t::slot_function_type _subscriber)
Definition: Intercom.cpp:108
boost::signals2::signal< void(const std::string &)> replySignal_t
Definition: Intercom.h:100
void fromPT(const boost::property_tree::ptree &_pt)
Init structure from boost's property tree.
Definition: dds_rms_plugin_protocol.cpp:76
void subscribe(signal_t::slot_function_type _subscriber)
Definition: Intercom.cpp:71
void subscribeOnError(errorSignal_t::slot_function_type _subscriber)
Subscribe on error messages from DDS intercom service.
Definition: Intercom.cpp:25
void subscribe(signal_t::slot_function_type _subscriber)
Definition: Intercom.cpp:102
void sendMessage(EMsgSeverity _severity, const std::string &_msg)
Send message to DDS commander.
Definition: dds_rms_plugin_protocol.cpp:238
std::string m_id
ID for communication with DDS commander.
Definition: Intercom.h:169
void waitCondition()
Definition: Intercom.cpp:42
Definition: Intercom.h:69
std::string m_wrkPackagePath
A full path of the agent worker package, which needs to be deployed.
Definition: Intercom.h:170
EMsgSeverity
Enumeration with message severity.
Definition: Intercom.h:126
std::string toJSON()
Converts structure to JSON.
Definition: dds_rms_plugin_protocol.cpp:52
CCustomCmd(CIntercomService &_service)
Definition: Intercom.cpp:87
Class implements basic API for DDS RMS plug-ins.
Definition: Intercom.h:251
void notify(std::istream &_stream)
Parse the input stream and notify subscribers.
Definition: dds_rms_plugin_protocol.cpp:247
SMessage()
Default constructor.
Definition: dds_rms_plugin_protocol.cpp:96
void subscribeOnTaskDone(taskDoneSignal_t::slot_function_type _subscriber)
Subscribe on Task Done events.
Definition: Intercom.cpp:31
void fromJSON(const std::string &_json)
Init structure from JSON.
Definition: dds_rms_plugin_protocol.cpp:117
Structure holds information of init notification.
Definition: Intercom.h:200
std::string toJSON()
Converts structure to JSON.
Definition: dds_rms_plugin_protocol.cpp:103
CRMSPluginProtocol(const std::string &_id)
Constructor with ID.
Definition: dds_rms_plugin_protocol.cpp:182
void stop()
Stop waiting.
Definition: dds_rms_plugin_protocol.cpp:233
SInit()
Default constructor.
Definition: dds_rms_plugin_protocol.cpp:142
boost::signals2::signal< void(uint64_t, uint32_t)> taskDoneSignal_t
Definition: Intercom.h:43
std::string toJSON()
Converts structure to JSON.
Definition: dds_rms_plugin_protocol.cpp:146
void putValue(const std::string &_key, const std::string &_value)
Definition: Intercom.cpp:66
CIntercomService()
Definition: Intercom.cpp:15
bool operator==(const SMessage &_val) const
Equality operator.
Definition: dds_rms_plugin_protocol.cpp:133
~CRMSPluginProtocol()
Destructor.
Definition: dds_rms_plugin_protocol.cpp:197
void unsubscribe()
Definition: Intercom.cpp:114
std::ostream & operator<<(std::ostream &_os, EMsgSeverity _severity)
Support ostreaming EMsgSeverity.
Definition: Intercom.h:133
void onSubmit(signalSubmit_t::slot_function_type _subscriber)
Subscribe for submit notifications.
Definition: dds_rms_plugin_protocol.cpp:202
std::string m_msg
Message text.
Definition: Intercom.h:195
~CIntercomService()
Definition: Intercom.cpp:20
~CCustomCmd()
Definition: Intercom.cpp:92
void stopCondition()
Definition: Intercom.cpp:47