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 
42  explicit Layer() : upperLayers(), lowerLayers(), type(std::string("")) { };
43 
51  explicit Layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { };
52 
57  virtual ~Layer() {
58  // Double linked list, only remove layers in lowerLayers from the lowest one
59  std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](Layer* it) { delete it; } );
60  lowerLayers.clear();
61  upperLayers.clear();
62  };
63 
69  void deleteLayer() { };
70 
71 public:
72 
79  inline void addUpperLayer(Layer* p_layer) {
80  if (p_layer != NULL) {
81  upperLayers.push_back(p_layer);
82  p_layer->lowerLayers.push_back(this);
83  };
84  };
85 
92  void removeUpperLayer(Layer* p_layer) { };
93 
103  virtual void sendData(OCTETSTRING& p_data, Params& p_params) { };
104 
114  virtual void receiveData(OCTETSTRING& p_data, Params& p_params) { }
115 
122  inline const std::string& to_string() const { return type; };
123 
124 protected:
125  inline void toAllLayers(std::vector<Layer*>&layers, OCTETSTRING& data, Params& params) {
126  for (std::vector<Layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
127  Layer * p = *it;
128  p->receiveData(data, params); // FIXME BUG I
129  } // End of 'for' statement
130  };
131 
132  inline void receiveToAllLayers(OCTETSTRING& data, Params& params) {
133  for (std::vector<Layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
134  Layer * p = *it;
135  p->receiveData(data, params);
136  } // End of 'for' statement
137  };
138 
139  inline void sendToAllLayers(OCTETSTRING& data, Params& params) {
140  for (std::vector<Layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
141  Layer * p = *it;
142  p->sendData(data, params);
143  } // End of 'for' statement
144  };
145 }; // End of class Layer
146 
void toAllLayers(std::vector< Layer *> &layers, OCTETSTRING &data, Params &params)
Definition: Layer.hh:125
Forward declaration of TITAN class.
Definition: Layer.hh:29
Layer()
Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...)
Definition: Layer.hh:42
void deleteLayer()
Delete this layer.
Definition: Layer.hh:69
virtual void sendData(OCTETSTRING &p_data, Params &p_params)
Send bytes formated data to the lower layers.
Definition: Layer.hh:103
Header file for the parameter dictionary.
void receiveToAllLayers(OCTETSTRING &data, Params &params)
Definition: Layer.hh:132
Layer(const std::string &p_type)
Specialized constructor Create a new instance of the Layer class with its type description.
Definition: Layer.hh:51
void removeUpperLayer(Layer *p_layer)
Remove the specified upper layer protocol from the list of the upper layer.
Definition: Layer.hh:92
void sendToAllLayers(OCTETSTRING &data, Params &params)
Definition: Layer.hh:139
This class provides basic functionalities for an ITS dictionary.
Definition: Params.hh:21
const std::string & to_string() const
Remove the specified upper layer protocol from the list of the upper layer.
Definition: Layer.hh:122
std::string type
List of the lower protocol layers.
Definition: Layer.hh:34
std::vector< Layer * > lowerLayers
List of the upper protocol layers.
Definition: Layer.hh:31
std::vector< Layer * > upperLayers
Definition: Layer.hh:30
virtual void receiveData(OCTETSTRING &p_data, Params &p_params)
Receive bytes formated data from the lower layers.
Definition: Layer.hh:114
void addUpperLayer(Layer *p_layer)
Add a new layer in the list of the upper layer.
Definition: Layer.hh:79
virtual ~Layer()
Default destructor.
Definition: Layer.hh:57