Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef LAYER_H
#define LAYER_H
#include <string>
#include <map>
#include <vector>
typedef std::map<std::string, std::string> Params;
class OCTETSTRING;
class Layer {
std::vector<Layer*> upperLayers;
std::vector<Layer*> lowerLayers;
public:
Layer(){}
public:
void addUpperLayer(Layer*);
void removeUpperLayer(Layer*);
virtual void sendData(const OCTETSTRING& data, const Params& params);
virtual void receiveData(const OCTETSTRING& data, const Params& info);
protected:
void toAllLayers(std::vector<Layer*>&layers, const OCTETSTRING& data, const Params& info);
inline void receiveToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(upperLayers, data, info); }
inline void sendToAllLayers(const OCTETSTRING& data, const Params& info) { toAllLayers(lowerLayers, data, info); }
};
template <typename TPort> class TLayer : public Layer {
typedef std::vector<TPort*> TPortList;
TPortList upperPorts;
public:
TLayer(){}
void addUpperPort(TPort*);
void removeUpperPort(TPort*);
/*
template <typename Msg> void receiveToAllPorts(Msg* m, const Param& param) {
for(TPortList::iterator it=upperPorts.begin(); it<upperPorts.end(); ++it){
(*it)->receiveMsg(m, param);
}
}
*/
};
class LayerFactory {
public:
LayerFactory(){}
virtual Layer * createLayer(const std::string & type, const std::string & param) = 0;
};
class StackFactory {
static StackFactory * _instance;
std::map<std::string,LayerFactory*> _fs;
public:
static StackFactory * getInstance();
void registerLayerFactory(const std::string & type, LayerFactory * f);
Layer* createLayerStack(const char*);
};
#endif