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

Txc5 Class Reference

Inheritance diagram for Txc5:

cSimpleModule cModule cDefaultList cObject cPolymorphic List of all members.

Detailed Description

In the previous models, `tic' and `toc' immediately sent back the received message. Here we'll add some timing: tic and toc will hold the message for 1 simulated second before sending it back. In OMNeT++ such timing is achieved by the module sending a message to itself. Such messages are called self-messages (but only because of the way they are used, otherwise they are completely ordinary messages) or events. Self-messages can be "sent" with the scheduleAt() function, and you can specify when they should arrive back at the module.

We leave out the counter, to keep the source code small.


Public Member Functions

 Module_Class_Members (Txc5, cSimpleModule, 0)
virtual void initialize ()
virtual void handleMessage (cMessage *msg)

Protected Attributes

cMessage * event
cMessage * tictocMsg


Member Function Documentation

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

Reimplemented from cSimpleModule.

00062 {
00063     // There are several ways of distinguishing messages, for example by message
00064     // kind (an int attribute of cMessage) or by class using dynamic_cast
00065     // (provided you subclass from cMessage). In this code we just check if we
00066     // recognize the pointer, which (if feasible) is the easiest and fastest
00067     // method.
00068     if (msg==event)
00069     {
00070         // The self-message arrived, so we can send out tictocMsg and NULL out
00071         // its pointer so that it doesn't confuse us later.
00072         ev << "Wait period is over, sending back message\n";
00073         send(tictocMsg, "out");
00074         tictocMsg = NULL;
00075     }
00076     else
00077     {
00078         // If the message we received is not our self-message, then it must
00079         // be the tic-toc message arriving from our partner. We remember its
00080         // pointer in the tictocMsg variable, then schedule our self-message
00081         // to come back to us in 1s simulated time.
00082         ev << "Message arrived, starting to wait 1 sec...\n";
00083         tictocMsg = msg;
00084         scheduleAt(simTime()+1.0, event);
00085     }
00086 }

void Txc5::initialize (   )  [virtual]
 

Reimplemented from cModule.

00043 {
00044     // Create the event object we'll use for timing -- just any ordinary message.
00045     event = new cMessage("event");
00046 
00047     // No tictoc message yet.
00048     tictocMsg = NULL;
00049 
00050     if (strcmp("tic", name()) == 0)
00051     {
00052         // We don't start right away, but instead send an message to ourselves
00053         // (a "self-message") -- we'll do the first sending when it arrives
00054         // back to us, at t=5.0s simulated time.
00055         ev << "Scheduling first send to t=5.0s\n";
00056         tictocMsg = new cMessage("tictocMsg");
00057         scheduleAt(5.0, event);
00058     }
00059 }

Txc5::Module_Class_Members (  Txc5  ,
cSimpleModule  ,
0 
) 
 


Member Data Documentation

cMessage* Txc5::event [protected]
 

cMessage* Txc5::tictocMsg [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