# HG changeset patch # User Mathieu Lacage # Date 1183535782 -7200 # Node ID c06feb6d1f519b3840fd340a0472332aefddf61f # Parent 97fbb72ad7790b10ca6cef4a42e43329ba70c627 PositionSetNotifier -> MobilityModelNotifier diff -r 97fbb72ad779 -r c06feb6d1f51 SConstruct --- a/SConstruct Wed Jul 04 09:48:49 2007 +0200 +++ b/SConstruct Wed Jul 04 09:56:22 2007 +0200 @@ -249,7 +249,7 @@ 'ipv4.cc', 'application.cc', 'position.cc', - 'position-set-notifier.cc', + 'mobility-model-notifier.cc', 'static-position.cc', 'static-speed-position.cc', 'grid-topology.cc', @@ -274,7 +274,7 @@ 'ipv4.h', 'application.h', 'position.h', - 'position-set-notifier.h', + 'mobility-model-notifier.h', 'static-position.h', 'static-speed-position.h', 'grid-topology.h', diff -r 97fbb72ad779 -r c06feb6d1f51 samples/main-random-walk.cc --- a/samples/main-random-walk.cc Wed Jul 04 09:48:49 2007 +0200 +++ b/samples/main-random-walk.cc Wed Jul 04 09:56:22 2007 +0200 @@ -2,7 +2,7 @@ #include "ns3/ptr.h" #include "ns3/position.h" -#include "ns3/position-set-notifier.h" +#include "ns3/mobility-model-notifier.h" #include "ns3/random-walk-position.h" #include "ns3/default-value.h" #include "ns3/command-line.h" @@ -29,7 +29,7 @@ CommandLine::Parse (argc, argv); - Ptr notifier = Create (); + Ptr notifier = Create (); Ptr position = Create (); position->AddInterface (notifier); notifier->RegisterListener (MakeCallback (&CourseChange)); diff -r 97fbb72ad779 -r c06feb6d1f51 src/node/mobility-model-notifier.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/node/mobility-model-notifier.cc Wed Jul 04 09:56:22 2007 +0200 @@ -0,0 +1,68 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#include "mobility-model-notifier.h" + +namespace ns3 { + +const InterfaceId MobilityModelNotifier::iid = MakeInterfaceId ("MobilityModelNotifier", Object::iid); +const ClassId MobilityModelNotifier::cid = + MakeClassId ("MobilityModelNotifier", + MobilityModelNotifier::iid); + +MobilityModelNotifier::MobilityModelNotifier () +{ + SetInterfaceId (MobilityModelNotifier::iid); +} + +void +MobilityModelNotifier::RegisterListener (Listener listener) +{ + m_listeners.push_back (listener); +} +void +MobilityModelNotifier::UnregisterListener (Listener callback) +{ + for (std::list::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 position) const +{ + for (std::list::const_iterator i = m_listeners.begin (); + i != m_listeners.end (); i++) + { + Listener listener = *i; + listener (position); + } +} + +} // namespace ns3 diff -r 97fbb72ad779 -r c06feb6d1f51 src/node/mobility-model-notifier.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/node/mobility-model-notifier.h Wed Jul 04 09:56:22 2007 +0200 @@ -0,0 +1,72 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Mathieu Lacage + */ +#ifndef MOBILITY_MODEL_NOTIFIER_H +#define MOBILITY_MODEL_NOTIFIER_H + +#include "ns3/object.h" +#include "ns3/component-manager.h" +#include "ns3/callback.h" +#include "position.h" + +namespace ns3 { + +/** + * \brief notify listeners of position changes. + */ +class MobilityModelNotifier : public Object +{ +public: + static const InterfaceId iid; + static const ClassId cid; + + typedef Callback > Listener; + + /** + * Create a new position notifier + */ + MobilityModelNotifier (); + + /** + * \param position the position which just changed. + */ + void Notify (Ptr 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); +private: + std::list m_listeners; +}; + +} // namespace ns3 + +#endif /* MOBILITY_MODEL_NOTIFIER_H */ diff -r 97fbb72ad779 -r c06feb6d1f51 src/node/position-set-notifier.cc --- a/src/node/position-set-notifier.cc Wed Jul 04 09:48:49 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#include "position-set-notifier.h" - -namespace ns3 { - -const InterfaceId PositionSetNotifier::iid = MakeInterfaceId ("PositionSetNotifier", Object::iid); -const ClassId PositionSetNotifier::cid = - MakeClassId ("PositionSetNotifier", - PositionSetNotifier::iid); - -PositionSetNotifier::PositionSetNotifier () -{ - SetInterfaceId (PositionSetNotifier::iid); -} - -void -PositionSetNotifier::RegisterListener (Listener listener) -{ - m_listeners.push_back (listener); -} -void -PositionSetNotifier::UnregisterListener (Listener callback) -{ - for (std::list::iterator i = m_listeners.begin (); - i != m_listeners.end ();) - { - Listener listener = *i; - if (listener.IsEqual (callback)) - { - i = m_listeners.erase (i); - } - else - { - i++; - } - } -} -void -PositionSetNotifier::Notify (Ptr position) const -{ - for (std::list::const_iterator i = m_listeners.begin (); - i != m_listeners.end (); i++) - { - Listener listener = *i; - listener (position); - } -} - -} // namespace ns3 diff -r 97fbb72ad779 -r c06feb6d1f51 src/node/position-set-notifier.h --- a/src/node/position-set-notifier.h Wed Jul 04 09:48:49 2007 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ -#ifndef POSITION_SET_NOTIFIER_H -#define POSITION_SET_NOTIFIER_H - -#include "ns3/object.h" -#include "ns3/component-manager.h" -#include "ns3/callback.h" -#include "position.h" - -namespace ns3 { - -/** - * \brief notify listeners of position changes. - */ -class PositionSetNotifier : public Object -{ -public: - static const InterfaceId iid; - static const ClassId cid; - - typedef Callback > Listener; - - /** - * Create a new position notifier - */ - PositionSetNotifier (); - - /** - * \param position the position which just changed. - */ - void Notify (Ptr 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); -private: - std::list m_listeners; -}; - -} // namespace ns3 - -#endif /* POSITION_SET_NOTIFIER_H */ diff -r 97fbb72ad779 -r c06feb6d1f51 src/node/position.cc --- a/src/node/position.cc Wed Jul 04 09:48:49 2007 +0200 +++ b/src/node/position.cc Wed Jul 04 09:56:22 2007 +0200 @@ -19,7 +19,7 @@ * Author: Mathieu Lacage */ #include "position.h" -#include "position-set-notifier.h" +#include "mobility-model-notifier.h" #include namespace ns3 { @@ -112,8 +112,8 @@ void Position::NotifyCourseChange (void) const { - Ptr notifier = - QueryInterface (PositionSetNotifier::iid); + Ptr notifier = + QueryInterface (MobilityModelNotifier::iid); if (notifier != 0) { notifier->Notify (this);