# Tic8 Class Reference

Inheritance diagram for Tic8:

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

| Tic8 ()
virtual | ~Tic8 ()

## Protected Member Functions

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

## Private Attributes

double | timeout
cMessage * | timeoutEvent
int | seq
cMessage * | message

## Constructor & Destructor Documentation

Tic8::Tic8 | ( |  | ) |

    00043 {
    00044     timeoutEvent = message = NULL;
    00045 }

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

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

## Member Function Documentation

cMessage * Tic8::generateNewMessage | ( |  | ) | `[protected, virtual]`

    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 Tic8::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->name() << "\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 Tic8::initialize | ( |  | ) | `[protected, virtual]`

Reimplemented from cModule.

    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 Tic8::sendCopyOf | ( | cMessage * | msg | ) | `[protected, virtual]`

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

## Member Data Documentation

cMessage* Tic8::message`[private]`

int Tic8::seq`[private]`

double Tic8::timeout`[private]`

cMessage* Tic8::timeoutEvent`[private]`

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

- txc8.cc