Tic9 Class Reference

Inheritance diagram for Tic9:
cSimpleModule cModule cComponent cDefaultList cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject

List of all members.

Public Member Functions

 Tic9 ()
virtual ~Tic9 ()

Protected Member Functions

virtual cMessagegenerateNewMessage ()
virtual void sendCopyOf (cMessage *msg)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Private Attributes

simtime_t timeout
cMessagetimeoutEvent
int seq
cMessagemessage

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.


Constructor & Destructor Documentation

Tic9::Tic9 (  ) 

00043 {
00044     timeoutEvent = message = NULL;
00045 }

Tic9::~Tic9 (  )  [virtual]

00048 {
00049     cancelAndDelete(timeoutEvent);
00050     delete message;
00051 }


Member Function Documentation

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::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().

00105 {
00106     // Duplicate message and send the copy.
00107     cMessage *copy = (cMessage *) msg->dup();
00108     send(copy, "out");
00109 }


Member Data Documentation

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().

Referenced by handleMessage(), initialize(), Tic9(), and ~Tic9().


The documentation for this class was generated from the following file:
Generated on Fri Mar 7 17:19:45 2014 for Tictoc Tutorial by  doxygen 1.6.3