samples/main-simulator.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 21 Nov 2006 15:50:09 +0100
changeset 162 5b398ac221c7
parent 150 663120712cd9
child 163 2a7e05018eeb
permissions -rw-r--r--
make Time relative instead of Absolute

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#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 (Seconds (10.0), 
                       &MyModel::DealWithEvent, 
                       this, Simulator::Now ().ApproximateToSeconds ());
}
void
MyModel::DealWithEvent (double value)
{
  std::cout << "Member method received event at " << Simulator::Now ().ApproximateToSeconds () 
            << "s started at " << value << "s" << std::endl;
}

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


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

  Simulator::Schedule (Seconds (10.0), &random_function, &model);

  Simulator::Run ();

  Simulator::Destroy ();
}