HDLC-Daemon
AliveState.h
Go to the documentation of this file.
1 
39 #ifndef ALIVE_STATE_H
40 #define ALIVE_STATE_H
41 
42 #include <memory>
43 #include <boost/asio/deadline_timer.hpp>
44 
52 class AliveState: public std::enable_shared_from_this<AliveState> {
53 public:
54  // CTOR and DTOR
55  AliveState(boost::asio::io_service& a_IOService);
56  ~AliveState();
57 
58  // Register callback methods
59  void SetSendProbeCallback(std::function<void()> a_SendProbeCallback);
60  void SetChangeBaudrateCallback(std::function<void()> a_ChangeBaudrateCallback);
61 
62  // Start and stop processing
63  void Start();
64  void Stop();
65 
66  // Notification regarding incoming data, and query methods
67  bool OnFrameReceived();
68  bool IsAlive() const;
69 
70 private:
71  // Helpers
72  void Reset();
73  void StartStateTimer();
74  void StartProbeTimer();
75 
76  // Members
82  typedef enum {
83  ALIVESTATE_PROBING = 0,
84  ALIVESTATE_FOUND = 1,
85  ALIVESTATE_REPROBING = 2,
86  } E_ALIVESTATE;
87  E_ALIVESTATE m_eAliveState;
88 
89  // Callbacks
90  std::function<void()> m_SendProbeCallback;
91  std::function<void()> m_ChangeBaudrateCallback;
92 
93  // Timer and timer handlers
94  boost::asio::deadline_timer m_StateTimer;
95  boost::asio::deadline_timer m_ProbeTimer;
96  void OnStateTimeout();
97  void OnProbeTimeout();
98 
99  // Observation
100  bool m_bFrameWasReceived;
101  int m_ProbeCounter;
102 };
103 
104 #endif // ALIVE_STATE_H
AliveState(boost::asio::io_service &a_IOService)
The constructor of AliveState objects.
Definition: AliveState.cpp:46
bool IsAlive() const
Query whether the related serialport is currently considered alive.
Definition: AliveState.cpp:141
void SetSendProbeCallback(std::function< void()> a_SendProbeCallback)
Register callback method for sending a probe request via HDLC.
Definition: AliveState.cpp:101
~AliveState()
The destructor of AliveState objects.
Definition: AliveState.cpp:54
bool OnFrameReceived()
Indicate that a HDLC frame was received via the related serial port.
Definition: AliveState.cpp:122
void Stop()
Stop all activities.
Definition: AliveState.cpp:89
void SetChangeBaudrateCallback(std::function< void()> a_ChangeBaudrateCallback)
Register callback method for changing the baud rate of the related serial port.
Definition: AliveState.cpp:111
void Start()
Start all activities.
Definition: AliveState.cpp:72
Class AliveState.
Definition: AliveState.h:52