samples/main-simulator.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 02 Oct 2006 11:41:40 +0200
changeset 108 6fd2357377ed
parent 54 f860e6f94787
child 110 9ac6d63bfe33
permissions -rw-r--r--
rename time.h to nstime.h

/* -*-    Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include <iostream>

using namespace ns3;

class MyModel {
public:
    void start (void);
private:
    void dealWithEvent (double eventValue);
};

void 
MyModel::start (void)
{
    Simulator::schedule (Time::relS (10.0), 
                 &MyModel::dealWithEvent, 
                 this, Simulator::now ().s ());
}
void
MyModel::dealWithEvent (double value)
{
    std::cout << "Member method received event at " << Simulator::now ().s () << 
        "s started at " << value << "s" << std::endl;
}

static void 
random_function (MyModel *model)
{
    std::cout << "random function received event at " << 
        Simulator::now ().s () << "s" << std::endl;
    model->start ();
}


int main (int argc, char *argv[])
{
    MyModel model;

    Simulator::schedule (Time::absS (10.0), &random_function, &model);

    Simulator::run ();

    Simulator::destroy ();
}