Protected Member Functions | |
virtual void | initialize () |
virtual void | handleMessage (cMessage *msg) |
Private Attributes | |
int | counter |
In this class we add a counter, and delete the message after ten exchanges.
void Txc3::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from cSimpleModule.
00051 { 00052 // Increment counter and check value. 00053 counter--; 00054 if (counter==0) 00055 { 00056 // If counter is zero, delete message. If you run the model, you'll 00057 // find that the simulation will stop at this point with the message 00058 // "no more events". 00059 EV << getName() << "'s counter reached zero, deleting message\n"; 00060 delete msg; 00061 } 00062 else 00063 { 00064 EV << getName() << "'s counter is " << counter << ", sending back message\n"; 00065 send(msg, "out"); 00066 } 00067 }
void Txc3::initialize | ( | ) | [protected, virtual] |
Reimplemented from cComponent.
00031 { 00032 // Initialize counter to ten. We'll decrement it every time and delete 00033 // the message when it reaches zero. 00034 counter = 10; 00035 00036 // The WATCH() statement below will let you examine the variable under 00037 // Tkenv. After doing a few steps in the simulation, double-click either 00038 // `tic' or `toc', select the Contents tab in the dialog that pops up, 00039 // and you'll find "counter" in the list. 00040 WATCH(counter); 00041 00042 if (strcmp("tic", getName()) == 0) 00043 { 00044 EV << "Sending initial message\n"; 00045 cMessage *msg = new cMessage("tictocMsg"); 00046 send(msg, "out"); 00047 } 00048 }
int Txc3::counter [private] |
Referenced by handleMessage(), and initialize().