-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientFully.cpp
More file actions
65 lines (53 loc) · 1.58 KB
/
ClientFully.cpp
File metadata and controls
65 lines (53 loc) · 1.58 KB
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
64
65
#include <string>
#include "ClientNetwork.hpp"
using namespace omnetpp;
class ClientFully : public ClientNetwork
{
public:
ClientFully();
protected:
virtual void initialize() override;
virtual void sendToAll(cMessage *msg) override;
virtual void forward(cMessage *msg) override;
private:
int myIndex;
};
Define_Module(ClientFully);
ClientFully::ClientFully() : ClientNetwork(), myIndex(-1) {}
void ClientFully::initialize()
{
ClientNetwork::initialize();
std::string fullName = this->getFullName();
std::string index = fullName.substr(fullName.find("[") + 1, fullName.find("]") - fullName.find("[") - 1);
std::cout << "Index: " << index << "name: " << fullName << std::endl;
this->myIndex = std::stoi(index);
this->timeToLive = 1;
}
void ClientFully::sendToAll(cMessage *msg)
{
for(int i = 0; i < gateSize("out"); i++) {
if(i != this->myIndex) {
cMessage *cMsg = msg->dup();
try{
send(cMsg, "out", i);
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
}
}
}
void ClientFully::forward(cMessage *msg)
{
for(int i = 0; i < gateSize("out"); i++) {
if(std::string(msg->getArrivalGate()->getFullName()) != "in" + std::to_string(i)) {
if(i != this->myIndex) {
cMessage *cMsg = msg->dup();
try{
send(cMsg, "out", i);
} catch(cRuntimeError e) {
cancelAndDelete(cMsg);
}
}
}
}
}