Satellite-Gateway
ConfigServerHandler.cpp
Go to the documentation of this file.
1 
24 #include "ConfigServerHandler.h"
27 #include "ConfigServer.h"
28 #include <assert.h>
29 
30 ConfigServerHandler::ConfigServerHandler(boost::asio::io_service& a_IOService, boost::asio::ip::tcp::tcp::socket& a_TcpSocket, std::shared_ptr<GatewayClientHandlerCollection> a_GatewayClientHandlerCollection, std::shared_ptr<HdlcdClientHandlerCollection> a_HdlcdClientHandlerCollection): m_IOService(a_IOService), m_GatewayClientHandlerCollection(a_GatewayClientHandlerCollection), m_HdlcdClientHandlerCollection(a_HdlcdClientHandlerCollection) {
31  // Checks
32  assert(m_GatewayClientHandlerCollection);
33  assert(m_HdlcdClientHandlerCollection);
34  m_Registered = false;
35  m_ConfigServer = std::make_shared<ConfigServer>(m_IOService, a_TcpSocket);
36 }
37 
38 void ConfigServerHandler::Start(std::shared_ptr<ConfigServerHandlerCollection> a_ConfigServerHandlerCollection) {
39  // Checks
40  assert(a_ConfigServerHandlerCollection);
41  assert(m_Registered == false);
42 
43  // Register to the collection
44  m_Registered = true;
45  m_ConfigServerHandlerCollection = a_ConfigServerHandlerCollection;
46  m_ConfigServerHandlerCollection->RegisterConfigServerHandler(shared_from_this());
47 
48  // Trigger activity
49  assert(m_ConfigServer);
50  m_ConfigServer->SetOnClosedCallback([this](){ Close(); });
51  m_ConfigServer->Start(m_GatewayClientHandlerCollection, m_HdlcdClientHandlerCollection);
52 }
53 
55  // Keep this object alive
56  auto self(shared_from_this());
57  if (m_Registered) {
58  m_Registered = false;
59  if (m_ConfigServer) {
60  m_ConfigServer->Close();
61  m_ConfigServer.reset();
62  } // if
63 
64  // Deregister from the collection
65  m_ConfigServerHandlerCollection->DeregisterConfigServerHandler(self);
66 
67  // Drop all shared pointers
68  m_GatewayClientHandlerCollection.reset();
69  m_HdlcdClientHandlerCollection.reset();
70  m_ConfigServerHandlerCollection.reset();
71  } // if
72 }
73 
74 void ConfigServerHandler::GatewayClientCreated(uint16_t a_ReferenceNbr) {
75  if (m_ConfigServer) {
76  // Relay the call to the config server entity
77  m_ConfigServer->GatewayClientCreated(a_ReferenceNbr);
78  } // if
79 }
80 
81 void ConfigServerHandler::GatewayClientDestroyed(uint16_t a_ReferenceNbr) {
82  if (m_ConfigServer) {
83  // Relay the call to the config server entity
84  m_ConfigServer->GatewayClientDestroyed(a_ReferenceNbr);
85  } // if
86 }
87 
88 void ConfigServerHandler::GatewayClientConnected(uint16_t a_ReferenceNbr) {
89  if (m_ConfigServer) {
90  // Relay the call to the config server entity
91  m_ConfigServer->GatewayClientConnected(a_ReferenceNbr);
92  } // if
93 }
94 
95 void ConfigServerHandler::GatewayClientDisconnected(uint16_t a_ReferenceNbr) {
96  if (m_ConfigServer) {
97  // Relay the call to the config server entity
98  m_ConfigServer->GatewayClientDisconnected(a_ReferenceNbr);
99  } // if
100 }
101 
102 void ConfigServerHandler::GatewayClientError(uint16_t a_ReferenceNbr, E_GATEWAY_CLIENT_ERROR a_ErrorCode) {
103  if (m_ConfigServer) {
104  // Relay the call to the config server entity
105  m_ConfigServer->GatewayClientError(a_ReferenceNbr, a_ErrorCode);
106  } // if
107 }
108 
109 void ConfigServerHandler::HdlcdClientCreated(uint16_t a_SerialPortNbr) {
110  if (m_ConfigServer) {
111  // Relay the call to the config server entity
112  m_ConfigServer->HdlcdClientCreated(a_SerialPortNbr);
113  } // if
114 }
115 
116 void ConfigServerHandler::HdlcdClientDestroyed(uint16_t a_SerialPortNbr) {
117  if (m_ConfigServer) {
118  // Relay the call to the config server entity
119  m_ConfigServer->HdlcdClientDestroyed(a_SerialPortNbr);
120  } // if
121 }
122 
123 void ConfigServerHandler::HdlcdClientConnected(uint16_t a_SerialPortNbr) {
124  if (m_ConfigServer) {
125  // Relay the call to the config server entity
126  m_ConfigServer->HdlcdClientConnected(a_SerialPortNbr);
127  } // if
128 }
129 
130 void ConfigServerHandler::HdlcdClientDisconnected(uint16_t a_SerialPortNbr) {
131  if (m_ConfigServer) {
132  // Relay the call to the config server entity
133  m_ConfigServer->HdlcdClientDisconnected(a_SerialPortNbr);
134  } // if
135 }
136 
137 void ConfigServerHandler::HdlcdClientNewStatus(uint16_t a_SerialPortNbr, bool a_bIsResumed, bool a_bIsAlive) {
138  if (m_ConfigServer) {
139  // Relay the call to the config server entity
140  m_ConfigServer->HdlcdClientNewStatus(a_SerialPortNbr, a_bIsResumed, a_bIsAlive);
141  } // if
142 }
143 
144 void ConfigServerHandler::HdlcdClientError(uint16_t a_SerialPortNbr, E_HDLCD_CLIENT_ERROR a_ErrorCode) {
145  if (m_ConfigServer) {
146  // Relay the call to the config server entity
147  m_ConfigServer->HdlcdClientError(a_SerialPortNbr, a_ErrorCode);
148  } // if
149 }
void GatewayClientDisconnected(uint16_t a_ReferenceNbr)
void GatewayClientError(uint16_t a_ReferenceNbr, E_GATEWAY_CLIENT_ERROR a_ErrorCode)
E_GATEWAY_CLIENT_ERROR
void HdlcdClientError(uint16_t a_SerialPortNbr, E_HDLCD_CLIENT_ERROR a_ErrorCode)
void GatewayClientCreated(uint16_t a_ReferenceNbr)
void HdlcdClientCreated(uint16_t a_SerialPortNbr)
void HdlcdClientDisconnected(uint16_t a_SerialPortNbr)
E_HDLCD_CLIENT_ERROR
void GatewayClientDestroyed(uint16_t a_ReferenceNbr)
void HdlcdClientConnected(uint16_t a_SerialPortNbr)
void GatewayClientConnected(uint16_t a_ReferenceNbr)
void HdlcdClientDestroyed(uint16_t a_SerialPortNbr)
void Start(std::shared_ptr< ConfigServerHandlerCollection > a_ConfigServerHandlerCollection)
void HdlcdClientNewStatus(uint16_t a_SerialPortNbr, bool a_bIsResumed, bool a_bIsAlive)
ConfigServerHandler(boost::asio::io_service &a_IOService, boost::asio::ip::tcp::tcp::socket &a_TcpSocket, std::shared_ptr< GatewayClientHandlerCollection > a_GatewayClientHandlerCollection, std::shared_ptr< HdlcdClientHandlerCollection > a_HdlcdClientHandlerCollection)