SSP21-CPP
IUpperLayer.h
Go to the documentation of this file.
1 #ifndef SSP21_IUPPERLAYER_H
2 #define SSP21_IUPPERLAYER_H
3 
4 /** @file
5  * @brief Interface @ref ssp21::IUpperLayer.
6  */
7 
8 namespace ssp21
9 {
10 
11 /**
12  * @brief Performs asynchronous RX/TX operations on behalf of an @ref ILowerLayer.
13  *
14  * This class is used by @ref IStack. User of the library must implement this interface
15  * to send and receive the bytes to the host application.
16  */
18 {
19 public:
20  /**
21  * @brief Open the layer if it was closed.
22  * @return @cpp true @ce if the layer was originally closed, @cpp false @ce otherwise.
23  *
24  * Implementor of this class must implement @ref IUpperLayer::on_lower_open_impl().
25  */
26  inline bool on_lower_open()
27  {
28  if (this->is_open_flag)
29  {
30  return false;
31  }
32  else
33  {
34  this->is_open_flag = true;
35  this->on_lower_open_impl();
36  return true;
37  }
38  }
39 
40  /**
41  * @brief Close the layer if it was open.
42  * @return @cpp true @ce if the layer was originally open, @cpp false @ce otherwise.
43  *
44  * Implementor of this class must implement @ref IUpperLayer::on_lower_close_impl().
45  */
46  inline bool on_lower_close()
47  {
48  if (this->is_open_flag)
49  {
50  this->is_open_flag = false;
51  this->on_lower_close_impl();
52  return true;
53  }
54  else
55  {
56  return false;
57  }
58  }
59 
60  /**
61  * @brief Called by the @ref ILowerLayer when it's ready to transmit data.
62  * @return @cpp true @ce if the layer is open, @cpp false @ce otherwise.
63  *
64  * Implementor of this class must implement @ref IUpperLayer::on_lower_tx_ready_impl().
65  */
66  inline bool on_lower_tx_ready()
67  {
68  if (this->is_open_flag)
69  {
70  this->on_lower_tx_ready_impl();
71  return true;
72  }
73  else
74  {
75  return false;
76  }
77  }
78 
79  /**
80  * @brief Called by the @ref ILowerLayer when new data is available.
81  * @return @cpp true @ce if the layer is open, @cpp false @ce otherwise.
82  *
83  * Implementor of this class must implement @ref IUpperLayer::on_lower_rx_ready_impl().
84  */
85  inline bool on_lower_rx_ready()
86  {
87  if (this->is_open_flag)
88  {
89  this->on_lower_rx_ready_impl();
90  return true;
91  }
92  else
93  {
94  return false;
95  }
96  }
97 
98  /**
99  * @brief Check if layer is currently open.
100  * @return @cpp true @ce if the layer is open, @cpp false @ce otherwise.
101  */
102  inline bool is_open() const
103  {
104  return is_open_flag;
105  }
106 
107 protected:
108  /**
109  * @brief Open the layer.
110  *
111  * See @ref IUpperLayer::on_lower_open()
112  */
113  virtual void on_lower_open_impl() = 0;
114 
115  /**
116  * @brief Close the layer.
117  *
118  * See @ref IUpperLayer::on_lower_close()
119  */
120  virtual void on_lower_close_impl() = 0;
121 
122  /**
123  * @brief Callback when @ref ILowerLayer is ready to transmit data.
124  *
125  * See @ref IUpperLayer::on_lower_tx_ready()
126  */
127  virtual void on_lower_tx_ready_impl() = 0;
128 
129  /**
130  * @brief Callback when @ref ILowerLayer received data.
131  *
132  * See @ref IUpperLayer::on_lower_rx_ready()
133  */
134  virtual void on_lower_rx_ready_impl() = 0;
135 
136 private:
137  bool is_open_flag = false;
138 };
139 
140 }
141 
142 #endif
SSP21-cpp main namespace.
Definition: BufferTypes.h:12
bool on_lower_close()
Close the layer if it was open.
Definition: IUpperLayer.h:46
bool on_lower_tx_ready()
Called by the ILowerLayer when it's ready to transmit data.
Definition: IUpperLayer.h:66
virtual void on_lower_open_impl()=0
Open the layer.
bool on_lower_rx_ready()
Called by the ILowerLayer when new data is available.
Definition: IUpperLayer.h:85
virtual void on_lower_close_impl()=0
Close the layer.
bool is_open() const
Check if layer is currently open.
Definition: IUpperLayer.h:102
virtual void on_lower_tx_ready_impl()=0
Callback when ILowerLayer is ready to transmit data.
Performs asynchronous RX/TX operations on behalf of an ILowerLayer.
Definition: IUpperLayer.h:17
virtual void on_lower_rx_ready_impl()=0
Callback when ILowerLayer received data.
bool on_lower_open()
Open the layer if it was closed.
Definition: IUpperLayer.h:26