Files
unison/samples/main-simulator.cc

48 lines
989 B
C++
Raw Normal View History

2006-09-05 13:18:11 +02:00
/* -*- Mode:C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:f -*- */
2006-08-29 17:51:04 +02:00
#include "ns3/simulator.h"
2006-09-03 12:24:04 +02:00
#include "ns3/time.h"
2006-08-29 17:47:17 +02:00
#include <iostream>
2006-08-29 17:55:34 +02:00
using namespace ns3;
2006-08-29 17:47:17 +02:00
class MyModel {
public:
2006-09-05 13:18:11 +02:00
void start (void);
2006-08-29 17:47:17 +02:00
private:
2006-09-05 13:18:11 +02:00
void dealWithEvent (double eventValue);
2006-08-29 17:47:17 +02:00
};
void
MyModel::start (void)
{
2006-09-05 13:18:11 +02:00
Simulator::schedule (Time::relS (10.0),
&MyModel::dealWithEvent,
this, Simulator::now ().s ());
2006-08-29 17:47:17 +02:00
}
void
MyModel::dealWithEvent (double value)
2006-08-29 17:47:17 +02:00
{
2006-09-05 13:18:11 +02:00
std::cout << "Member method received event at " << Simulator::now ().s () <<
"s started at " << value << "s" << std::endl;
2006-08-29 17:47:17 +02:00
}
static void
random_function (MyModel *model)
{
2006-09-05 13:18:11 +02:00
std::cout << "random function received event at " <<
Simulator::now ().s () << "s" << std::endl;
model->start ();
2006-08-29 17:47:17 +02:00
}
int main (int argc, char *argv[])
{
2006-09-05 13:18:11 +02:00
MyModel model;
2006-08-29 17:47:17 +02:00
2006-09-05 13:18:11 +02:00
Simulator::schedule (Time::absS (10.0), &random_function, &model);
2006-08-29 17:47:17 +02:00
2006-09-05 13:18:11 +02:00
Simulator::run ();
2006-08-29 17:47:17 +02:00
2006-09-05 13:18:11 +02:00
Simulator::destroy ();
2006-08-29 17:47:17 +02:00
}