// This file is part of an OMNeT++/OMNEST simulation example.
// Copyright (C) 2003-2008 Andras Varga
// This file is distributed WITHOUT ANY WARRANTY. See the file
// `license' for details on this and other legal matters.

#include <stdio.h>
#include <string.h>
#include <omnetpp.h>

class Txc3 : public cSimpleModule
    int counter;  // Note the counter here

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


void Txc3::initialize()
    // Initialize counter to ten. We'll decrement it every time and delete
    // the message when it reaches zero.
    counter = 10;

    // The WATCH() statement below will let you examine the variable under
    // Tkenv. After doing a few steps in the simulation, double-click either
    // `tic' or `toc', select the Contents tab in the dialog that pops up,
    // and you'll find "counter" in the list.

    if (strcmp("tic", getName()) == 0)
        EV << "Sending initial message\n";
        cMessage *msg = new cMessage("tictocMsg");
        send(msg, "out");

void Txc3::handleMessage(cMessage *msg)
    // Increment counter and check value.
    if (counter==0)
        // If counter is zero, delete message. If you run the model, you'll
        // find that the simulation will stop at this point with the message
        // "no more events".
        EV << getName() << "'s counter reached zero, deleting message\n";
        delete msg;
        EV << getName() << "'s counter is " << counter << ", sending back message\n";
        send(msg, "out");

Generated on Tue Dec 2 11:16:33 2014 for Tictoc Tutorial by  doxygen 1.6.3