Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

Tic8 Class Reference

Inheritance diagram for Tic8:

cSimpleModule cModule cDefaultList cObject cPolymorphic List of all members.

Detailed Description

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.


Public Member Functions

 Module_Class_Members (Tic8, cSimpleModule, 0)
virtual cMessage * generateNewMessage ()
virtual void sendCopyOf (cMessage *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Protected Attributes

double timeout
cMessage * timeoutEvent
int seq
cMessage * message


Member Function Documentation

cMessage * Tic8::generateNewMessage (   )  [virtual]
 

00079 {
00080     // Generate a message with a different name every time.
00081     char msgname[20];
00082     sprintf(msgname, "tic-%d", ++seq);
00083     cMessage *msg = new cMessage(msgname);
00084     return msg;
00085 }

void Tic8::handleMessage (  cMessage *  msg  )  [virtual]
 

Reimplemented from cSimpleModule.

00054 {
00055     if (msg==timeoutEvent)
00056     {
00057         // If we receive the timeout event, that means the packet hasn't
00058         // arrived in time and we have to re-send it.
00059         ev << "Timeout expired, resending message and restarting timer\n";
00060         sendCopyOf(message);
00061         scheduleAt(simTime()+timeout, timeoutEvent);
00062     }
00063     else // message arrived
00064     {
00065         // Acknowledgement received -- delete the stored message and cancel
00066         // the timeout event.
00067         ev << "Timer cancelled.\n";
00068         cancelEvent(timeoutEvent);
00069         delete message;
00070 
00071         // Ready to send another one.
00072         message = generateNewMessage();
00073         sendCopyOf(message);
00074         scheduleAt(simTime()+timeout, timeoutEvent);
00075     }
00076 }

void Tic8::initialize (   )  [virtual]
 

Reimplemented from cModule.

00040 {
00041     // Initialize variables.
00042     seq = 0;
00043     timeout = 1.0;
00044     timeoutEvent = new cMessage("timeoutEvent");
00045 
00046     // Generate and send initial message.
00047     ev << "Sending initial message\n";
00048     message = generateNewMessage();
00049     sendCopyOf(message);
00050     scheduleAt(simTime()+timeout, timeoutEvent);
00051 }

Tic8::Module_Class_Members (  Tic8  ,
cSimpleModule  ,
0 
) 
 

void Tic8::sendCopyOf (  cMessage *  msg  )  [virtual]
 

00088 {
00089     // Duplicate message and send the copy.
00090     cMessage *copy = (cMessage *) msg->dup();
00091     send(copy, "out");
00092 }


Member Data Documentation

cMessage* Tic8::message [protected]
 

int Tic8::seq [protected]
 

double Tic8::timeout [protected]
 

cMessage* Tic8::timeoutEvent [protected]
 


The documentation for this class was generated from the following file:
Generated on Fri Apr 1 12:25:42 2005 for Tictoc Tutorial by  doxygen 1.3.9.1