32 std::shared_ptr<HdlcdClientHandlerCollection> a_HdlcdClientHandlerCollection, uint16_t a_ReferenceNbr,
33 std::string a_RemoteAddress, uint16_t a_RemotePortNbr):
34 m_IOService(a_IOService), m_ConfigServerHandlerCollection(a_ConfigServerHandlerCollection),
35 m_HdlcdClientHandlerCollection(a_HdlcdClientHandlerCollection), m_GatewayClientConnectGuard(a_ConfigServerHandlerCollection, a_ReferenceNbr),
36 m_RemoteAddress(a_RemoteAddress), m_RemotePortNbr(a_RemotePortNbr), m_ReferenceNbr(a_ReferenceNbr), m_Resolver(a_IOService), m_ConnectionRetryTimer(a_IOService) {
38 assert(m_ConfigServerHandlerCollection);
39 assert(m_HdlcdClientHandlerCollection);
47 if (m_GatewayClient) {
48 m_GatewayClient->Close();
49 m_GatewayClient.reset();
52 m_ConfigServerHandlerCollection.reset();
53 m_HdlcdClientHandlerCollection.reset();
57 if (m_GatewayClient) {
58 m_GatewayClient->SendPacket(a_SerialPortNbr, a_Buffer);
62 void GatewayClientHandler::ResolveDestination() {
63 std::stringstream l_OStream;
64 l_OStream << m_RemotePortNbr;
65 m_Resolver.async_resolve({m_RemoteAddress, l_OStream.str()}, [
this](
const boost::system::error_code& a_ErrorCode, boost::asio::ip::tcp::resolver::iterator a_EndpointIterator) {
67 std::cout <<
"Failed to resolve host name: " << m_RemoteAddress << std::endl;
68 m_ConnectionRetryTimer.expires_from_now(boost::posix_time::seconds(2));
69 m_ConnectionRetryTimer.async_wait([
this](
const boost::system::error_code& a_ErrorCode) {
77 m_GatewayClient = std::make_shared<GatewayClient>(m_IOService, a_EndpointIterator, m_ConfigServerHandlerCollection, m_HdlcdClientHandlerCollection, m_GatewayClientConnectGuard, m_ReferenceNbr);
80 m_GatewayClient->SetOnClosedCallback([
this]() {
81 m_ConnectionRetryTimer.expires_from_now(boost::posix_time::seconds(2));
82 m_ConnectionRetryTimer.async_wait([
this](
const boost::system::error_code& a_ErrorCode) {
GatewayClientHandler(boost::asio::io_service &a_IOService, std::shared_ptr< ConfigServerHandlerCollection > a_ConfigServerHandlerCollection, std::shared_ptr< HdlcdClientHandlerCollection > a_HdlcdClientHandlerCollection, uint16_t a_ReferenceNbr, std::string a_RemoteAddress, uint16_t a_RemotePortNbr)
void SendPacket(uint16_t a_SerialPortNbr, const std::vector< unsigned char > &a_Payload)