Txc6 Class Reference

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

List of all members.

Public Member Functions

 Txc6 ()
virtual ~Txc6 ()

Protected Member Functions

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

Private Attributes

cMessageevent
cMessagetictocMsg

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.


Constructor & Destructor Documentation

Txc6::Txc6 (  ) 

00045 {
00046     // Set the pointer to NULL, so that the destructor won't crash
00047     // even if initialize() doesn't get called because of a runtime
00048     // error or user cancellation during the startup process.
00049     event = tictocMsg = NULL;
00050 }

Txc6::~Txc6 (  )  [virtual]

00053 {
00054     // Dispose of dynamically allocated the objects
00055     cancelAndDelete(event);
00056     delete tictocMsg;
00057 }


Member Function Documentation

void Txc6::handleMessage ( cMessage msg  )  [protected, virtual]

Reimplemented from cSimpleModule.

00079 {
00080     // There are several ways of distinguishing messages, for example by message
00081     // kind (an int attribute of cMessage) or by class using dynamic_cast
00082     // (provided you subclass from cMessage). In this code we just check if we
00083     // recognize the pointer, which (if feasible) is the easiest and fastest
00084     // method.
00085     if (msg==event)
00086     {
00087         // The self-message arrived, so we can send out tictocMsg and NULL out
00088         // its pointer so that it doesn't confuse us later.
00089         EV << "Wait period is over, sending back message\n";
00090         send(tictocMsg, "out");
00091         tictocMsg = NULL;
00092     }
00093     else
00094     {
00095         // If the message we received is not our self-message, then it must
00096         // be the tic-toc message arriving from our partner. We remember its
00097         // pointer in the tictocMsg variable, then schedule our self-message
00098         // to come back to us in 1s simulated time.
00099         EV << "Message arrived, starting to wait 1 sec...\n";
00100         tictocMsg = msg;
00101         scheduleAt(simTime()+1.0, event);
00102     }
00103 }

void Txc6::initialize (  )  [protected, virtual]

Reimplemented from cComponent.

00060 {
00061     // Create the event object we'll use for timing -- just any ordinary message.
00062     event = new cMessage("event");
00063 
00064     // No tictoc message yet.
00065     tictocMsg = NULL;
00066 
00067     if (strcmp("tic", getName()) == 0)
00068     {
00069         // We don't start right away, but instead send an message to ourselves
00070         // (a "self-message") -- we'll do the first sending when it arrives
00071         // back to us, at t=5.0s simulated time.
00072         EV << "Scheduling first send to t=5.0s\n";
00073         tictocMsg = new cMessage("tictocMsg");
00074         scheduleAt(5.0, event);
00075     }
00076 }


Member Data Documentation

cMessage* Txc6::event [private]

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

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


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:33 2014 for Tictoc Tutorial by  doxygen 1.6.3