DDS  ver. 3.4
ConnectionManager.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 #ifndef __DDS__ConnectionManager__
6 #define __DDS__ConnectionManager__
7 // DDS
8 #include "AgentChannel.h"
10 #include "Options.h"
11 #include "SSHScheduler.h"
12 #include "ToolsProtocol.h"
13 #include "TopoCore.h"
14 #include "UIChannelInfo.h"
15 // STD
16 #include <condition_variable>
17 #include <mutex>
18 
19 namespace dds
20 {
21  namespace commander_cmd
22  {
23  class CConnectionManager : public protocol_api::CConnectionManagerImpl<CAgentChannel, CConnectionManager>,
24  public std::enable_shared_from_this<CConnectionManager>
25  {
26  public:
27  CConnectionManager(const SOptions_t& _options);
28 
30 
31  public:
33  void _start();
34  void _stop();
35  void _createInfoFile(const std::vector<size_t>& _ports) const;
36  void _deleteInfoFile() const;
37 
38  private:
39  void on_cmdBINARY_ATTACHMENT_RECEIVED(
40  const protocol_api::SSenderInfo& _sender,
43  void on_cmdTRANSPORT_TEST(
44  const protocol_api::SSenderInfo& _sender,
47  void on_cmdREPLY(const protocol_api::SSenderInfo& _sender,
50  void on_cmdUPDATE_KEY(const protocol_api::SSenderInfo& _sender,
53  void on_cmdUSER_TASK_DONE(
54  const protocol_api::SSenderInfo& _sender,
57  void on_cmdGET_PROP_LIST(
58  const protocol_api::SSenderInfo& _sender,
61  void on_cmdGET_PROP_VALUES(
62  const protocol_api::SSenderInfo& _sender,
65  void on_cmdREPLY_ID(const protocol_api::SSenderInfo& _sender,
68  void on_cmdENABLE_STAT(
69  const protocol_api::SSenderInfo& _sender,
72  void on_cmdDISABLE_STAT(
73  const protocol_api::SSenderInfo& _sender,
76  void on_cmdGET_STAT(const protocol_api::SSenderInfo& _sender,
79  void on_cmdCUSTOM_CMD(const protocol_api::SSenderInfo& _sender,
82 
83  private:
84  template <protocol_api::ECmdType _cmd, class... Args>
85  void broadcastUpdateTopologyAndWait(weakChannelInfo_t::container_t agents,
87  const std::string& _msg,
88  Args&&... args);
89  template <protocol_api::ECmdType _cmd>
90  void broadcastUpdateTopologyAndWait_impl(size_t index, weakChannelInfo_t _agent);
91  template <protocol_api::ECmdType _cmd>
92  void broadcastUpdateTopologyAndWait_impl(
93  size_t index,
94  weakChannelInfo_t _agent,
96  template <protocol_api::ECmdType _cmd>
97  void broadcastUpdateTopologyAndWait_impl(size_t index,
98  weakChannelInfo_t _agent,
99  const std::string& _filePath,
100  const std::string& _filename);
101  template <protocol_api::ECmdType _cmd>
102  void broadcastUpdateTopologyAndWait_impl(size_t index,
103  weakChannelInfo_t _agent,
104  const std::vector<std::string>& _filePaths,
105  const std::vector<std::string>& _filenames);
106  template <protocol_api::ECmdType _cmd>
107  void broadcastUpdateTopologyAndWait_impl(
108  size_t index,
109  weakChannelInfo_t _agent,
110  const std::vector<typename protocol_api::SCommandAttachmentImpl<_cmd>::ptr_t>& _attachments);
111 
112  void activateTasks(const CSSHScheduler& _scheduler, CAgentChannel::weakConnectionPtr_t _channel);
113  void enableDisableStatForChannels(bool _enable);
114  void _createWnPkg(bool _needInlineBashScript, bool _lightweightPkg, uint32_t _nSlots) const;
115  void processToolsAPIRequests(const protocol_api::SCustomCmdCmd& _cmd,
117  void submitAgents(const dds::tools_api::SSubmitRequestData& _submitInfo,
119  void updateTopology(const dds::tools_api::STopologyRequestData& _topologyInfo,
121  void getLog(const dds::tools_api::SGetLogRequestData& _getLog, CAgentChannel::weakConnectionPtr_t _channel);
122  void sendToolsAPIMsg(CAgentChannel::weakConnectionPtr_t _channel,
123  dds::tools_api::requestID_t _requestID,
124  const std::string& _msg,
125  intercom_api::EMsgSeverity _severity);
126  void sendUICommanderInfo(const dds::tools_api::SCommanderInfoRequestData& _info,
128  void sendUIAgentInfo(const dds::tools_api::SAgentInfoRequestData& _info,
130  void sendUIAgentCount(const dds::tools_api::SAgentCountRequestData& _info,
132 
133  void sendCustomCommandResponse(CAgentChannel::weakConnectionPtr_t _channel, const std::string& _json) const;
134  void sendDoneResponse(CAgentChannel::weakConnectionPtr_t _channel, tools_api::requestID_t _requestID) const;
135 
136  private:
137  CGetLogChannelInfo m_getLog;
138  CTestChannelInfo m_transportTest;
139  CUpdateTopologyChannelInfo m_updateTopology;
140  CSubmitAgentsChannelInfo m_SubmitAgents;
142 
143  // TODO: This is temporary storage only. Store this information as a part of scheduler.
144  typedef std::map<uint64_t, weakChannelInfo_t> TaskIDToAgentChannelMap_t;
145  TaskIDToAgentChannelMap_t m_taskIDToAgentChannelMap;
146  std::mutex m_mapMutex;
147 
148  std::mutex m_updateTopoMutex;
149  std::condition_variable m_updateTopoCondition;
150 
151  // Statistic on/off flag
152  bool m_statEnabled;
153  };
154  } // namespace commander_cmd
155 } // namespace dds
156 #endif /* defined(__DDS__ConnectionManager__) */
void _start()
Definition: ConnectionManager.cpp:45
std::shared_ptr< CAgentChannel > connectionPtr_t
Definition: BaseChannelImpl.h:235
SWeakChannelInfo< CAgentChannel > weakChannelInfo_t
Definition: ConnectionManagerImpl.h:42
Definition: BaseEventHandlersImpl.h:48
void _stop()
Definition: ConnectionManager.cpp:66
std::shared_ptr< SEmptyCmd > ptr_t
Definition: CommandAttachmentImpl.h:64
void _createInfoFile(const std::vector< size_t > &_ports) const
Definition: ConnectionManager.cpp:206
Definition: UIChannelInfo.h:249
Definition: UIChannelInfo.h:288
Definition: ConnectionManager.h:23
std::weak_ptr< CAgentChannel > weakConnectionPtr_t
Definition: BaseChannelImpl.h:236
CConnectionManager(const SOptions_t &_options)
Definition: ConnectionManager.cpp:34
uint64_t requestID_t
Definition: ToolsProtocolCore.h:111
Definition: UIChannelInfo.h:338
Structure holds information of a submit request.
Definition: ToolsProtocol.h:74
Definition: AgentConnectionManager.h:13
void newClientCreated(CAgentChannel::connectionPtr_t _newClient)
Definition: ConnectionManager.cpp:70
Definition: TopoCore.h:25
dds-commander's container of options
Definition: dds-commander/src/Options.h:24
Definition: CustomCmdCmd.h:14
EMsgSeverity
Enumeration with message severity.
Definition: Intercom.h:126
Definition: SSHScheduler.h:20
void _deleteInfoFile() const
Definition: ConnectionManager.cpp:242
~CConnectionManager()
Definition: ConnectionManager.cpp:41
Structure holds information of topology request.
Definition: ToolsProtocol.h:99
Base class for connection managers.
Definition: ConnectionManagerImpl.h:38
std::vector< SWeakChannelInfo > container_t
Definition: ChannelInfo.h:52
Definition: UIChannelInfo.h:391
ECmdType
Definition: ProtocolCommands.h:25