-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientRing.cpp
63 lines (53 loc) · 1.37 KB
/
ClientRing.cpp
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
61
62
63
#include <string>
#include "ClientNetwork.hpp"
using namespace omnetpp;
class ClientRing : public ClientNetwork
{
public:
ClientRing();
protected:
virtual void initialize() override;
virtual void sendToAll(cMessage *msg) override;
virtual void forward(cMessage *msg) override;
};
Define_Module(ClientRing);
ClientRing::ClientRing() : ClientNetwork() {}
void ClientRing::initialize()
{
ClientNetwork::initialize();
this->timeToLive = getParentModule()->par("numClients").intValue() / 2;
}
void ClientRing::sendToAll(cMessage *msg)
{
cMessage *cMsg = msg->dup();
try{
send(cMsg, "out_left");
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
cMsg = msg->dup();
try{
send(cMsg, "out_right");
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
}
void ClientRing::forward(cMessage *msg)
{
if(std::string(msg->getArrivalGate()->getName()) == "in_left") {
cMessage *cMsg = msg->dup();
try{
send(cMsg, "out_right");
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
}
else if(std::string(msg->getArrivalGate()->getName()) == "in_right") {
cMessage *cMsg = msg->dup();
try{
send(cMsg, "out_left");
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
}
}