GeoNetworkingLayer.cc 1.99 KB
Newer Older
garciay's avatar
garciay committed
1
2
3
4
5
#include "GeoNetworkingLayer.hh"
#include "GeoNetworkingTypes.hh"

#include "loggers.hh"

6
7
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & type, const std::string & param) : GeoNetworkingLayer() {
    loggers::loggers::log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", type.c_str(), param.c_str());
8
9
10
    // Setup parameters
    Params::convert(_params, param);
    _params.log();
11
12
}

garciay's avatar
garciay committed
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
void GeoNetworkingLayer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, const Params& params) {
    loggers::loggers::log(">>> GeoNetworkingLayer::sendMsg");
    const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu & pdu = p.msgOut();
    OCTETSTRING data;
    _codec.encode(pdu, data);
    const unsigned char mac_address[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
    data += OCTETSTRING(sizeof(mac_address), static_cast<const unsigned char *>(mac_address));
    sendData(data, params);
}

void GeoNetworkingLayer::sendData(const OCTETSTRING& data, const Params& params) {
    sendToAllLayers(data, params);
}

void GeoNetworkingLayer::receiveData(const OCTETSTRING& data, const Params& info) {
    LibItsGeoNetworking__TestSystem::GeoNetworkingInd p;
//    _codec.decode(data, p);

    toAllUpperPorts(p, info);

//    if (p.payload().is_present()) {
//        toAllUpperLayers(p.payload()().rawPayload(), info);
//    }
}

class GeoNetworkingFactory: public LayerFactory {
    static GeoNetworkingFactory _f;
public:
    GeoNetworkingFactory();
    virtual Layer * createLayer(const std::string & type,
            const std::string & param);
};

GeoNetworkingFactory::GeoNetworkingFactory() {
    // register factory
48
49
    loggers::loggers::log(">>> GeoNetworkingFactory::GeoNetworkingFactory");
    LayerStackBuilder::RegisterLayerFactory("GN", this);
garciay's avatar
garciay committed
50
51
52
}

Layer * GeoNetworkingFactory::createLayer(const std::string & type, const std::string & param) {
53
    return new GeoNetworkingLayer(type, param);
garciay's avatar
garciay committed
54
55
56
}

GeoNetworkingFactory GeoNetworkingFactory::_f;