DDS  ver. 3.6
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  using slotID_t = uint64_t;
25  using taskID_t = uint64_t;
26  struct SSlotInfo
27  {
28  slotID_t m_id{ 0 };
31  };
32 
33  struct SAgentInfo
34  {
35  using SlotContainer_t = std::map<slotID_t, SSlotInfo>;
36 
38  : m_id(0)
39  , m_startUpTime(0)
40  {
41  }
42  void addSlot(const SSlotInfo& _slot)
43  {
44  std::lock_guard<std::mutex> lock(m_mtxSlot);
45  m_slots.insert(std::make_pair(_slot.m_id, _slot));
46  }
48  {
49  return m_slots;
50  }
51 
53  {
54  std::lock_guard<std::mutex> lock(m_mtxSlot);
55  auto it = m_slots.find(_slotID);
56  if (it == m_slots.end())
57  {
58  std::stringstream ss;
59  ss << "getSlotByID: slot " << _slotID << " does not exist.";
60  throw std::runtime_error(ss.str());
61  }
62 
63  return it->second;
64  }
65 
66  // We use unique ID because we need to identify a new agent after shutdown of the system on the same host.
67  // We have to distinguish between new and old agent.
68  uint64_t m_id;
70  std::chrono::milliseconds m_startUpTime;
71 
72  private:
73  std::mutex m_mtxSlot;
74  SlotContainer_t m_slots;
75  };
76 
77  class CAgentChannel : public protocol_api::CServerChannelImpl<CAgentChannel>
78  {
79  CAgentChannel(boost::asio::io_context& _context, uint64_t _protocolHeaderID = 0);
80 
81  public:
83  MESSAGE_HANDLER(cmdREPLY_HOST_INFO, on_cmdREPLY_HOST_INFO)
84  //====> replay on the "submit" command request
85  MESSAGE_HANDLER(cmdSUBMIT, on_cmdSUBMIT)
87  //====> replay on the "info" command request
88  // - get Agents Info command
91  //
93  MESSAGE_HANDLER(cmdBINARY_ATTACHMENT_RECEIVED, on_cmdBINARY_ATTACHMENT_RECEIVED)
95  MESSAGE_HANDLER(cmdREPLY, on_cmdREPLY)
96  // - Topology commands
98  // - Agents commands
101  // Watchdog
102  MESSAGE_HANDLER(cmdWATCHDOG_HEARTBEAT, on_cmdWATCHDOG_HEARTBEAT)
105  // custom command
107  // TASK SLOTS
108  MESSAGE_HANDLER(cmdREPLY_ADD_SLOT, on_cmdREPLY_ADD_SLOT)
109  END_MSG_MAP()
110 
111  public:
112  uint64_t getId() const;
113  void setId(uint64_t _id);
114 
116  std::chrono::milliseconds getStartupTime(const dds::protocol_api::SSenderInfo& _sender);
117 
119 
120  private:
121  // Message Handlers
123  const protocol_api::SSenderInfo& _sender);
124  bool on_cmdREPLY_HOST_INFO(
126  const protocol_api::SSenderInfo& _sender);
127  bool on_cmdBINARY_ATTACHMENT_RECEIVED(
129  const protocol_api::SSenderInfo& _sender);
131  const protocol_api::SSenderInfo& _sender);
132  bool on_cmdWATCHDOG_HEARTBEAT(
134  const protocol_api::SSenderInfo& _sender);
135  bool on_cmdREPLY_ADD_SLOT(
137  const protocol_api::SSenderInfo& _sender);
138 
139  std::string _remoteEndIDString();
140 
141  private:
142  std::string m_sCurrentTopoFile;
143  SAgentInfo m_info;
144  std::mutex m_mtxInfo;
145  };
146  } // namespace commander_cmd
147 } // namespace dds
148 #endif /* defined(__DDS__CAgentChannel__) */
Definition: ProtocolCommands.h:66
Definition: ProtocolCommands.h:54
Definition: dds-commander/src/AgentChannel.h:77
Definition: BaseEventHandlersImpl.h:48
uint64_t taskID_t
Definition: dds-commander/src/AgentChannel.h:25
Definition: ProtocolCommands.h:61
EAgentState
Definition: dds-commander/src/AgentChannel.h:16
std::chrono::milliseconds m_startUpTime
Definition: dds-commander/src/AgentChannel.h:70
Definition: ProtocolCommands.h:65
uint64_t m_id
Definition: dds-commander/src/AgentChannel.h:68
Definition: ProtocolCommands.h:47
protocol_api::SHostInfoCmd m_remoteHostInfo
Definition: dds-commander/src/AgentChannel.h:69
std::shared_ptr< SEmptyCmd > ptr_t
Definition: CommandAttachmentImpl.h:64
slotID_t m_id
Definition: dds-commander/src/AgentChannel.h:28
protocol_api::SHostInfoCmd getRemoteHostInfo(const dds::protocol_api::SSenderInfo &_sender)
Definition: dds-commander/src/AgentChannel.cpp:70
on_cmdREPLY_HOST_INFO MESSAGE_HANDLER(cmdSUBMIT, on_cmdSUBMIT) MESSAGE_HANDLER_DISPATCH(cmdUSER_TASK_DONE) MESSAGE_HANDLER_DISPATCH(cmdGET_AGENTS_INFO) MESSAGE_HANDLER_DISPATCH(cmdGET_IDLE_AGENTS_COUNT) MESSAGE_HANDLER_DISPATCH(cmdREPLY_ID) MESSAGE_HANDLER(cmdBINARY_ATTACHMENT_RECEIVED
EAgentState m_state
Definition: dds-commander/src/AgentChannel.h:30
uint64_t slotID_t
Definition: dds-commander/src/AgentChannel.h:24
const std::array< std::string, 3 > g_agentStates
Definition: dds-commander/src/AgentChannel.h:22
Definition: ProtocolCommands.h:59
std::map< slotID_t, SSlotInfo > SlotContainer_t
Definition: dds-commander/src/AgentChannel.h:35
Definition: dds-commander/src/AgentChannel.h:26
on_cmdREPLY_HOST_INFO on_cmdBINARY_ATTACHMENT_RECEIVED on_cmdREPLY on_cmdWATCHDOG_HEARTBEAT on_cmdREPLY_ADD_SLOT END_MSG_MAP() public void setId(uint64_t _id)
Definition: dds-commander/src/AgentChannel.cpp:65
#define END_MSG_MAP()
Definition: BaseChannelImpl.h:148
Definition: ProtocolCommands.h:32
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
Definition: ProtocolCommands.h:62
SlotContainer_t & getSlots()
Definition: dds-commander/src/AgentChannel.h:47
Definition: ProtocolCommands.h:55
Definition: dds-commander/src/AgentChannel.h:19
Definition: ProtocolCommands.h:56
std::chrono::milliseconds getStartupTime(const dds::protocol_api::SSenderInfo &_sender)
Definition: dds-commander/src/AgentChannel.cpp:75
Definition: dds-commander/src/AgentChannel.h:33
BEGIN_MSG_MAP(CAgentChannel) MESSAGE_HANDLER(cmdREPLY_HOST_INFO
Definition: dds-commander/src/AgentChannel.h:20
on_cmdREPLY_HOST_INFO on_cmdBINARY_ATTACHMENT_RECEIVED MESSAGE_HANDLER_DISPATCH(cmdTRANSPORT_TEST) MESSAGE_HANDLER(cmdREPLY
Definition: HostInfoCmd.h:15
SSlotInfo & getSlotByID(slotID_t _slotID)
Definition: dds-commander/src/AgentChannel.h:52
Definition: BaseChannelImpl.h:37
Definition: ProtocolCommands.h:44
taskID_t m_taskID
slot ID
Definition: dds-commander/src/AgentChannel.h:29
void addSlot(const SSlotInfo &_slot)
Definition: dds-commander/src/AgentChannel.h:42
SAgentInfo & getAgentInfo()
Definition: dds-commander/src/AgentChannel.cpp:55
Definition: ProtocolCommands.h:37
Definition: ProtocolCommands.h:46
Definition: ProtocolCommands.h:69
Definition: ProtocolCommands.h:41
Definition: ProtocolCommands.h:53
Definition: dds-commander/src/AgentChannel.h:18
SAgentInfo()
Definition: dds-commander/src/AgentChannel.h:37
Definition: ProtocolCommands.h:57