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
layer::send_data
virtual void send_data(OCTETSTRING &p_data, Params &p_params)
Send bytes formated data to the lower layers.
Definition: layer.hh:101
layer::lowerLayers
std::vector< layer * > lowerLayers
List of the upper protocol layers.
Definition: layer.hh:31
layer::layer
layer(const std::string &p_type)
Specialized constructor Create a new instance of the layer class with its type description.
Definition: layer.hh:50
layer
Forward declaration of TITAN class.
Definition: layer.hh:29
std
layer::receive_data
virtual void receive_data(OCTETSTRING &p_data, Params &p_params)
Receive bytes formated data from the lower layers.
Definition: layer.hh:112
layer::receive_to_all_layers
void receive_to_all_layers(OCTETSTRING &data, Params &params)
Definition: layer.hh:130
layer::layer
layer()
Type description, it indicates the protocol type (e.g. CAM, DENM, GN, ETH, PCAP...)
Definition: layer.hh:41
layer::to_all_layers
void to_all_layers(std::vector< layer *> &layers, OCTETSTRING &data, Params &params)
Definition: layer.hh:123
Params.hh
Header file for the parameter dictionary.
layer::type
std::string type
List of the lower protocol layers.
Definition: layer.hh:34
Params
This class provides basic functionalities for an ITS dictionary.
Definition: Params.hh:21
layer::upperLayers
std::vector< layer * > upperLayers
Definition: layer.hh:30
layer::to_string
const std::string & to_string() const
Remove the specified upper layer protocol from the list of the upper layer.
Definition: layer.hh:120
layer::send_to_all_layers
void send_to_all_layers(OCTETSTRING &data, Params &params)
Definition: layer.hh:137
layer::delete_layer
void delete_layer()
Delete this layer.
Definition: layer.hh:68
layer::add_upper_layer
void add_upper_layer(layer *p_layer)
Add a new layer in the list of the upper layer.
Definition: layer.hh:77
layer::~layer
virtual ~layer()
Default destructor.
Definition: layer.hh:56
layer::remove_upper_layer
void remove_upper_layer(layer *p_layer)
Remove the specified upper layer protocol from the list of the upper layer.
Definition: layer.hh:90