bug 251: mobility helper has no ascii output
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 28 Jul 2008 09:03:10 -0700
changeset 3491 b2de71af0e3f
parent 3490 973e8f700e58
child 3492 7e1c5827504f
bug 251: mobility helper has no ascii output
src/helper/mobility-helper.cc
src/helper/mobility-helper.h
--- a/src/helper/mobility-helper.cc	Mon Jul 28 08:59:05 2008 -0700
+++ b/src/helper/mobility-helper.cc	Mon Jul 28 09:03:10 2008 -0700
@@ -23,6 +23,8 @@
 #include "ns3/hierarchical-mobility-model.h"
 #include "ns3/log.h"
 #include "ns3/pointer.h"
+#include "ns3/config.h"
+#include "ns3/simulator.h"
 
 namespace ns3 {
 
@@ -153,4 +155,38 @@
   Install (NodeContainer::GetGlobal ());
 }
 
+void
+MobilityHelper::CourseChanged (std::ostream *os, Ptr<const MobilityModel> mobility)
+{
+  Ptr<Node> node = mobility->GetObject<Node> ();
+  *os << "now=" << Simulator::Now ()
+      << " node=" << node->GetId () 
+      << " pos=" << mobility->GetPosition () 
+      << " vel=" << mobility->GetVelocity ()
+      << std::endl;
+}
+
+void 
+MobilityHelper::EnableAscii (std::ostream &os, uint32_t nodeid)
+{
+  std::ostringstream oss;
+  oss << "/NodeList/" << nodeid << "/$ns3::MobilityModel/CourseChange";
+  Config::ConnectWithoutContext (oss.str (), 
+                                 MakeBoundCallback (&MobilityHelper::CourseChanged, &os));
+}
+void 
+MobilityHelper::EnableAscii (std::ostream &os, NodeContainer n)
+{
+  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
+    {
+      EnableAscii (os, (*i)->GetId ());
+    }
+}
+void 
+MobilityHelper::EnableAsciiAll (std::ostream &os)
+{
+  EnableAscii (os, NodeContainer::GetGlobal ());
+}
+
+
 } // namespace ns3
--- a/src/helper/mobility-helper.h	Mon Jul 28 08:59:05 2008 -0700
+++ b/src/helper/mobility-helper.h	Mon Jul 28 09:03:10 2008 -0700
@@ -163,8 +163,36 @@
    * exist in the simulation.
    */
   void InstallAll (void);
+
+  /**
+   * \param os output stream
+   * \param nodeid the id of the node to generate ascii output for.
+   *
+   * Enable ascii output on the mobility model associated to the
+   * specified nodeid and dump that to the specified stdc++ output 
+   * stream.
+   */
+  static void EnableAscii (std::ostream &os, uint32_t nodeid);
+  /**
+   * \param os output stream
+   * \param n node container
+   *
+   * Enable ascii output on the mobility model associated each of
+   * the nodes in the input container and dump that to the 
+   * specified stdc++ output stream.
+   */
+  static void EnableAscii (std::ostream &os, NodeContainer n);
+  /**
+   * \param os output stream
+   *
+   * Enable ascii output on the mobility model associated
+   * every node in the system and dump that to the specified 
+   * stdc++ output stream.
+   */
+  static void EnableAsciiAll (std::ostream &os);
+
 private:
-
+  static void CourseChanged (std::ostream *os, Ptr<const MobilityModel> mobility);
   std::vector<Ptr<MobilityModel> > m_mobilityStack;
   ObjectFactory m_mobility;
   Ptr<PositionAllocator> m_position;