
Public Member Functions | |
| Tic9 () | |
| virtual | ~Tic9 () |
Protected Member Functions | |
| virtual cMessage * | generateNewMessage () |
| virtual void | sendCopyOf (cMessage *msg) |
| virtual void | initialize () |
| virtual void | handleMessage (cMessage *msg) |
Private Attributes | |
| simtime_t | timeout |
| cMessage * | timeoutEvent |
| int | seq |
| cMessage * | message |
| Tic9::Tic9 | ( | ) |
| Tic9::~Tic9 | ( | ) | [virtual] |
| cMessage * Tic9::generateNewMessage | ( | ) | [protected, virtual] |
Referenced by handleMessage(), and initialize().
00096 { 00097 // Generate a message with a different name every time. 00098 char msgname[20]; 00099 sprintf(msgname, "tic-%d", ++seq); 00100 cMessage *msg = new cMessage(msgname); 00101 return msg; 00102 }
| void Tic9::sendCopyOf | ( | cMessage * | msg | ) | [protected, virtual] |
Referenced by handleMessage(), and initialize().
00105 { 00106 // Duplicate message and send the copy. 00107 cMessage *copy = (cMessage *) msg->dup(); 00108 send(copy, "out"); 00109 }
| void Tic9::initialize | ( | ) | [protected, virtual] |
Reimplemented from cComponent.
00054 { 00055 // Initialize variables. 00056 seq = 0; 00057 timeout = 1.0; 00058 timeoutEvent = new cMessage("timeoutEvent"); 00059 00060 // Generate and send initial message. 00061 EV << "Sending initial message\n"; 00062 message = generateNewMessage(); 00063 sendCopyOf(message); 00064 scheduleAt(simTime()+timeout, timeoutEvent); 00065 }
| void Tic9::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Reimplemented from cSimpleModule.
00068 { 00069 if (msg==timeoutEvent) 00070 { 00071 // If we receive the timeout event, that means the packet hasn't 00072 // arrived in time and we have to re-send it. 00073 EV << "Timeout expired, resending message and restarting timer\n"; 00074 sendCopyOf(message); 00075 scheduleAt(simTime()+timeout, timeoutEvent); 00076 } 00077 else // message arrived 00078 { 00079 // Acknowledgement received! 00080 EV << "Received: " << msg->getName() << "\n"; 00081 delete msg; 00082 00083 // Also delete the stored message and cancel the timeout event. 00084 EV << "Timer cancelled.\n"; 00085 cancelEvent(timeoutEvent); 00086 delete message; 00087 00088 // Ready to send another one. 00089 message = generateNewMessage(); 00090 sendCopyOf(message); 00091 scheduleAt(simTime()+timeout, timeoutEvent); 00092 } 00093 }
simtime_t Tic9::timeout [private] |
Referenced by handleMessage(), and initialize().
cMessage* Tic9::timeoutEvent [private] |
Referenced by handleMessage(), initialize(), Tic9(), and ~Tic9().
int Tic9::seq [private] |
Referenced by generateNewMessage(), and initialize().
cMessage* Tic9::message [private] |
Referenced by handleMessage(), initialize(), Tic9(), and ~Tic9().
1.5.5