add hierarchical support to MobilityHelper
This commit is contained in:
@@ -28,32 +28,48 @@ TypeId
|
||||
HierarchicalMobilityModel::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("HierarchicalMobilityModel")
|
||||
.SetParent<MobilityModel> ();
|
||||
.SetParent<MobilityModel> ()
|
||||
.AddConstructor<HierarchicalMobilityModel> ()
|
||||
.AddParameter ("child", "The child mobility model.",
|
||||
MakePtrParamSpec (&HierarchicalMobilityModel::SetChild))
|
||||
.AddParameter ("parent", "The parent mobility model.",
|
||||
MakePtrParamSpec (&HierarchicalMobilityModel::SetParent))
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
HierarchicalMobilityModel::HierarchicalMobilityModel (Ptr<MobilityModel> child, Ptr<MobilityModel> parent)
|
||||
: m_child (child),
|
||||
m_parent (parent)
|
||||
HierarchicalMobilityModel::HierarchicalMobilityModel ()
|
||||
{}
|
||||
|
||||
void
|
||||
HierarchicalMobilityModel::SetChild (Ptr<MobilityModel> model)
|
||||
{
|
||||
Ptr<MobilityModelNotifier> childNotifier =
|
||||
m_child = model;
|
||||
Ptr<MobilityModelNotifier> notifier =
|
||||
m_child->QueryInterface<MobilityModelNotifier> ();
|
||||
Ptr<MobilityModelNotifier> parentNotifier =
|
||||
m_parent->QueryInterface<MobilityModelNotifier> ();
|
||||
if (childNotifier == 0)
|
||||
if (notifier == 0)
|
||||
{
|
||||
childNotifier = CreateObject<MobilityModelNotifier> ();
|
||||
child->AddInterface (childNotifier);
|
||||
notifier = CreateObject<MobilityModelNotifier> ();
|
||||
m_child->AddInterface (notifier);
|
||||
}
|
||||
if (parentNotifier == 0)
|
||||
{
|
||||
parentNotifier = CreateObject<MobilityModelNotifier> ();
|
||||
parent->AddInterface (parentNotifier);
|
||||
}
|
||||
childNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
|
||||
parentNotifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
|
||||
notifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ChildChanged, this));
|
||||
}
|
||||
|
||||
void
|
||||
HierarchicalMobilityModel::SetParent (Ptr<MobilityModel> model)
|
||||
{
|
||||
m_parent = model;
|
||||
Ptr<MobilityModelNotifier> notifier =
|
||||
m_parent->QueryInterface<MobilityModelNotifier> ();
|
||||
if (notifier == 0)
|
||||
{
|
||||
notifier = CreateObject<MobilityModelNotifier> ();
|
||||
m_parent->AddInterface (notifier);
|
||||
}
|
||||
notifier->TraceConnect ("/course-changed", MakeCallback (&HierarchicalMobilityModel::ParentChanged, this));
|
||||
}
|
||||
|
||||
|
||||
Ptr<MobilityModel>
|
||||
HierarchicalMobilityModel::GetChild (void) const
|
||||
{
|
||||
|
||||
@@ -35,11 +35,7 @@ class HierarchicalMobilityModel : public MobilityModel
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
/**
|
||||
* \param child the "relative" mobility model
|
||||
* \param parent the "reference" mobility model
|
||||
*/
|
||||
HierarchicalMobilityModel (Ptr<MobilityModel> child, Ptr<MobilityModel> parent);
|
||||
HierarchicalMobilityModel ();
|
||||
|
||||
/**
|
||||
* \returns the child mobility model.
|
||||
@@ -62,6 +58,8 @@ private:
|
||||
virtual void DoSetPosition (const Vector &position);
|
||||
virtual Vector DoGetVelocity (void) const;
|
||||
|
||||
void SetChild (Ptr<MobilityModel> model);
|
||||
void SetParent (Ptr<MobilityModel> model);
|
||||
void ParentChanged (const TraceContext &context, Ptr<const MobilityModel> model);
|
||||
void ChildChanged (const TraceContext &context, Ptr<const MobilityModel> model);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "mobility-model.h"
|
||||
#include "mobility-model-notifier.h"
|
||||
#include "position-allocator.h"
|
||||
#include "hierarchical-mobility-model.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -73,6 +74,19 @@ MobilityHelper::SetMobilityModel (std::string type,
|
||||
m_mobility.Set (n9, v9);
|
||||
}
|
||||
|
||||
void
|
||||
MobilityHelper::PushReferenceMobilityModel (Ptr<Object> reference)
|
||||
{
|
||||
Ptr<MobilityModel> mobility = reference->QueryInterface<MobilityModel> ();
|
||||
m_mobilityStack.push_back (mobility);
|
||||
}
|
||||
void
|
||||
MobilityHelper::PopReferenceMobilityModel (void)
|
||||
{
|
||||
m_mobilityStack.pop_back ();
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
MobilityHelper::GetMobilityModelType (void) const
|
||||
{
|
||||
@@ -94,7 +108,19 @@ MobilityHelper::Layout (const std::vector<Ptr<Object> > &objects)
|
||||
NS_FATAL_ERROR ("The requested mobility model is not a mobility model: \""<<
|
||||
m_mobility.GetTypeId ().GetName ()<<"\"");
|
||||
}
|
||||
object->AddInterface (model);
|
||||
if (m_mobilityStack.empty ())
|
||||
{
|
||||
object->AddInterface (model);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we need to setup a hierarchical mobility model
|
||||
Ptr<MobilityModel> parent = m_mobilityStack.back ();
|
||||
Ptr<MobilityModel> hierarchical =
|
||||
CreateObjectWith<HierarchicalMobilityModel> ("child", model,
|
||||
"parent", parent);
|
||||
object->AddInterface (hierarchical);
|
||||
}
|
||||
}
|
||||
Vector position = m_position->GetNext ();
|
||||
model->SetPosition (position);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace ns3 {
|
||||
|
||||
class PositionAllocator;
|
||||
class MobilityModel;
|
||||
|
||||
class MobilityHelper
|
||||
{
|
||||
@@ -42,6 +43,9 @@ public:
|
||||
std::string n8 = "", PValue v8 = PValue (),
|
||||
std::string n9 = "", PValue v9 = PValue ());
|
||||
|
||||
void PushReferenceMobilityModel (Ptr<Object> reference);
|
||||
void PopReferenceMobilityModel (void);
|
||||
|
||||
std::string GetMobilityModelType (void) const;
|
||||
|
||||
template <typename T>
|
||||
@@ -49,6 +53,7 @@ public:
|
||||
private:
|
||||
void Layout (const std::vector<Ptr<Object> > &objects);
|
||||
|
||||
std::vector<Ptr<MobilityModel> > m_mobilityStack;
|
||||
bool m_notifierEnabled;
|
||||
ObjectFactory m_mobility;
|
||||
Ptr<PositionAllocator> m_position;
|
||||
|
||||
Reference in New Issue
Block a user