A Discrete-Event Network Simulator
API
hierarchical-mobility-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
21 #include "ns3/pointer.h"
22 #include "ns3/log.h"
23 #include "ns3/simulator.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("HierarchicalMobilityModel");
28 
29 NS_OBJECT_ENSURE_REGISTERED (HierarchicalMobilityModel);
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::HierarchicalMobilityModel")
36  .SetGroupName ("Mobility")
37  .AddConstructor<HierarchicalMobilityModel> ()
38  .AddAttribute ("Child", "The child mobility model.",
39  PointerValue (),
42  MakePointerChecker<MobilityModel> ())
43  .AddAttribute ("Parent", "The parent mobility model.",
44  PointerValue (),
47  MakePointerChecker<MobilityModel> ())
48  ;
49  return tid;
50 }
51 
53  : m_child (0),
54  m_parent (0)
55 {
56  NS_LOG_FUNCTION (this);
57 }
58 
59 void
61 {
62  NS_LOG_FUNCTION (this << model);
63  Ptr<MobilityModel> oldChild = m_child;
64  Vector pos;
65  if (m_child)
66  {
67  NS_LOG_DEBUG ("Disconnecting previous child model " << m_child);
68  pos = GetPosition ();
70  }
71  m_child = model;
73 
74  // if we had a child before, then we had a valid position before;
75  // try to preserve the old absolute position.
76  if (oldChild)
77  {
78  NS_LOG_DEBUG ("Restoring previous position " << pos);
79  SetPosition (pos);
80  }
81 }
82 
83 void
85 {
86  NS_LOG_FUNCTION (this << model);
87  Vector pos;
88  if (m_child)
89  {
90  pos = GetPosition ();
91  }
92  if (m_parent)
93  {
94  NS_LOG_DEBUG ("Disconnecting previous parent model " << m_child);
96  }
97  m_parent = model;
98  if (m_parent)
99  {
101  }
102  // try to preserve the old position across parent changes
103  if (m_child)
104  {
105  NS_LOG_DEBUG ("Restoring previous position " << pos);
106  SetPosition (pos);
107  }
108 }
109 
110 
113 {
114  return m_child;
115 }
116 
119 {
120  return m_parent;
121 }
122 
123 Vector
125 {
126  if (!m_parent)
127  {
128  return m_child->GetPosition ();
129  }
130  Vector parentPosition = m_parent->GetPosition ();
131  Vector childPosition = m_child->GetPositionWithReference (parentPosition);
132  return Vector (parentPosition.x + childPosition.x,
133  parentPosition.y + childPosition.y,
134  parentPosition.z + childPosition.z);
135 }
136 void
138 {
139  NS_LOG_FUNCTION (this << position);
140  if (m_child == 0)
141  {
142  return;
143  }
144  // This implementation of DoSetPosition is really an arbitrary choice.
145  // anything else would have been ok.
146  if (m_parent)
147  {
148  Vector parentPosition = m_parent->GetPosition ();
149  Vector childPosition (position.x - parentPosition.x,
150  position.y - parentPosition.y,
151  position.z - parentPosition.z);
152  m_child->SetPosition (childPosition);
153  }
154  else
155  {
156  m_child->SetPosition (position);
157  }
158 }
159 Vector
161 {
162  if (m_parent)
163  {
164  Vector parentSpeed = m_parent->GetVelocity ();
165  Vector childSpeed = m_child->GetVelocity ();
166  Vector speed (parentSpeed.x + childSpeed.x,
167  parentSpeed.y + childSpeed.y,
168  parentSpeed.z + childSpeed.z);
169  return speed;
170  }
171  else
172  {
173  return m_child->GetVelocity ();
174  }
175 }
176 
177 void
179 {
181 }
182 
183 void
185 {
187 }
188 
189 void
191 {
192  NS_LOG_FUNCTION (this);
193  if (m_parent && !m_parent->IsInitialized ())
194  {
195  m_parent->Initialize ();
196  }
197  m_child->Initialize ();
198 }
199 
200 int64_t
202 {
203  NS_LOG_FUNCTION (this << stream);
204  int64_t streamsAllocated = 0;
205  streamsAllocated += m_parent->AssignStreams (stream);
206  streamsAllocated += m_child->AssignStreams (stream + streamsAllocated);
207  return streamsAllocated;
208 }
209 
210 } // namespace ns3
ns3::HierarchicalMobilityModel::DoGetPosition
virtual Vector DoGetPosition(void) const
Definition: hierarchical-mobility-model.cc:124
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::HierarchicalMobilityModel
Hierarchical mobility model.
Definition: hierarchical-mobility-model.h:58
ns3::HierarchicalMobilityModel::SetParent
void SetParent(Ptr< MobilityModel > model)
Sets the parent mobility model to a new one, possibly replacing an existing one.
Definition: hierarchical-mobility-model.cc:84
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ObjectBase::TraceDisconnectWithoutContext
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:319
ns3::MobilityModel::NotifyCourseChange
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
Definition: mobility-model.cc:108
ns3::MobilityModel::SetPosition
void SetPosition(const Vector &position)
Definition: mobility-model.cc:88
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition: pointer.h:37
ns3::HierarchicalMobilityModel::HierarchicalMobilityModel
HierarchicalMobilityModel()
Definition: hierarchical-mobility-model.cc:52
ns3::HierarchicalMobilityModel::GetChild
Ptr< MobilityModel > GetChild(void) const
Definition: hierarchical-mobility-model.cc:112
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::HierarchicalMobilityModel::SetChild
void SetChild(Ptr< MobilityModel > model)
Sets the child mobility model to a new one, possibly replacing an existing one.
Definition: hierarchical-mobility-model.cc:60
ns3::HierarchicalMobilityModel::GetParent
Ptr< MobilityModel > GetParent(void) const
Definition: hierarchical-mobility-model.cc:118
ns3::HierarchicalMobilityModel::m_child
Ptr< MobilityModel > m_child
pointer to child mobility model
Definition: hierarchical-mobility-model.h:120
ns3::Ptr< MobilityModel >
ns3::HierarchicalMobilityModel::ParentChanged
void ParentChanged(Ptr< const MobilityModel > model)
Callback for when parent mobility model course change occurs.
Definition: hierarchical-mobility-model.cc:178
ns3::MobilityModel::GetVelocity
Vector GetVelocity(void) const
Definition: mobility-model.cc:82
ns3::MobilityModel::AssignStreams
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: mobility-model.cc:114
ns3::HierarchicalMobilityModel::DoAssignStreams
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
Definition: hierarchical-mobility-model.cc:201
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
ns3::MakePointerAccessor
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:227
ns3::HierarchicalMobilityModel::DoGetVelocity
virtual Vector DoGetVelocity(void) const
Definition: hierarchical-mobility-model.cc:160
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::HierarchicalMobilityModel::ChildChanged
void ChildChanged(Ptr< const MobilityModel > model)
Callback for when child mobility model course change occurs.
Definition: hierarchical-mobility-model.cc:184
hierarchical-mobility-model.h
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition: mobility-model.h:40
ns3::HierarchicalMobilityModel::DoSetPosition
virtual void DoSetPosition(const Vector &position)
Definition: hierarchical-mobility-model.cc:137
ns3::HierarchicalMobilityModel::DoInitialize
virtual void DoInitialize(void)
Initialize() implementation.
Definition: hierarchical-mobility-model.cc:190
ns3::MobilityModel::GetPositionWithReference
Vector GetPositionWithReference(const Vector &referencePosition) const
This method may be used if the position returned may depend on some reference position provided.
Definition: mobility-model.cc:69
ns3::HierarchicalMobilityModel::GetTypeId
static TypeId GetTypeId(void)
Register this type with the TypeId system.
Definition: hierarchical-mobility-model.cc:32
ns3::ObjectBase::TraceConnectWithoutContext
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:293
ns3::Object::Initialize
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
ns3::MobilityModel::GetPosition
Vector GetPosition(void) const
Definition: mobility-model.cc:64
ns3::HierarchicalMobilityModel::m_parent
Ptr< MobilityModel > m_parent
pointer to parent mobility model
Definition: hierarchical-mobility-model.h:121
ns3::Object::IsInitialized
bool IsInitialized(void) const
Check if the object has been initialized.
Definition: object.cc:208