DDS  ver. 2.0
dds-commander/src/AgentChannel.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef __DDS__CAgentChannel__
6 #define __DDS__CAgentChannel__
7 // DDS
8 #include "ServerChannelImpl.h"
9 // STD
10 #include <chrono>
11 
12 namespace dds
13 {
14  namespace commander_cmd
15  {
17  {
18  unknown = 0,
19  idle, // no tasks are assigned
20  executing // assigned task is executing
21  };
22  const std::array<std::string, 3> g_agentStates = { { "unknown", "idle", "executing" } };
23 
24  struct SAgentInfo
25  {
27  : m_lobbyLeader(false)
28  , m_id(0)
29  , m_taskID(0)
31  {
32  }
33 
35  // We use unique ID because we need to identify a new agent after shutdown of the system on the same host.
36  // We have to distinguish between new and old agent.
37  uint64_t m_id;
39  uint64_t m_taskID;
40  std::chrono::milliseconds m_startUpTime;
42  };
43 
44  typedef std::map<uint64_t, SAgentInfo> AgentInfoContainer_t;
45  typedef std::vector<uint64_t> LobbyProtocolHeaderIdContainer_t;
46 
47  class CAgentChannel : public protocol_api::CServerChannelImpl<CAgentChannel>
48  {
49  CAgentChannel(boost::asio::io_service& _service, uint64_t _protocolHeaderID = 0);
50 
51  public:
53  MESSAGE_HANDLER(cmdREPLY_HOST_INFO, on_cmdREPLY_HOST_INFO)
54  //====> replay on the "submit" command request
55  MESSAGE_HANDLER(cmdSUBMIT, on_cmdSUBMIT)
56  MESSAGE_HANDLER(cmdUSER_TASK_DONE, on_cmdUSER_TASK_DONE)
57  //====> replay on the "info" command request
58  // - get pid of the commander server
59  MESSAGE_HANDLER(cmdGED_PID, on_cmdGED_PID)
60  // - get Agents Info command
61  MESSAGE_HANDLER(cmdGET_AGENTS_INFO, on_cmdGET_AGENTS_INFO)
62  MESSAGE_HANDLER(cmdREPLY_ID, on_cmdREPLY_ID)
63  MESSAGE_HANDLER(cmdBINARY_ATTACHMENT_RECEIVED, on_cmdBINARY_ATTACHMENT_RECEIVED)
64  MESSAGE_HANDLER(cmdTRANSPORT_TEST, on_cmdTRANSPORT_TEST)
65  MESSAGE_HANDLER(cmdSIMPLE_MSG, on_cmdSIMPLE_MSG)
66  // - Topology commands
67  MESSAGE_HANDLER(cmdUPDATE_TOPOLOGY, on_cmdUPDATE_TOPOLOGY)
68  // - Agents commands
69  MESSAGE_HANDLER(cmdGET_LOG, on_cmdGET_LOG)
70  MESSAGE_HANDLER(cmdUPDATE_KEY, on_cmdUPDATE_KEY)
71  // Watchdog
72  MESSAGE_HANDLER(cmdWATCHDOG_HEARTBEAT, on_cmdWATCHDOG_HEARTBEAT)
73  MESSAGE_HANDLER(cmdGET_PROP_LIST, on_cmdGET_PROP_LIST)
74  MESSAGE_HANDLER(cmdGET_PROP_VALUES, on_cmdGET_PROP_VALUES)
75  // Statistics commands
76  MESSAGE_HANDLER(cmdENABLE_STAT, on_cmdENABLE_STAT)
77  MESSAGE_HANDLER(cmdDISABLE_STAT, on_cmdDISABLE_STAT)
78  MESSAGE_HANDLER(cmdGET_STAT, on_cmdGET_STAT)
79  // custom command
80  MESSAGE_HANDLER(cmdCUSTOM_CMD, on_cmdCUSTOM_CMD)
81  END_MSG_MAP()
82 
83  public:
84  uint64_t getId(const dds::protocol_api::SSenderInfo& _sender);
85  void setId(const dds::protocol_api::SSenderInfo& _sender, uint64_t _id);
86 
87  protocol_api::SHostInfoCmd getRemoteHostInfo(const dds::protocol_api::SSenderInfo& _sender);
88  // This function only used in tests
89  void setRemoteHostInfo(const dds::protocol_api::SSenderInfo& _sender,
90  const protocol_api::SHostInfoCmd& _hostInfo);
91 
92  std::chrono::milliseconds getStartupTime(const dds::protocol_api::SSenderInfo& _sender);
93 
94  EAgentState getState(const dds::protocol_api::SSenderInfo& _sender);
95  void setState(const dds::protocol_api::SSenderInfo& _sender, EAgentState _state);
96 
97  uint64_t getTaskID(const dds::protocol_api::SSenderInfo& _sender);
98  void setTaskID(const dds::protocol_api::SSenderInfo& _sender, uint64_t _taskID);
99 
100  // AgentInfo operations
102  void updateAgentInfo(const dds::protocol_api::SSenderInfo& _sender, const SAgentInfo& _info);
103  void updateAgentInfo(uint64_t _protocolHeaderID, const SAgentInfo& _info);
105  // FIXME: This function makes a copy of the info struct. Find a solution to avoid copy operations. But the
106  // function and the info struct still must be thread safe.
107  SAgentInfo getAgentInfo(const dds::protocol_api::SSenderInfo& _sender);
108  SAgentInfo getAgentInfo(uint64_t _protocolHeaderID);
109  LobbyProtocolHeaderIdContainer_t getLobbyPHID() const;
110 
111  private:
112  // Message Handlers
114  const protocol_api::SSenderInfo& _sender);
115  bool on_cmdREPLY_HOST_INFO(
117  const protocol_api::SSenderInfo& _sender);
119  const protocol_api::SSenderInfo& _sender);
121  const protocol_api::SSenderInfo& _sender);
123  const protocol_api::SSenderInfo& _sender);
124  bool on_cmdBINARY_ATTACHMENT_RECEIVED(
126  const protocol_api::SSenderInfo& _sender);
127  bool on_cmdGET_AGENTS_INFO(
129  const protocol_api::SSenderInfo& _sender);
130  bool on_cmdTRANSPORT_TEST(
132  const protocol_api::SSenderInfo& _sender);
134  const protocol_api::SSenderInfo& _sender);
136  const protocol_api::SSenderInfo& _sender);
137  bool on_cmdUSER_TASK_DONE(
139  const protocol_api::SSenderInfo& _sender);
140  bool on_cmdWATCHDOG_HEARTBEAT(
142  const protocol_api::SSenderInfo& _sender);
143  bool on_cmdGET_PROP_LIST(
145  const protocol_api::SSenderInfo& _sender);
146  bool on_cmdGET_PROP_VALUES(
148  const protocol_api::SSenderInfo& _sender);
149  bool on_cmdUPDATE_TOPOLOGY(
151  const protocol_api::SSenderInfo& _sender);
152  bool on_cmdENABLE_STAT(
154  const protocol_api::SSenderInfo& _sender);
155  bool on_cmdDISABLE_STAT(
157  const protocol_api::SSenderInfo& _sender);
159  const protocol_api::SSenderInfo& _sender);
161  const protocol_api::SSenderInfo& _sender);
162 
163  std::string _remoteEndIDString();
164 
165  private:
166  std::string m_sCurrentTopoFile;
167  AgentInfoContainer_t m_info;
168  std::mutex m_mtxInfo;
169  };
170  }
171 }
172 #endif /* defined(__DDS__CAgentChannel__) */
Definition: ProtocolCommands.h:53
Definition: dds-commander/src/AgentChannel.h:47
Definition: BaseEventHandlersImpl.h:48
uint64_t m_taskID
Definition: dds-commander/src/AgentChannel.h:39
Definition: ProtocolCommands.h:62
EAgentState
Definition: dds-commander/src/AgentChannel.h:16
std::chrono::milliseconds m_startUpTime
Definition: dds-commander/src/AgentChannel.h:40
#define MESSAGE_HANDLER(msg, func)
Definition: BaseChannelImpl.h:112
uint64_t m_id
Definition: dds-commander/src/AgentChannel.h:37
Definition: ProtocolCommands.h:47
Definition: ProtocolCommands.h:38
protocol_api::SHostInfoCmd m_remoteHostInfo
Definition: dds-commander/src/AgentChannel.h:38
std::shared_ptr< SEmptyCmd > ptr_t
Definition: CommandAttachmentImpl.h:66
EAgentState m_state
Definition: dds-commander/src/AgentChannel.h:41
const std::array< std::string, 3 > g_agentStates
Definition: dds-commander/src/AgentChannel.h:22
Definition: ProtocolCommands.h:60
Definition: ProtocolCommands.h:63
std::map< uint64_t, SAgentInfo > AgentInfoContainer_t
Definition: dds-commander/src/AgentChannel.h:44
Definition: ProtocolCommands.h:33
#define END_MSG_MAP()
Definition: BaseChannelImpl.h:134
Definition: ProtocolCommands.h:32
Definition: dds-agent/src/AgentConnectionManager.h:18
Definition: ProtocolCommands.h:66
Definition: ProtocolCommands.h:54
Definition: dds-commander/src/AgentChannel.h:19
Definition: ProtocolCommands.h:57
Definition: dds-commander/src/AgentChannel.h:24
bool m_lobbyLeader
Definition: dds-commander/src/AgentChannel.h:34
Definition: dds-commander/src/AgentChannel.h:20
Definition: HostInfoCmd.h:15
Definition: ProtocolCommands.h:64
Definition: ProtocolCommands.h:65
Definition: BaseChannelImpl.h:43
Definition: ProtocolCommands.h:44
Definition: ProtocolCommands.h:37
Definition: ProtocolCommands.h:46
std::vector< uint64_t > LobbyProtocolHeaderIdContainer_t
Definition: dds-commander/src/AgentChannel.h:45
Definition: ProtocolCommands.h:41
Definition: ProtocolCommands.h:52
Definition: dds-commander/src/AgentChannel.h:18
SAgentInfo()
Definition: dds-commander/src/AgentChannel.h:26
#define BEGIN_MSG_MAP(theClass)
Definition: BaseChannelImpl.h:49
Definition: ProtocolCommands.h:58