Files
unison/samples/main-simulator.cc

48 lines
995 B
C++
Raw Normal View History

2006-11-01 13:11:30 +01:00
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2006-08-29 17:51:04 +02:00
#include "ns3/simulator.h"
2006-10-02 11:41:40 +02:00
#include "ns3/nstime.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-11-01 13:11:30 +01:00
void Start (void);
2006-08-29 17:47:17 +02:00
private:
2006-11-01 13:11:30 +01:00
void DealWithEvent (double eventValue);
2006-08-29 17:47:17 +02:00
};
void
2006-10-06 13:37:25 +02:00
MyModel::Start (void)
2006-08-29 17:47:17 +02:00
{
2006-11-21 15:50:09 +01:00
Simulator::Schedule (Seconds (10.0),
2006-11-01 13:11:30 +01:00
&MyModel::DealWithEvent,
this, Simulator::Now ().GetSeconds ());
2006-08-29 17:47:17 +02:00
}
void
2006-10-06 13:37:25 +02:00
MyModel::DealWithEvent (double value)
2006-08-29 17:47:17 +02:00
{
std::cout << "Member method received event at " << Simulator::Now ().GetSeconds ()
2006-11-01 13:11:30 +01:00
<< "s started at " << value << "s" << std::endl;
2006-08-29 17:47:17 +02:00
}
static void
random_function (MyModel *model)
{
2006-11-01 13:11:30 +01:00
std::cout << "random function received event at " <<
Simulator::Now ().GetSeconds () << "s" << std::endl;
2006-11-01 13:11:30 +01:00
model->Start ();
2006-08-29 17:47:17 +02:00
}
int main (int argc, char *argv[])
{
2006-11-01 13:11:30 +01:00
MyModel model;
2006-08-29 17:47:17 +02:00
2006-11-21 15:50:09 +01:00
Simulator::Schedule (Seconds (10.0), &random_function, &model);
2006-08-29 17:47:17 +02:00
2006-11-01 13:11:30 +01:00
Simulator::Run ();
2006-08-29 17:47:17 +02:00
2006-11-01 13:11:30 +01:00
Simulator::Destroy ();
2006-08-29 17:47:17 +02:00
}