a b/src/DAF/CDAP/CDAP.cc
1
//
2
// This program is free software: you can redistribute it and/or modify
3
// it under the terms of the GNU Lesser General Public License as published by
4
// the Free Software Foundation, either version 3 of the License, or
5
// (at your option) any later version.
6
// 
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
// GNU Lesser General Public License for more details.
11
// 
12
// You should have received a copy of the GNU Lesser General Public License
13
// along with this program.  If not, see http://www.gnu.org/licenses/.
14
// 
15
16
#include "CDAP.h"
17
18
Define_Module(CDAP);
19
20
void CDAP::initialize()
21
{
22
    initSignalsAndListeners();
23
}
24
25
void CDAP::handleMessage(cMessage* msg)
26
{
27
    //Pass CDAP message to AE or RIBd
28
    if (dynamic_cast<CDAPMessage*>(msg)) {
29
        CDAPMessage* cmsg = check_and_cast<CDAPMessage*>(msg);
30
        cmsg->setHandle(cmsg->getArrivalGate()->getIndex());
31
        signalizeReceiveData(cmsg);
32
    }
33
    //FIXME: Vesely - Proper disposing of object
34
    //delete msg;
35
}
36
37
void CDAP::initSignalsAndListeners() {
38
    cModule* catcher = this->getParentModule()->getParentModule();
39
40
    //Signals emmited by this module
41
    sigCDAPReceiveData = registerSignal(SIG_CDAP_DateReceive);
42
43
    //Listeners registered to process signal
44
    lisCDAPSendData = new LisCDAPSendData(this);
45
    catcher->subscribe(SIG_AE_DataSend, lisCDAPSendData);
46
    catcher->subscribe(SIG_RIBD_DataSend, lisCDAPSendData);
47
}
48
49
void CDAP::sendData(CDAPMessage* cmsg) {
50
    //Change and take ownership
51
    Enter_Method("SendData()");
52
    take(check_and_cast<cOwnedObject*>(cmsg) );
53
54
    //Send message
55
    cGate* out = gateHalf(GATE_SPLITIO, cGate::OUTPUT, cmsg->getHandle());
56
    send(cmsg, out);
57
}
58
59
void CDAP::signalizeReceiveData(CDAPMessage* cmsg) {
60
    emit(sigCDAPReceiveData, cmsg);
61
}