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 |
In the previous model we just created another packet if we needed to retransmit. This is OK because the packet didn't contain much, but in real life it's usually more practical to keep a copy of the original packet so that we can re-send it without the need to build it again.
Tic9::Tic9 | ( | ) |
00043 { 00044 timeoutEvent = message = NULL; 00045 }
Tic9::~Tic9 | ( | ) | [virtual] |
00048 { 00049 cancelAndDelete(timeoutEvent); 00050 delete message; 00051 }
cMessage * Tic9::generateNewMessage | ( | ) | [protected, virtual] |
Referenced by handleMessage(), and initialize().
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 }
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::sendCopyOf | ( | cMessage * | msg | ) | [protected, virtual] |
Referenced by handleMessage(), and initialize().
cMessage* Tic9::message [private] |
Referenced by handleMessage(), initialize(), Tic9(), and ~Tic9().
int Tic9::seq [private] |
Referenced by generateNewMessage(), and initialize().
simtime_t Tic9::timeout [private] |
Referenced by handleMessage(), and initialize().
cMessage* Tic9::timeoutEvent [private] |
Referenced by handleMessage(), initialize(), Tic9(), and ~Tic9().