Protected Member Functions | |
virtual void | forwardMessage (cMessage *msg) |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
Let's make it more interesting by using several (n) `tic' modules, and connecting every module to every other. For now, let's keep it simple what they do: module 0 generates a message, and the others keep tossing it around in random directions until it arrives at module 2.
void Txc12::forwardMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Referenced by handleMessage().
00061 { 00062 // In this example, we just pick a random gate to send it on. 00063 // We draw a random number between 0 and the size of gate `gate[]'. 00064 int n = gateSize("gate"); 00065 int k = intuniform(0,n-1); 00066 00067 EV << "Forwarding message " << msg << " on gate[" << k << "]\n"; 00068 // $o and $i suffix is used to identify the input/output part of a two way gate 00069 send(msg, "gate$o", k); 00070 }
void Txc12::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from cSimpleModule.
00046 { 00047 if (getIndex()==3) 00048 { 00049 // Message arrived. 00050 EV << "Message " << msg << " arrived.\n"; 00051 delete msg; 00052 } 00053 else 00054 { 00055 // We need to forward the message. 00056 forwardMessage(msg); 00057 } 00058 }
void Txc12::initialize | ( | ) | [protected, virtual] |
Reimplemented from cComponent.
00034 { 00035 if (getIndex()==0) 00036 { 00037 // Boot the process scheduling the initial message as a self-message. 00038 char msgname[20]; 00039 sprintf(msgname, "tic-%d", getIndex()); 00040 cMessage *msg = new cMessage(msgname); 00041 scheduleAt(0.0, msg); 00042 } 00043 }