ETSI STF525 / Internal Testing test suite
This project provides an internal testing test suite and its associated Test Adapter/Codec
layer.hh
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <string>
14 #include <map>
15 #include <vector>
16 #include <algorithm>
17 
18 #include "Params.hh"
19 
20 class OCTETSTRING;
21 class BITSTRING;
22 class CHARSTRING;
23 class INTEGER;
24 
29 class layer {
30  std::vector<layer*> upperLayers;
31  std::vector<layer*> lowerLayers;
32 
33 protected:
34  std::string type;
35 
36 public:
37 
41  explicit layer() : upperLayers(), lowerLayers(), type(std::string("")) { };
42 
50  explicit layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { };
51 
56  virtual ~layer() {
57  // Double linked list, only remove layers in lowerLayers from the lowest one
58  std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](layer* it) { delete it; } );
59  lowerLayers.clear();
60  upperLayers.clear();
61  };
62 
68  void delete_layer() { };
69 
70 public:
71 
77  inline void add_upper_layer(layer* p_layer) {
78  if (p_layer != NULL) {
79  upperLayers.push_back(p_layer);
80  p_layer->lowerLayers.push_back(this);
81  };
82  };
83 
90  void remove_upper_layer(layer* p_layer) { };
91 
101  virtual void send_data(OCTETSTRING& p_data, Params& p_params) { };
102 
112  virtual void receive_data(OCTETSTRING& p_data, Params& p_params) { }
113 
120  inline const std::string& to_string() const { return type; };
121 
122 protected:
123  inline void to_all_layers(std::vector<layer*>&layers, OCTETSTRING& data, Params& params) {
124  for (std::vector<layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
125  layer* p = *it;
126  p->receive_data(data, params); // FIXME BUG I
127  } // End of 'for' statement
128  };
129 
130  inline void receive_to_all_layers(OCTETSTRING& data, Params& params) {
131  for (std::vector<layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
132  layer* p = *it;
133  p->receive_data(data, params);
134  } // End of 'for' statement
135  };
136 
137  inline void send_to_all_layers(OCTETSTRING& data, Params& params) {
138  for (std::vector<layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
139  layer* p = *it;
140  p->send_data(data, params);
141  } // End of 'for' statement
142  };
143 }; // End of class layer
144 
virtual void send_data(OCTETSTRING &p_data, Params &p_params)
Send bytes formated data to the lower layers.
Definition: layer.hh:101
std::vector< layer * > lowerLayers
List of the upper protocol layers.
Definition: layer.hh:31
layer(const std::string &p_type)
Specialized constructor Create a new instance of the layer class with its type description.
Definition: layer.hh:50
Forward declaration of TITAN class.
Definition: layer.hh:29
virtual void receive_data(OCTETSTRING &p_data, Params &p_params)
Receive bytes formated data from the lower layers.
Definition: layer.hh:112
void receive_to_all_layers(OCTETSTRING &data, Params &params)
Definition: layer.hh:130
layer()
Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...)
Definition: layer.hh:41
void to_all_layers(std::vector< layer *> &layers, OCTETSTRING &data, Params &params)
Definition: layer.hh:123
Header file for the parameter dictionary.
std::string type
List of the lower protocol layers.
Definition: layer.hh:34
This class provides basic functionalities for an ITS dictionary.
Definition: Params.hh:21
std::vector< layer * > upperLayers
Definition: layer.hh:30
const std::string & to_string() const
Remove the specified upper layer protocol from the list of the upper layer.
Definition: layer.hh:120
void send_to_all_layers(OCTETSTRING &data, Params &params)
Definition: layer.hh:137
void delete_layer()
Delete this layer.
Definition: layer.hh:68
void add_upper_layer(layer *p_layer)
Add a new layer in the list of the upper layer.
Definition: layer.hh:77
virtual ~layer()
Default destructor.
Definition: layer.hh:56
void remove_upper_layer(layer *p_layer)
Remove the specified upper layer protocol from the list of the upper layer.
Definition: layer.hh:90