replace the adhoc mobility course change callbacks with a trace source
This commit is contained in:
@@ -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 @@ int main (int argc, char *argv[])
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ HierarchicalMobilityModel::HierarchicalMobilityModel (Ptr<MobilityModel> child,
|
||||
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 @@ HierarchicalMobilityModel::DoGetSpeed (void) const
|
||||
}
|
||||
|
||||
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 ();
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ private:
|
||||
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;
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -32,37 +33,19 @@ MobilityModelNotifier::MobilityModelNotifier ()
|
||||
SetInterfaceId (MobilityModelNotifier::iid);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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 @@ public:
|
||||
static const InterfaceId iid;
|
||||
static const ClassId cid;
|
||||
|
||||
typedef Callback<void,Ptr<const MobilityModel> > Listener;
|
||||
|
||||
/**
|
||||
* Create a new position notifier
|
||||
*/
|
||||
@@ -48,23 +47,10 @@ public:
|
||||
* \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
|
||||
|
||||
Reference in New Issue
Block a user