# Txc5 Class Reference

Inheritance diagram for Txc5:

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

| Txc5 ()
virtual | ~Txc5 ()

## Protected Member Functions

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

## Private Attributes

cMessage * | event
cMessage * | tictocMsg

## Constructor & Destructor Documentation

Txc5::Txc5 | ( |  | ) |

    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 }

Txc5::~Txc5 | ( |  | ) | `[virtual]`

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

## Member Function Documentation

void Txc5::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 Txc5::initialize | ( |  | ) | `[protected, virtual]`

Reimplemented from cModule.

    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", name()) == 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* Txc5::event`[private]`

cMessage* Txc5::tictocMsg`[private]`

The documentation for this class was generated from the following file:

- txc5.cc