Satellite-Gateway
GatewayClientHandlerCollection.cpp
Go to the documentation of this file.
1 
27 #include "GatewayClientHandler.h"
29 #include <assert.h>
30 
31 GatewayClientHandlerCollection::GatewayClientHandlerCollection(boost::asio::io_service& a_IOService): m_IOService(a_IOService) {
32 }
33 
34 void GatewayClientHandlerCollection::Initialize(std::shared_ptr<ConfigServerHandlerCollection> a_ConfigServerHandlerCollection,
35  std::shared_ptr<HdlcdClientHandlerCollection> a_HdlcdClientHandlerCollection) {
36  assert(a_ConfigServerHandlerCollection);
37  assert(a_HdlcdClientHandlerCollection);
38  m_ConfigServerHandlerCollection = a_ConfigServerHandlerCollection;
39  m_HdlcdClientHandlerCollection = a_HdlcdClientHandlerCollection;
40 }
41 
43  // Silently remove the previous gateway client
44  if (m_GatewayClientHandler) {
45  m_GatewayClientHandler->Close();
46  m_GatewayClientHandler.reset();
47  } // if
48 
49  // Drop all shared pointers
50  m_ConfigServerHandlerCollection.reset();
51  m_HdlcdClientHandlerCollection.reset();
52 }
53 
55  // Silently remove the previous gateway client
56  if (m_GatewayClientHandler) {
57  m_GatewayClientHandler->Close();
58  m_GatewayClientHandler.reset();
59  } // if
60 }
61 
62 void GatewayClientHandlerCollection::CreateClient(uint16_t a_ReferenceNbr, std::string a_RemoteAddress, uint16_t a_RemotePortNbr) {
63  if (m_GatewayClientHandler) {
64  // There was already a client entity! Replace it.
65  m_ConfigServerHandlerCollection->GatewayClientError(a_ReferenceNbr, GATEWAY_CLIENT_ERROR_ALREADY_EXISTED);
66  m_GatewayClientHandler->Close();
67  m_ConfigServerHandlerCollection->GatewayClientDestroyed(m_GatewayClientHandler->GetReferenceNbr());
68  m_GatewayClientHandler.reset();
69  } // if
70 
71  // Create new entity
72  m_GatewayClientHandler = std::make_shared<GatewayClientHandler>(m_IOService, m_ConfigServerHandlerCollection, m_HdlcdClientHandlerCollection,
73  a_ReferenceNbr, a_RemoteAddress, a_RemotePortNbr);
74  m_ConfigServerHandlerCollection->GatewayClientCreated(a_ReferenceNbr);
75 }
76 
77 void GatewayClientHandlerCollection::DestroyClient(uint16_t a_ReferenceNbr) {
78  if (m_GatewayClientHandler) {
79  if (m_GatewayClientHandler->GetReferenceNbr() == a_ReferenceNbr) {
80  m_ConfigServerHandlerCollection->GatewayClientDestroyed(a_ReferenceNbr);
81  m_GatewayClientHandler->Close();
82  m_GatewayClientHandler.reset();
83  } else {
84  // The reference number did not match!
85  m_ConfigServerHandlerCollection->GatewayClientError(a_ReferenceNbr, GATEWAY_CLIENT_ERROR_NO_MATCH);
86  } // else
87  } else {
88  // There was no client entity!
89  m_ConfigServerHandlerCollection->GatewayClientError(a_ReferenceNbr, GATEWAY_CLIENT_ERROR_NOT_EXISTED);
90  } // else
91 }
92 
93 void GatewayClientHandlerCollection::SendPacket(uint16_t a_SerialPortNbr, const std::vector<unsigned char> &a_Buffer) {
94  if (m_GatewayClientHandler) {
95  m_GatewayClientHandler->SendPacket(a_SerialPortNbr, a_Buffer);
96  } // if
97 }
void CreateClient(uint16_t a_ReferenceNbr, std::string a_RemoteAddress, uint16_t a_RemotePortNbr)
void SendPacket(uint16_t a_SerialPortNbr, const std::vector< unsigned char > &a_Buffer)
void Initialize(std::shared_ptr< ConfigServerHandlerCollection > a_ConfigServerHandlerCollection, std::shared_ptr< HdlcdClientHandlerCollection > a_HdlcdClientHandlerCollection)
void DestroyClient(uint16_t a_ReferenceNbr)
GatewayClientHandlerCollection(boost::asio::io_service &a_IOService)