layer.hh
Go to the documentation of this file.
#pragma once
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include "Params.hh"
class OCTETSTRING;
class BITSTRING;
class CHARSTRING;
class INTEGER;
class layer {
std::vector<layer*> upperLayers;
std::vector<layer*> lowerLayers;
protected:
std::string type;
public:
explicit layer() : upperLayers(), lowerLayers(), type(std::string("")) { };
explicit layer(const std::string& p_type) : upperLayers(), lowerLayers(), type(std::string(p_type.begin(), p_type.end())) { };
virtual ~layer() {
// Double linked list, only remove layers in lowerLayers from the lowest one
std::for_each(lowerLayers.rbegin(), lowerLayers.rend(), [](layer* it) { delete it; } );
lowerLayers.clear();
upperLayers.clear();
};
void delete_layer() { };
public:
inline void add_upper_layer(layer* p_layer) {
if (p_layer != NULL) {
upperLayers.push_back(p_layer);
p_layer->lowerLayers.push_back(this);
};
};
void remove_upper_layer(layer* p_layer) { };
virtual void send_data(OCTETSTRING& p_data, Params& p_params) { };
virtual void receive_data(OCTETSTRING& p_data, Params& p_params) { }
inline const std::string& to_string() const { return type; };
protected:
inline void to_all_layers(std::vector<layer*>&layers, OCTETSTRING& data, Params& params) {
for (std::vector<layer*>::const_iterator it = layers.cbegin(); it != layers.cend(); ++it) {
layer* p = *it;
p->receive_data(data, params); // FIXME BUG I
} // End of 'for' statement
};
inline void receive_to_all_layers(OCTETSTRING& data, Params& params) {
for (std::vector<layer*>::const_iterator it = upperLayers.cbegin(); it != upperLayers.cend(); ++it) {
layer* p = *it;
p->receive_data(data, params);
} // End of 'for' statement
};
inline void send_to_all_layers(OCTETSTRING& data, Params& params) {
for (std::vector<layer*>::const_iterator it = lowerLayers.cbegin(); it != lowerLayers.cend(); ++it) {
layer* p = *it;
p->send_data(data, params);
} // End of 'for' statement
};
}; // End of class layer
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