samples/main-random-walk.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 02 Jul 2007 15:08:10 +0200
changeset 1555 d3e9007db75b
parent 1554 76e781c120bb
child 1556 2d5363ef077f
permissions -rw-r--r--
improve sample code, make it build

/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */

#include "ns3/ptr.h"
#include "ns3/position.h"
#include "ns3/position-set-notifier.h"
#include "ns3/random-walk-position.h"
#include "ns3/default-value.h"
#include "ns3/command-line.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"

using namespace ns3;

static void 
CourseChange (Ptr<const Position> position)
{
  double x, y, z;
  position->Get (x, y, z);
  std::cout << "pos=" << position << ", x=" << x << ", y=" << y << ", z=" << z << std::endl;
}

int main (int argc, char *argv[])
{
  Bind ("RandomWalkMinSpeed", "2");
  Bind ("RandomWalkMaxSpeed", "3");
  Bind ("RandomWalkMode", "Time");
  Bind ("RandomWalkModeDistance", "20");
  Bind ("RandomWalkModeTime", "2s");

  CommandLine::Parse (argc, argv);

  Ptr<PositionSetNotifier> notifier = Create<PositionSetNotifier> ();
  Ptr<RandomWalkPosition> position = Create<RandomWalkPosition> ();
  position->AddInterface (notifier);
  notifier->RegisterListener (MakeCallback (&CourseChange));

  Simulator::StopAt (Seconds (10.0));

  Simulator::Run ();
  
  return 0;
}