replace the adhoc mobility course change callbacks with a trace source
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 12 Aug 2007 18:28:37 +0200
changeset 1347 83786345b743
parent 1346 47de68729c86
child 1348 b77625f55e90
replace the adhoc mobility course change callbacks with a trace source
samples/main-random-topology.cc
src/mobility/hierarchical-mobility-model.cc
src/mobility/hierarchical-mobility-model.h
src/mobility/mobility-model-notifier.cc
src/mobility/mobility-model-notifier.h
--- a/samples/main-random-topology.cc	Sun Aug 12 18:28:13 2007 +0200
+++ b/samples/main-random-topology.cc	Sun Aug 12 18:28:37 2007 +0200
@@ -15,7 +15,7 @@
 using namespace ns3;
 
 static void 
-CourseChange (Ptr<const MobilityModel> position)
+CourseChange (const TraceContext &context, Ptr<const MobilityModel> position)
 {
   Position pos = position->Get ();
   std::cout << Simulator::Now () << ", pos=" << position << ", x=" << pos.x << ", y=" << pos.y
@@ -39,7 +39,7 @@
   for (uint32_t i = 0; i < 10000; i++)
     {
       Ptr<MobilityModelNotifier> notifier = Create<MobilityModelNotifier> ();
-      notifier->RegisterListener (MakeCallback (&CourseChange));
+      notifier->TraceConnect ("/course-change", MakeCallback (&CourseChange));
       objects.push_back (notifier);
     }
 
--- a/src/mobility/hierarchical-mobility-model.cc	Sun Aug 12 18:28:13 2007 +0200
+++ b/src/mobility/hierarchical-mobility-model.cc	Sun Aug 12 18:28:37 2007 +0200
@@ -41,8 +41,8 @@
       parentNotifier = Create<MobilityModelNotifier> ();
       parent->AddInterface (parentNotifier);
     }
-  childNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
-  parentNotifier->RegisterListener (MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
+  childNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
+  parentNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
 }
 
 Ptr<MobilityModel> 
@@ -89,13 +89,13 @@
 }
 
 void 
-HierarchicalMobilityModel::ParentChanged (Ptr<const MobilityModel> model)
+HierarchicalMobilityModel::ParentChanged (const TraceContext &context, Ptr<const MobilityModel> model)
 {
   MobilityModel::NotifyCourseChange ();
 }
 
 void 
-HierarchicalMobilityModel::ChildChanged (Ptr<const MobilityModel> model)
+HierarchicalMobilityModel::ChildChanged (const TraceContext &context, Ptr<const MobilityModel> model)
 {
   MobilityModel::NotifyCourseChange ();
 }
--- a/src/mobility/hierarchical-mobility-model.h	Sun Aug 12 18:28:13 2007 +0200
+++ b/src/mobility/hierarchical-mobility-model.h	Sun Aug 12 18:28:37 2007 +0200
@@ -63,8 +63,8 @@
   virtual void DoSet (const Position &position);
   virtual Speed DoGetSpeed (void) const;
 
-  void ParentChanged (Ptr<const MobilityModel> model);
-  void ChildChanged (Ptr<const MobilityModel> model);
+  void ParentChanged (const TraceContext &context, Ptr<const MobilityModel> model);
+  void ChildChanged (const TraceContext &context, Ptr<const MobilityModel> model);
 
   Ptr<MobilityModel> m_child;
   Ptr<MobilityModel> m_parent;
--- a/src/mobility/mobility-model-notifier.cc	Sun Aug 12 18:28:13 2007 +0200
+++ b/src/mobility/mobility-model-notifier.cc	Sun Aug 12 18:28:37 2007 +0200
@@ -19,6 +19,7 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "mobility-model-notifier.h"
+#include "ns3/composite-trace-resolver.h"
 
 namespace ns3 {
 
@@ -33,36 +34,18 @@
 }
 
 void 
-MobilityModelNotifier::RegisterListener (Listener listener)
-{
-  m_listeners.push_back (listener);
-}
-void 
-MobilityModelNotifier::UnregisterListener (Listener callback)
-{
-  for (std::list<Listener>::iterator i = m_listeners.begin ();
-       i != m_listeners.end ();)
-    {
-      Listener listener = *i;
-      if (listener.IsEqual (callback))
-	{
-	  i = m_listeners.erase (i);
-	}
-      else
-	{
-	  i++;
-	}
-    }  
-}
-void 
 MobilityModelNotifier::Notify (Ptr<const MobilityModel> position) const
 {
-  for (std::list<Listener>::const_iterator i = m_listeners.begin ();
-       i != m_listeners.end (); i++)
-    {
-      Listener listener = *i;
-      listener (position);
-    }
+  m_trace (position);
+}
+
+Ptr<TraceResolver> 
+MobilityModelNotifier::GetTraceResolver (void)
+{
+  Ptr<CompositeTraceResolver> resolver = 
+    Create<CompositeTraceResolver> ();
+  resolver->Add ("course-change", m_trace);
+  return resolver;
 }
 
 } // namespace ns3
--- a/src/mobility/mobility-model-notifier.h	Sun Aug 12 18:28:13 2007 +0200
+++ b/src/mobility/mobility-model-notifier.h	Sun Aug 12 18:28:37 2007 +0200
@@ -24,6 +24,7 @@
 #include "ns3/object.h"
 #include "ns3/component-manager.h"
 #include "ns3/callback.h"
+#include "ns3/callback-trace-source.h"
 #include "mobility-model.h"
 
 namespace ns3 {
@@ -37,8 +38,6 @@
   static const InterfaceId iid;
   static const ClassId cid;
 
-  typedef Callback<void,Ptr<const MobilityModel> > Listener;
-
   /**
    * Create a new position notifier
    */
@@ -48,23 +47,10 @@
    * \param position the position which just changed.
    */
   void Notify (Ptr<const MobilityModel> position) const;
-
-  /**
-   * \param listener listener to add
-   *
-   * The listener will be notified upon every position change.
-   */
-  void RegisterListener (Listener listener);
-  /**
-   * \param listener listener to remove
-   *
-   * The listener will not be notified anymore upon every 
-   * position change. It is not an error to try to unregister
-   * a non-registered liste
-   */
-  void UnregisterListener (Listener listener);
+protected:
+  virtual Ptr<TraceResolver> GetTraceResolver (void);
 private:
-  std::list<Listener> m_listeners;
+  CallbackTraceSource<Ptr<const MobilityModel> > m_trace;
 };
 
 } // namespace ns3