HDLC-Daemon
HdlcdServerHandler.h
Go to the documentation of this file.
1 
22 #ifndef HDLCD_SERVER_HANDLER_H
23 #define HDLCD_SERVER_HANDLER_H
24 
25 #include <iostream>
26 #include <memory>
27 #include <string>
28 #include <deque>
29 #include <vector>
30 #include <boost/asio.hpp>
31 #include "AliveGuard.h"
32 #include "LockGuard.h"
33 #include "BufferType.h"
34 class Frame;
35 class HdlcdPacketData;
36 class HdlcdPacketCtrl;
38 class FrameEndpoint;
40 class SerialPortHandler;
42 
43 class HdlcdServerHandler: public std::enable_shared_from_this<HdlcdServerHandler> {
44 public:
45  HdlcdServerHandler(boost::asio::io_service& a_IOService, std::weak_ptr<HdlcdServerHandlerCollection> a_HdlcdServerHandlerCollection, boost::asio::ip::tcp::socket& a_TcpSocket);
46 
47  E_BUFFER_TYPE GetBufferType() const { return m_eBufferType; }
48  void DeliverBufferToClient(E_BUFFER_TYPE a_eBufferType, const std::vector<unsigned char> &a_Payload, bool a_bReliable, bool a_bInvalid, bool a_bWasSent);
49  void UpdateSerialPortState(bool a_bAlive, size_t a_LockHolders);
50  void QueryForPayload(bool a_bQueryReliable, bool a_bQueryUnreliable);
51 
52  void Start(std::shared_ptr<SerialPortHandlerCollection> a_SerialPortHandlerCollection);
53  void Stop();
54 
55 private:
56  // Callbacks
57  bool OnFrame(const std::shared_ptr<Frame> a_Frame); // To parse the session header
58  bool OnDataReceived(std::shared_ptr<const HdlcdPacketData> a_PacketData);
59  void OnCtrlReceived(const HdlcdPacketCtrl& a_PacketCtrl);
60  void OnClosed();
61 
62  // Members
63  boost::asio::io_service& m_IOService;
64  std::weak_ptr<HdlcdServerHandlerCollection> m_HdlcdServerHandlerCollection;
65  std::shared_ptr<FrameEndpoint> m_FrameEndpoint;
66  std::shared_ptr<HdlcdPacketEndpoint> m_PacketEndpoint;
67 
68  bool m_Registered;
69  std::shared_ptr<SerialPortHandlerCollection> m_SerialPortHandlerCollection;
70  std::shared_ptr<std::shared_ptr<SerialPortHandler>> m_SerialPortHandlerStopper;
71  std::shared_ptr<SerialPortHandler> m_SerialPortHandler;
72 
73  // Pending incoming data packets
74  bool m_bSerialPortHandlerAwaitsPacket;
75  std::shared_ptr<const HdlcdPacketData> m_PendingIncomingPacketData;
76 
77  // Track the status of the serial port, communicate changes
78  bool m_bDeliverInitialState;
79  AliveGuard m_AliveGuard;
80  LockGuard m_LockGuard;
81 
82  // SAP specification
83  E_BUFFER_TYPE m_eBufferType;
84  bool m_bDeliverSent;
85  bool m_bDeliverRcvd;
86  bool m_bDeliverInvalidData;
87 };
88 
89 #endif // HDLCD_SERVER_HANDLER_H
Copyright (c) 2016, Florian Evers, florian-evers@gmx.de All rights reserved.
Class LockGuard.
Definition: LockGuard.h:35
void Start(std::shared_ptr< SerialPortHandlerCollection > a_SerialPortHandlerCollection)
Class AliveGuard.
Definition: AliveGuard.h:32
Class FrameEndpoint.
Definition: FrameEndpoint.h:65
E_BUFFER_TYPE GetBufferType() const
void QueryForPayload(bool a_bQueryReliable, bool a_bQueryUnreliable)
void DeliverBufferToClient(E_BUFFER_TYPE a_eBufferType, const std::vector< unsigned char > &a_Payload, bool a_bReliable, bool a_bInvalid, bool a_bWasSent)
Class Frame.
Definition: Frame.h:59
HdlcdServerHandler(boost::asio::io_service &a_IOService, std::weak_ptr< HdlcdServerHandlerCollection > a_HdlcdServerHandlerCollection, boost::asio::ip::tcp::socket &a_TcpSocket)
E_BUFFER_TYPE
Definition: BufferType.h:40
This file contains the header declaration of class AliveGuard.
void UpdateSerialPortState(bool a_bAlive, size_t a_LockHolders)
This file contains the header declaration of class LockGuard.