diff --git a/examples/simple-error-model.cc b/examples/simple-error-model.cc index aa5d543a3..7f767644d 100644 --- a/examples/simple-error-model.cc +++ b/examples/simple-error-model.cc @@ -52,7 +52,6 @@ #include "ns3/pcap-trace.h" #include "ns3/internet-node.h" #include "ns3/default-value.h" -#include "ns3/component-manager.h" #include "ns3/random-variable.h" #include "ns3/point-to-point-channel.h" #include "ns3/point-to-point-net-device.h" diff --git a/samples/main-grid-topology.cc b/samples/main-grid-topology.cc index 14bd2ebcb..156d7d627 100644 --- a/samples/main-grid-topology.cc +++ b/samples/main-grid-topology.cc @@ -27,7 +27,7 @@ int main (int argc, char *argv[]) GridTopology grid (-100, -100, 20, 5, 20); // each object will be attached a static position. - grid.SetMobilityModel (StaticMobilityModel::cid); + grid.SetMobilityModel (StaticMobilityModel::iid ()); // finalize the setup by attaching to each object // in the input array a position and initializing diff --git a/src/common/error-model.cc b/src/common/error-model.cc index 16f3768b7..9d727d5f2 100644 --- a/src/common/error-model.cc +++ b/src/common/error-model.cc @@ -28,14 +28,18 @@ #include "ns3/log.h" #include "ns3/random-variable.h" #include "ns3/default-value.h" +#include "ns3/interface-id-default-value.h" NS_LOG_COMPONENT_DEFINE ("ErrorModel"); namespace ns3 { -static ClassIdDefaultValue g_classIdErrorModelDefaultValue ("ErrorModel", - "Error Model", ErrorModel::iid (), - "RateErrorModel"); +static InterfaceIdDefaultValue g_interfaceIdErrorModelDefaultValue ("ErrorModel", + "Error Model", + ErrorModel::iid (), + "RateErrorModel"); + +NS_OBJECT_ENSURE_REGISTERED (ErrorModel); InterfaceId ErrorModel::iid (void) { @@ -59,8 +63,8 @@ Ptr ErrorModel::CreateDefault (void) { NS_LOG_FUNCTION; - ClassId classId = g_classIdErrorModelDefaultValue.GetValue (); - Ptr em = ComponentManager::Create (classId); + InterfaceId interfaceId = g_interfaceIdErrorModelDefaultValue.GetValue (); + Ptr em = interfaceId.CreateObject ()->QueryInterface (); return em; } @@ -107,11 +111,6 @@ ErrorModel::IsEnabled (void) const // RateErrorModel // - -const ClassId RateErrorModel::cid = - MakeClassId ("RateErrorModel", ErrorModel::iid (), - RateErrorModel::iid ()); - // Defaults for rate/size static NumericDefaultValue g_defaultRateErrorModelErrorRate ("RateErrorModelErrorRate", "The error rate for the error model", 0.0); @@ -124,10 +123,13 @@ static EnumDefaultValue EU_BIT, "EU_BIT", 0, (void*)0); +NS_OBJECT_ENSURE_REGISTERED (RateErrorModel); + InterfaceId RateErrorModel::iid (void) { static InterfaceId iid = InterfaceId ("RateErrorModel") - .SetParent (); + .SetParent () + .AddConstructor (); return iid; } @@ -242,14 +244,13 @@ RateErrorModel::DoReset (void) // ListErrorModel // -const ClassId ListErrorModel::cid = - MakeClassId ("ListErrorModel", ErrorModel::iid (), - ListErrorModel::iid ()); +NS_OBJECT_ENSURE_REGISTERED (ListErrorModel); InterfaceId ListErrorModel::iid (void) { static InterfaceId iid = InterfaceId ("ListErrorModel") - .SetParent (); + .SetParent () + .AddConstructor (); return iid; } diff --git a/src/common/error-model.h b/src/common/error-model.h index 3d5df5e50..2d1b24ea0 100644 --- a/src/common/error-model.h +++ b/src/common/error-model.h @@ -23,7 +23,6 @@ #include #include "ns3/object.h" -#include "ns3/component-manager.h" namespace ns3 { @@ -138,7 +137,6 @@ class RateErrorModel : public ErrorModel { public: static InterfaceId iid (void); - static const ClassId cid; RateErrorModel (); virtual ~RateErrorModel (); @@ -205,7 +203,6 @@ class ListErrorModel : public ErrorModel { public: static InterfaceId iid (void); - static const ClassId cid; ListErrorModel (); virtual ~ListErrorModel (); diff --git a/src/core/component-manager.cc b/src/core/component-manager.cc deleted file mode 100644 index b939a0919..000000000 --- a/src/core/component-manager.cc +++ /dev/null @@ -1,414 +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 "component-manager.h" -#include "uid-manager.h" -#include "singleton.h" - -namespace ns3 { - -// we redefine a UidManager type for the class id singleton below. -// otherwise, we would have to share the same id singleton instance -// with the Iids. -class CidManager : public UidManager -{}; - -ClassId::ClassId (std::string name) - : m_classId (Singleton::Get ()->Allocate (name)) -{} - -ClassId::ClassId (uint32_t classId) - : m_classId (classId) -{} - -std::string -ClassId::GetName (void) const -{ - return Singleton::Get ()->LookupByUid (m_classId); -} - -bool operator == (const ClassId &a, const ClassId &b) -{ - return a.m_classId == b.m_classId; -} - -ComponentManager::ClassIdEntry::ClassIdEntry (ClassId classId) - : m_classId (classId) -{} - -Ptr -ComponentManager::Create (ClassId classId) -{ - Callback > callback = DoGetCallback (classId); - return callback (); -} - -CallbackBase * -ComponentManager::Lookup (ClassId classId) -{ - List *list = Singleton::Get (); - for (List::const_iterator i = list->begin (); i != list->end (); i++) - { - if (i->m_classId == classId) - { - return i->m_callback; - } - } - return 0; -} - -ClassId -ComponentManager::LookupByName (std::string name) -{ - return ClassId (Singleton::Get ()->LookupByName (name)); -} -ClassId -ComponentManager::LookupByName (std::string name, bool *ok) -{ - uint32_t cid = Singleton::Get ()->LookupByName (name); - if (cid == 0) - { - *ok = false; - } - else - { - *ok = true; - } - return ClassId (cid); -} -std::vector -ComponentManager::LookupByInterfaceId (InterfaceId iid) -{ - std::vector classIdList; - List *list = Singleton::Get (); - for (List::const_iterator i = list->begin (); i != list->end (); i++) - { - for (std::vector::const_iterator j = i->m_supportedInterfaces.begin (); - j != i->m_supportedInterfaces.end (); j++) - { - if (*j == iid) - { - classIdList.push_back (i->m_classId); - break; - } - } - } - unique (classIdList.begin (), classIdList.end ()); - return classIdList; -} - -void -ComponentManager::Register (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces) -{ - List *list = Singleton::Get (); - struct ClassIdEntry entry = ClassIdEntry (classId); - entry.m_callback = callback; - bool foundObject = false; - for (std::vector::iterator i = supportedInterfaces.begin (); - i != supportedInterfaces.end (); i++) - { - if (*i == Object::iid ()) - { - foundObject = true; - } - } - if (!foundObject) - { - supportedInterfaces.push_back (Object::iid ()); - } - entry.m_supportedInterfaces = supportedInterfaces; - list->push_back (entry); -} - -void -RegisterCallback (ClassId classId, CallbackBase *callback, std::vector supportedInterfaces) -{ - return ComponentManager::Register (classId, callback, supportedInterfaces); -} - - -ClassIdDefaultValue::ClassIdDefaultValue (std::string name, - std::string help, - InterfaceId iid, - std::string defaultValue) - : DefaultValueBase (name, help), - m_defaultName (defaultValue), - m_name (defaultValue), - m_interfaceId (iid) -{ - DefaultValueList::Add (this); -} -ClassId -ClassIdDefaultValue::GetValue (void) const -{ - return ComponentManager::LookupByName (m_name); -} -void -ClassIdDefaultValue::SetValue (ClassId classId) -{ - m_name = classId.GetName (); -} -void -ClassIdDefaultValue::SetValue (std::string name) -{ - m_name = name; -} -bool -ClassIdDefaultValue::DoParseValue (const std::string &value) -{ - bool ok; - ClassId classId = ComponentManager::LookupByName (value, &ok); - if (!ok) - { - return false; - } - std::vector classIdList = ComponentManager::LookupByInterfaceId (m_interfaceId); - for (std::vector::const_iterator i = classIdList.begin (); - i != classIdList.end (); i++) - { - if (*i == classId) - { - m_name = value; - return true; - } - } - return false; -} - -std::string -ClassIdDefaultValue::DoGetType (void) const -{ - std::vector classIdList = ComponentManager::LookupByInterfaceId (m_interfaceId); - std::ostringstream oss; - oss << "("; - for (std::vector::const_iterator i = classIdList.begin (); - i != classIdList.end (); i++) - { - if (i != classIdList.begin ()) - { - oss << "|"; - } - oss << i->GetName (); - } - oss << ")"; - return oss.str (); -} - -std::string -ClassIdDefaultValue::DoGetDefaultValue (void) const -{ - return m_name; -} - - - - -} // namespace ns3 - -#ifdef RUN_SELF_TESTS - -#include "test.h" -#include "object.h" - -namespace { - - -class B : public ns3::Object -{ -public: - static ns3::InterfaceId iid (void) { - static ns3::InterfaceId iid = ns3::InterfaceId ("B") - .SetParent (); - return iid; - } - - B (); -}; - -B::B () -{} - - -class A : public ns3::Object -{ -public: - static const ns3::ClassId cidZero; - static const ns3::ClassId cidOneBool; - static const ns3::ClassId cidOneUi32; - static const ns3::ClassId cidOther; - static ns3::InterfaceId iid (void) { - static ns3::InterfaceId iid = ns3::InterfaceId ("A") - .SetParent (); - return iid; - } - - - A (); - A (bool); - A (uint32_t); - - bool m_zeroInvoked; - bool m_oneBoolInvoked; - bool m_oneUi32Invoked; - - bool m_bool; - int m_ui32; -}; - -const ns3::ClassId A::cidZero = ns3::MakeClassId ("A", A::iid ()); -const ns3::ClassId A::cidOneBool = ns3::MakeClassId ("ABool", A::iid ()); -const ns3::ClassId A::cidOneUi32 = ns3::MakeClassId ("AUi32", A::iid ()); - -A::A () - : m_zeroInvoked (true), - m_oneBoolInvoked (false), - m_oneUi32Invoked (false) -{ - ns3::Ptr b = ns3::CreateObject (); - AddInterface (b); -} - -A::A (bool bo) - : m_zeroInvoked (false), - m_oneBoolInvoked (true), - m_oneUi32Invoked (false), - m_bool (bo) -{ - ns3::Ptr b = ns3::CreateObject (); - AddInterface (b); -} - -A::A (uint32_t i) - : m_zeroInvoked (false), - m_oneBoolInvoked (false), - m_oneUi32Invoked (true), - m_ui32 (i) -{ - ns3::Ptr b = ns3::CreateObject (); - AddInterface (b); -} - -class X : public A -{ -public: - static ns3::InterfaceId iid (void) { - static ns3::InterfaceId iid = ns3::InterfaceId ("X") - .SetParent (); - return iid; - } - -}; -class C : public X -{ -public: - static ns3::InterfaceId iid (void) { - static ns3::InterfaceId iid = ns3::InterfaceId ("C") - .SetParent (); - return iid; - } -}; -class D : public C -{ -public: - static ns3::InterfaceId iid (void) { - static ns3::InterfaceId iid = ns3::InterfaceId ("D") - .SetParent (); - return iid; - } - static const ns3::ClassId cid; -}; - -const ns3::ClassId D::cid = ns3::MakeClassId ("D", A::iid (), X::iid (), C::iid (), D::iid ()); - -} - -namespace ns3 { - -class ComponentManagerTest : public Test -{ -public: - ComponentManagerTest (); - virtual bool RunTests (void); -}; - -ComponentManagerTest::ComponentManagerTest () - : Test ("ComponentManager") -{} -bool -ComponentManagerTest::RunTests (void) -{ - bool ok = true; - - Ptr a = 0; - a = ComponentManager::Create (A::cidZero); - if (a == 0 || - !a->m_zeroInvoked) - { - ok = false; - } - - a = ComponentManager::Create (A::cidOneBool, true); - if (a == 0 || - !a->m_oneBoolInvoked || - !a->m_bool) - { - ok = false; - } - - a = ComponentManager::Create (A::cidOneBool, false); - if (a == 0 || - !a->m_oneBoolInvoked || - a->m_bool) - { - ok = false; - } - - a = ComponentManager::Create (A::cidOneUi32, 10); - if (a == 0 || - !a->m_oneUi32Invoked || - a->m_ui32 != 10) - { - ok = false; - } - - a = ComponentManager::Create (A::cidOneUi32, (uint32_t)10); - if (a == 0 || - !a->m_oneUi32Invoked || - a->m_ui32 != 10) - { - ok = false; - } - - Ptr b = ComponentManager::Create (A::cidOneUi32, 10); - if (b == 0) - { - ok = false; - } - - return ok; -} - - -static ComponentManagerTest g_unknownManagerTest; - -} // namespace ns3 - -#endif /* RUN_SELF_TESTS */ diff --git a/src/core/component-manager.h b/src/core/component-manager.h deleted file mode 100644 index dee19717d..000000000 --- a/src/core/component-manager.h +++ /dev/null @@ -1,679 +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 COMPONENT_MANAGER_H -#define COMPONENT_MANAGER_H - -#include -#include -#include -#include "callback.h" -#include "object.h" -#include "fatal-error.h" -#include "ptr.h" -#include "empty.h" -#include "default-value.h" - -namespace { - // anonymous namespace for implementation code. -template -struct ObjectMaker; -} - -namespace ns3 { - -/** - * \brief Unique Identifier for class constructors. - * - * Instances of this type must be allocated through - * the ns3::MakeClassId class. - */ -class ClassId -{ -public: - /** - * \returns the symbolic name associated to this class id - * - * This name is the name which was associated to this class id - * by the ns3::Ns3UnknownManager::RegisterConstructor methods. - * This name is also the name which is expected to be input - * to ns3::UnknownManager::LookupByName. - */ - std::string GetName (void) const; -protected: - ClassId (std::string name); -private: - ClassId (uint32_t classId); - friend class ComponentManager; - friend bool operator == (const ClassId &a, const ClassId &b); - uint32_t m_classId; -}; - -/** - * \brief a class used to create ClassIds - * - * - */ -template -class MakeClassId : public ClassId -{ -public: - /** - * \param name name of ClassId - * - * Create a ClassId with specified name. - */ - MakeClassId (std::string name); - /** - * \param name name of ClassId - * \param iid interface id - * - * Create a ClassId with specified name. Register iid - * as a supported interface. - */ - MakeClassId (std::string name, - InterfaceId iid); - /** - * \param name name of ClassId - * \param iid0 interface id - * \param iid1 interface id - * - * Create a ClassId with specified name. Register iid0 and iid1 - * as supported interfaces. - */ - MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1); - /** - * \param name name of ClassId - * \param iid0 interface id - * \param iid1 interface id - * \param iid2 interface id - * - * Create a ClassId with specified name. Register iid0, iid1 - * and iid2 as supported interfaces. - */ - MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2); - /** - * \param name name of ClassId - * \param iid0 interface id - * \param iid1 interface id - * \param iid2 interface id - * \param iid3 interface id - * - * Create a ClassId with specified name. Register iid0, iid1 - * iid2, and iid3 as supported interfaces. - */ - MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2, - InterfaceId iid3); - /** - * \param name name of ClassId - * \param iid0 interface id - * \param iid1 interface id - * \param iid2 interface id - * \param iid3 interface id - * \param iid4 interface id - * - * Create a ClassId with specified name. Register iid0, iid1 - * iid2, iid3, and iid4 as supported interfaces. - */ - MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2, - InterfaceId iid3, - InterfaceId iid4); -private: - typedef ObjectMaker MakerType; - static Callback,T1,T2,T3,T4,T5> m_callback; - void Register (InterfaceId array [], uint32_t n); -}; - - -/** - * \brief Create any Interface - * - * This class keeps track of a set of ClassId, each - * of which uniquely identifies the constructor of an - * object which derives from the Interface base class. - * This class can also create an instance of any of - * the objects tracked through any of their tracked - * constructor/ClassId. - */ -class ComponentManager -{ -public: - /** - * \param name the symbolic name to lookup - * \returns the ClassId associated to the input name. - */ - static ClassId LookupByName (std::string name); - static ClassId LookupByName (std::string name, bool *ok); - /** - * \param iid interface id to lookup - * \returns the list of ClassId which can be used to - * create objects which support the requested - * interface. - * - * Note that this method will not necessarily return the - * complete list of objects which support a given interface - * since dynamic aggregation of objects is not under - * the control of this class. - */ - static std::vector LookupByInterfaceId (InterfaceId iid); - - /** - * \param classId class id of the constructor to invoke. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. This method invokes the default constructor. - */ - static Ptr Create (ClassId classId); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 argument to pass to the constructor. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. - */ - template - static Ptr Create (ClassId classId, T1 a1); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to the constructor. - * \param a2 second argument to pass to the constructor. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2); - - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to the constructor. - * \param a2 second argument to pass to the constructor. - * \param a3 third argument to pass to the constructor. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to the constructor. - * \param a2 second argument to pass to the constructor. - * \param a3 third argument to pass to the constructor. - * \param a4 fourth argument to pass to the constructor. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to the constructor. - * \param a2 second argument to pass to the constructor. - * \param a3 third argument to pass to the constructor. - * \param a4 fourth argument to pass to the constructor. - * \param a5 fifth argument to pass to the constructor. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); - - /** - * \param classId class id of the constructor to invoke. - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to constructor - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId, T1 a1); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to constructor - * \param a2 second argument to pass to constructor - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to constructor - * \param a2 second argument to pass to constructor - * \param a3 third argument to pass to constructor - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to constructor - * \param a2 second argument to pass to constructor - * \param a3 third argument to pass to constructor - * \param a4 fourth argument to pass to constructor - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4); - - /** - * \param classId class id of the constructor to invoke. - * \param a1 first argument to pass to constructor - * \param a2 second argument to pass to constructor - * \param a3 third argument to pass to constructor - * \param a4 fourth argument to pass to constructor - * \param a5 fifth argument to pass to constructor - * \return a pointer to the instance created. - * - * Create an instance of the object identified by its - * ClassId, call QueryInterface on it, and return the - * result. - */ - template - static Ptr Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5); - -private: - friend void RegisterCallback (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces); - static void Register (ClassId classId, CallbackBase *callback, - std::vector supportedInterfaces); - - template - static Callback,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId); - - struct ClassIdEntry { - ClassIdEntry (ClassId classId); - ClassId m_classId; - CallbackBase *m_callback; - std::vector m_supportedInterfaces; - }; - - typedef std::vector List; - static List *GetList (void); - static CallbackBase *Lookup (ClassId classId); -}; - -/** - * \brief a DefaultValue class to handle ClassIds - * - * This class provides the necessary glue to allow - * the Bind function and the command-line arguments - * to control the type of an object to create. - */ -class ClassIdDefaultValue : public DefaultValueBase -{ -public: - /** - * \param name the name of this default value. - * \param help the help text associated to this default value - * \param iid the interface id which all objects created - * through this "default value" must support. - * \param defaultValue the name of the object to create - * by default. - */ - ClassIdDefaultValue (std::string name, - std::string help, - InterfaceId iid, - std::string defaultValue); - /** - * \returns the ClassId of the object selected by the user. - */ - ClassId GetValue (void) const; - /** - * \param classId the new ClassId selected. - * - * Override the currently-selected value. - */ - void SetValue (ClassId classId); - /** - * \param name the new object selected. - * - * Override the currently-selected value. - */ - void SetValue (std::string name); -private: - virtual bool DoParseValue (const std::string &value); - virtual std::string DoGetType (void) const; - virtual std::string DoGetDefaultValue (void) const; - std::string m_defaultName; - std::string m_name; - InterfaceId m_interfaceId; -}; - -} // namespace ns3 - - -namespace { - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (void) { - return ns3::CreateObject (); - } -}; - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (T1 a1) { - return ns3::CreateObject (a1); - } -}; - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (T1 a1, T2 a2) { - return ns3::CreateObject (a1, a2); - } -}; - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (T1 a1, T2 a2, T3 a3) { - return ns3::CreateObject (a1, a2, a3); - } -}; - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (T1 a1, T2 a2, T3 a3, T4 a4) { - return ns3::CreateObject (a1, a2, a3, a4); - } -}; - -template -struct ObjectMaker { - static ns3::Ptr - MakeObject (T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) { - return ns3::CreateObject (a1, a2, a3, a4, a5); - } -}; - -} // anonymous namespace - -namespace ns3 { - -void RegisterCallback (ClassId classId, ns3::CallbackBase *callback, - std::vector supportedInterfaces); - - - -template -void -MakeClassId::Register (InterfaceId array [], uint32_t n) -{ - std::vector supportedInterfaces; - for (uint32_t i = 0; i < n; i++) - { - supportedInterfaces.push_back (array[i]); - } - RegisterCallback (*this, &m_callback, supportedInterfaces); -} - -template -MakeClassId::MakeClassId (std::string name) - : ClassId (name) -{ - InterfaceId array[] = {}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} -template -MakeClassId::MakeClassId (std::string name, - InterfaceId iid) - : ClassId (name) -{ - InterfaceId array[] = {iid}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} -template -MakeClassId::MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1) - : ClassId (name) -{ - InterfaceId array[] = {iid0, iid1}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} -template -MakeClassId::MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2) - : ClassId (name) -{ - InterfaceId array[] = {iid0, iid1, iid2}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} -template -MakeClassId::MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2, - InterfaceId iid3) - : ClassId (name) -{ - InterfaceId array[] = {iid0, iid1, iid2, iid3}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} -template -MakeClassId::MakeClassId (std::string name, - InterfaceId iid0, - InterfaceId iid1, - InterfaceId iid2, - InterfaceId iid3, - InterfaceId iid4) - : ClassId (name) -{ - InterfaceId array[] = {iid0, iid1, iid2, iid3, iid4}; - Register (array, sizeof (array)/sizeof(InterfaceId)); -} - -template -Callback,T1,T2,T3,T4,T5> MakeClassId::m_callback = - MakeCallback (&MakeClassId::MakerType::MakeObject); - - - -template -Callback,T1,T2,T3,T4,T5> -ComponentManager::DoGetCallback (ClassId classId) -{ - CallbackBase *callback = Lookup (classId); - if (callback == 0) - { - NS_FATAL_ERROR ("Invalid Class Id."); - } - Callback,T1,T2,T3,T4,T5> reference; - reference.Assign (*callback); - return reference; -} - - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1) -{ - Callback,T1> callback = DoGetCallback (classId); - return callback (a1); -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2) -{ - Callback,T1,T2> callback = DoGetCallback (classId); - return callback (a1, a2); -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3) -{ - Callback,T1,T2,T3> callback = DoGetCallback (classId); - return callback (a1, a2, a3); -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4) -{ - Callback,T1,T2,T3,T4> callback = DoGetCallback (classId); - return callback (a1, a2, a3, a4); -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) -{ - Callback,T1,T2,T3,T4,T5> callback = DoGetCallback (classId); - return callback (a1, a2, a3, a4, a5); -} - - -template -Ptr -ComponentManager::Create (ClassId classId) -{ - Ptr obj = Create (classId); - Ptr i = obj->QueryInterface (); - return i; -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1) -{ - Ptr obj = Create (classId, a1); - Ptr i = obj->QueryInterface (); - return i; -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2) -{ - Ptr obj = Create (classId, a1, a2); - Ptr i = obj->QueryInterface (); - return i; -} - - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3) -{ - Ptr obj = Create (classId, a1, a2, a3); - Ptr i = obj->QueryInterface (); - return i; -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4) -{ - Ptr obj = Create (classId, a1, a2, a3, a4); - Ptr i = obj->QueryInterface (); - return i; -} - -template -Ptr -ComponentManager::Create (ClassId classId, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) -{ - Ptr obj = Create (classId, a1, a2, a3, a4, a5); - Ptr i = obj->QueryInterface (); - return i; -} - -} // namespace ns3 - -#endif /* COMPONENT_MANAGER_H */ diff --git a/src/core/wscript b/src/core/wscript index b3b0b74e4..fa8a23a16 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -40,7 +40,6 @@ def build(bld): 'default-value.cc', 'command-line.cc', 'type-name.cc', - 'component-manager.cc', 'random-variable-default-value.cc', 'variable-tracer-test.cc', 'trace-context.cc', @@ -81,7 +80,6 @@ def build(bld): 'default-value.h', 'command-line.h', 'type-name.h', - 'component-manager.h', 'type-traits.h', 'random-variable-default-value.h', 'trace-source.h', diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index c34233f73..913c4b30c 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -35,6 +35,8 @@ namespace ns3 { const uint16_t ArpL3Protocol::PROT_NUMBER = 0x0806; +NS_OBJECT_ENSURE_REGISTERED (ArpL3Protocol); + InterfaceId ArpL3Protocol::iid (void) { diff --git a/src/internet-node/ipv4-l3-protocol.cc b/src/internet-node/ipv4-l3-protocol.cc index 91e004160..eff0d651f 100644 --- a/src/internet-node/ipv4-l3-protocol.cc +++ b/src/internet-node/ipv4-l3-protocol.cc @@ -42,6 +42,8 @@ namespace ns3 { const uint16_t Ipv4L3Protocol::PROT_NUMBER = 0x0800; +NS_OBJECT_ENSURE_REGISTERED (Ipv4L3Protocol); + InterfaceId Ipv4L3Protocol::iid (void) { diff --git a/src/internet-node/ipv4-l4-demux.cc b/src/internet-node/ipv4-l4-demux.cc index a4ae9beaa..5441bdbc5 100644 --- a/src/internet-node/ipv4-l4-demux.cc +++ b/src/internet-node/ipv4-l4-demux.cc @@ -30,6 +30,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (Ipv4L4Demux); + Ipv4L4ProtocolTraceContextElement::Ipv4L4ProtocolTraceContextElement () : m_protocolNumber (0) {} diff --git a/src/mobility/grid-topology.cc b/src/mobility/grid-topology.cc index e2471a67b..6c7e66119 100644 --- a/src/mobility/grid-topology.cc +++ b/src/mobility/grid-topology.cc @@ -28,13 +28,13 @@ GridTopology::GridTopology (double xMin, double yMin, uint32_t n, double deltaX, m_n (n), m_deltaX (deltaX), m_deltaY (deltaY), - m_positionClassId (StaticMobilityModel::cid) + m_positionInterfaceId (StaticMobilityModel::iid ()) {} void -GridTopology::SetMobilityModel (ClassId classId) +GridTopology::SetMobilityModel (InterfaceId interfaceId) { - m_positionClassId = classId; + m_positionInterfaceId = interfaceId; } void @@ -43,7 +43,7 @@ GridTopology::LayoutOneRowFirst (Ptr object, uint32_t i) double x, y; x = m_xMin + m_deltaX * (i % m_n); y = m_yMin + m_deltaY * (i / m_n); - Ptr mobility = ComponentManager::Create (m_positionClassId); + Ptr mobility = m_positionInterfaceId.CreateObject ()->QueryInterface (); object->AddInterface (mobility); mobility->SetPosition (Vector (x, y, 0.0)); } @@ -54,7 +54,7 @@ GridTopology::LayoutOneColumnFirst (Ptr object, uint32_t i) double x, y; x = m_xMin + m_deltaX * (i / m_n); y = m_yMin + m_deltaY * (i % m_n); - Ptr mobility = ComponentManager::Create (m_positionClassId); + Ptr mobility = m_positionInterfaceId.CreateObject ()->QueryInterface (); object->AddInterface (mobility); mobility->SetPosition (Vector (x, y, 0.0)); } diff --git a/src/mobility/grid-topology.h b/src/mobility/grid-topology.h index f58daaae5..b9cb012d9 100644 --- a/src/mobility/grid-topology.h +++ b/src/mobility/grid-topology.h @@ -21,8 +21,8 @@ #define GRID_TOPOLOGY_H #include -#include "ns3/component-manager.h" #include "ns3/ptr.h" +#include "ns3/object.h" namespace ns3 { @@ -44,17 +44,17 @@ class GridTopology GridTopology (double xMin, double yMin, uint32_t n, double deltaX, double deltaY); /** - * \param classId the classId of the position object to attach to each + * \param interfaceId the interfaceId of the position object to attach to each * input object. */ - void SetMobilityModel (ClassId classId); + void SetMobilityModel (InterfaceId interfaceId); /** * \param begin an iterator to the first object to layout. * \param end an iterator to the last object to layout. * * Attach a position (the type of position is specified through - * the ClassId given to SetMobilityModelModel) to each input object + * the InterfaceId given to SetMobilityModelModel) to each input object * and configure its initial location with a set * of coordinates arranged according to a regular rectangular grid, * one row after the other. @@ -67,7 +67,7 @@ class GridTopology * \param end an iterator to the last object to layout. * * Attach a position (the type of position is specified through - * the ClassId given to SetMobilityModelModel) to each input object + * the InterfaceId given to SetMobilityModelModel) to each input object * and configure its initial location with a set * of coordinates arranged according to a regular rectangular grid, * one column after the other. @@ -83,7 +83,7 @@ class GridTopology uint32_t m_n; double m_deltaX; double m_deltaY; - ClassId m_positionClassId; + InterfaceId m_positionInterfaceId; }; } // namespace ns3 diff --git a/src/mobility/hierarchical-mobility-model.cc b/src/mobility/hierarchical-mobility-model.cc index d0d3f19ad..5da69f7cb 100644 --- a/src/mobility/hierarchical-mobility-model.cc +++ b/src/mobility/hierarchical-mobility-model.cc @@ -22,6 +22,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (HierarchicalMobilityModel); + InterfaceId HierarchicalMobilityModel::iid (void) { diff --git a/src/mobility/mobility-model-notifier.cc b/src/mobility/mobility-model-notifier.cc index 106896dd6..2d151e203 100644 --- a/src/mobility/mobility-model-notifier.cc +++ b/src/mobility/mobility-model-notifier.cc @@ -23,14 +23,12 @@ namespace ns3 { -const ClassId MobilityModelNotifier::cid = - MakeClassId ("MobilityModelNotifier", - MobilityModelNotifier::iid ()); InterfaceId MobilityModelNotifier::iid (void) { static InterfaceId iid = InterfaceId ("MobilityModelNotifier") - .SetParent (); + .SetParent () + .AddConstructor (); return iid; } diff --git a/src/mobility/mobility-model-notifier.h b/src/mobility/mobility-model-notifier.h index 0e9c8e544..5ec2b65a6 100644 --- a/src/mobility/mobility-model-notifier.h +++ b/src/mobility/mobility-model-notifier.h @@ -21,7 +21,6 @@ #define MOBILITY_MODEL_NOTIFIER_H #include "ns3/object.h" -#include "ns3/component-manager.h" #include "ns3/callback.h" #include "ns3/callback-trace-source.h" #include "mobility-model.h" @@ -34,7 +33,6 @@ namespace ns3 { class MobilityModelNotifier : public Object { public: - static const ClassId cid; static InterfaceId iid (void); /** diff --git a/src/mobility/random-direction-2d-mobility-model.cc b/src/mobility/random-direction-2d-mobility-model.cc index 073831027..f01a0af65 100644 --- a/src/mobility/random-direction-2d-mobility-model.cc +++ b/src/mobility/random-direction-2d-mobility-model.cc @@ -31,9 +31,8 @@ NS_LOG_COMPONENT_DEFINE ("RandomDirection2dMobilityModel"); namespace ns3 { const double RandomDirection2dMobilityModel::PI = 3.14159265358979323846; -const ClassId RandomDirection2dMobilityModel::cid = - MakeClassId ("RandomDirection2dMobilityModel", - MobilityModel::iid ()); + +NS_OBJECT_ENSURE_REGISTERED (RandomDirection2dMobilityModel); static RandomVariableDefaultValue @@ -111,6 +110,16 @@ RandomDirection2dMobilityModelParameters::GetCurrent (void) return parameters; } +InterfaceId +RandomDirection2dMobilityModel::iid (void) +{ + static InterfaceId iid = InterfaceId ("RandomDirection2dMobilityModel") + .SetParent () + .AddConstructor () + .AddConstructor > (); + return iid; +} + RandomDirection2dMobilityModel::RandomDirection2dMobilityModel () : m_parameters (RandomDirection2dMobilityModelParameters::GetCurrent ()) diff --git a/src/mobility/random-direction-2d-mobility-model.h b/src/mobility/random-direction-2d-mobility-model.h index 1d0773e50..56803bb0d 100644 --- a/src/mobility/random-direction-2d-mobility-model.h +++ b/src/mobility/random-direction-2d-mobility-model.h @@ -25,7 +25,6 @@ #include "ns3/ptr.h" #include "ns3/nstime.h" #include "ns3/event-id.h" -#include "ns3/component-manager.h" #include "ns3/rectangle.h" #include "mobility-model.h" #include "static-speed-helper.h" @@ -90,7 +89,7 @@ class RandomDirection2dMobilityModelParameters : public Object class RandomDirection2dMobilityModel : public MobilityModel { public: - static const ClassId cid; + static InterfaceId iid (void); /** * Create from \valueref{RandomDirection2dSpeed}, diff --git a/src/mobility/random-position.cc b/src/mobility/random-position.cc index 80bab1572..387cda9bf 100644 --- a/src/mobility/random-position.cc +++ b/src/mobility/random-position.cc @@ -58,6 +58,8 @@ g_discY ("RandomDiscPositionY", "The y coordinate of the center of the random position disc.", 0.0); +NS_OBJECT_ENSURE_REGISTERED (RandomPosition); + InterfaceId RandomPosition::iid (void) { @@ -66,13 +68,6 @@ RandomPosition::iid (void) return iid; } -const ClassId RandomRectanglePosition::cid = - MakeClassId ("RandomRectanglePosition", - RandomPosition::iid ()); -const ClassId RandomDiscPosition::cid = - MakeClassId ("RandomDiscPosition", - RandomPosition::iid ()); - RandomPosition::RandomPosition () { } @@ -80,6 +75,18 @@ RandomPosition::RandomPosition () RandomPosition::~RandomPosition () {} +NS_OBJECT_ENSURE_REGISTERED (RandomRectanglePosition); + +InterfaceId +RandomRectanglePosition::iid (void) +{ + static InterfaceId iid = InterfaceId ("RandomRectanglePosition") + .SetParent () + .AddConstructor () + .AddConstructor (); + return iid; +} + RandomRectanglePosition::RandomRectanglePosition () : m_x (g_rectangleX.GetCopy ()), m_y (g_rectangleY.GetCopy ()) @@ -104,6 +111,18 @@ RandomRectanglePosition::Get (void) const return Vector (x, y, 0.0); } +NS_OBJECT_ENSURE_REGISTERED (RandomDiscPosition); + +InterfaceId +RandomDiscPosition::iid (void) +{ + static InterfaceId iid = InterfaceId ("RandomDiscPosition") + .SetParent () + .AddConstructor () + .AddConstructor (); + return iid; +} + RandomDiscPosition::RandomDiscPosition () : m_theta (g_discTheta.GetCopy ()), m_rho (g_discRho.GetCopy ()), diff --git a/src/mobility/random-position.h b/src/mobility/random-position.h index bbd7272ea..6950d66f0 100644 --- a/src/mobility/random-position.h +++ b/src/mobility/random-position.h @@ -21,7 +21,6 @@ #define RANDOM_POSITION_H #include "ns3/object.h" -#include "ns3/component-manager.h" #include "vector.h" namespace ns3 { @@ -52,7 +51,7 @@ public: class RandomRectanglePosition : public RandomPosition { public: - static const ClassId cid; + static InterfaceId iid (void); /** * Create a random position model with construction * values from \valueref{RandomRectanglePositionX}, and @@ -81,7 +80,7 @@ private: class RandomDiscPosition : public RandomPosition { public: - static const ClassId cid; + static InterfaceId iid (void); /** * Create a random position model with construction * values from \valueref{RandomDiscPositionTheta}, diff --git a/src/mobility/random-topology.cc b/src/mobility/random-topology.cc index 8f5d39dc7..0a41bf78a 100644 --- a/src/mobility/random-topology.cc +++ b/src/mobility/random-topology.cc @@ -22,16 +22,17 @@ #include "random-topology.h" #include "random-position.h" #include "mobility-model.h" +#include "ns3/interface-id-default-value.h" namespace ns3 { -static ClassIdDefaultValue +static InterfaceIdDefaultValue g_position ("RandomTopologyPositionType", "The type of initial random position in a 3d topology.", RandomPosition::iid (), "RandomRectanglePosition"); -static ClassIdDefaultValue +static InterfaceIdDefaultValue g_mobility ("RandomTopologyMobilityType", "The type of mobility model attached to an object in a 3d topology.", MobilityModel::iid (), @@ -40,9 +41,9 @@ g_mobility ("RandomTopologyMobilityType", RandomTopology::RandomTopology () : m_mobilityModel (g_mobility.GetValue ()) { - m_positionModel = ComponentManager::Create (g_position.GetValue ()); + m_positionModel = g_position.GetValue ().CreateObject ()->QueryInterface (); } -RandomTopology::RandomTopology (Ptr positionModel, ClassId mobilityModel) +RandomTopology::RandomTopology (Ptr positionModel, InterfaceId mobilityModel) : m_positionModel (positionModel), m_mobilityModel (mobilityModel) {} @@ -52,9 +53,9 @@ RandomTopology::~RandomTopology () } void -RandomTopology::SetMobilityModel (ClassId classId) +RandomTopology::SetMobilityModel (InterfaceId interfaceId) { - m_mobilityModel = classId; + m_mobilityModel = interfaceId; } void @@ -66,7 +67,7 @@ RandomTopology::SetPositionModel (Ptr positionModel) void RandomTopology::LayoutOne (Ptr object) { - Ptr mobility = ComponentManager::Create (m_mobilityModel); + Ptr mobility = m_mobilityModel.CreateObject ()->QueryInterface (); object->AddInterface (mobility); Vector position = m_positionModel->Get (); mobility->SetPosition (position); diff --git a/src/mobility/random-topology.h b/src/mobility/random-topology.h index 4a6d1817c..ac1676d37 100644 --- a/src/mobility/random-topology.h +++ b/src/mobility/random-topology.h @@ -23,7 +23,6 @@ #include "ns3/ptr.h" #include "ns3/object.h" -#include "ns3/component-manager.h" namespace ns3 { @@ -55,15 +54,15 @@ class RandomTopology * specified position and mobility models. */ RandomTopology (Ptr positionModel, - ClassId mobilityModel); + InterfaceId mobilityModel); ~RandomTopology (); /** - * \param classId the type of mobility model attached to each + * \param interfaceId the type of mobility model attached to each * input object if it does not have one already. */ - void SetMobilityModel (ClassId classId); + void SetMobilityModel (InterfaceId interfaceId); /** * \param positionModel the position model used to initialize * the position of each object. @@ -91,7 +90,7 @@ class RandomTopology void Layout (const T &begin, const T &end); private: Ptr m_positionModel; - ClassId m_mobilityModel; + InterfaceId m_mobilityModel; }; } // namespace ns3 diff --git a/src/mobility/random-walk-2d-mobility-model.cc b/src/mobility/random-walk-2d-mobility-model.cc index 992f04235..03c3f3a0f 100644 --- a/src/mobility/random-walk-2d-mobility-model.cc +++ b/src/mobility/random-walk-2d-mobility-model.cc @@ -31,9 +31,7 @@ NS_LOG_COMPONENT_DEFINE ("RandomWalk2d"); namespace ns3 { -const ClassId RandomWalk2dMobilityModel::cid = - MakeClassId ("RandomWalk2dMobilityModel", RandomWalk2dMobilityModel::iid ()); - +NS_OBJECT_ENSURE_REGISTERED (RandomWalk2dMobilityModel); static EnumDefaultValue g_mode ("RandomWalk2dMode", @@ -131,12 +129,28 @@ RandomWalk2dMobilityModelParameters::GetCurrent (void) return parameters; } +InterfaceId +RandomWalk2dMobilityModel::iid (void) +{ + static InterfaceId iid = InterfaceId ("RandomWalkMobilityModel") + .SetParent () + .AddConstructor () + .AddConstructor > (); + return iid; +} + RandomWalk2dMobilityModel::RandomWalk2dMobilityModel () : m_parameters (RandomWalk2dMobilityModelParameters::GetCurrent ()) { m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); } +RandomWalk2dMobilityModel::RandomWalk2dMobilityModel (Ptr parameters) + : m_parameters (parameters) +{ + m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this); +} + void RandomWalk2dMobilityModel::Start (void) { diff --git a/src/mobility/random-walk-2d-mobility-model.h b/src/mobility/random-walk-2d-mobility-model.h index 72def7ade..b0b8271c3 100644 --- a/src/mobility/random-walk-2d-mobility-model.h +++ b/src/mobility/random-walk-2d-mobility-model.h @@ -23,7 +23,6 @@ #include "ns3/object.h" #include "ns3/nstime.h" -#include "ns3/component-manager.h" #include "ns3/event-id.h" #include "ns3/rectangle.h" #include "mobility-model.h" @@ -116,7 +115,7 @@ class RandomWalk2dMobilityModelParameters : public Object class RandomWalk2dMobilityModel : public MobilityModel { public: - static const ClassId cid; + static InterfaceId iid (void); /** * Instantiate a set of RandomWalk parameters initialized * with construction values from \valueref{RandomWalk2dMode}, diff --git a/src/mobility/random-waypoint-mobility-model.cc b/src/mobility/random-waypoint-mobility-model.cc index 983970411..f31daaf7d 100644 --- a/src/mobility/random-waypoint-mobility-model.cc +++ b/src/mobility/random-waypoint-mobility-model.cc @@ -21,12 +21,14 @@ #include "ns3/simulator.h" #include "ns3/random-variable.h" #include "ns3/random-variable-default-value.h" -#include "ns3/component-manager.h" +#include "ns3/interface-id-default-value.h" #include "random-waypoint-mobility-model.h" #include "random-position.h" namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (RandomWaypointMobilityModel); + static RandomVariableDefaultValue g_speed ("RandomWaypointSpeed", "A random variable used to pick the speed of a random waypoint model.", @@ -37,20 +39,18 @@ g_pause ("RandomWaypointPause", "A random variable used to pick the pause of a random waypoint model.", "Constant:2"); -static ClassIdDefaultValue +static InterfaceIdDefaultValue g_position ("RandomWaypointPosition", "A random position model used to pick the next waypoint position.", RandomPosition::iid (), "RandomRectanglePosition"); -const ClassId RandomWaypointMobilityModel::cid = - MakeClassId ("RandomWaypointMobilityModel", MobilityModel::iid ()); RandomWaypointMobilityModelParameters::RandomWaypointMobilityModelParameters () : m_speed (g_speed.GetCopy ()), m_pause (g_pause.GetCopy ()) { - m_position = ComponentManager::Create (g_position.GetValue ()); + m_position = g_position.GetValue ().CreateObject ()->QueryInterface (); } RandomWaypointMobilityModelParameters::RandomWaypointMobilityModelParameters (Ptr randomPosition, const RandomVariable &speed, @@ -100,6 +100,16 @@ RandomWaypointMobilityModelParameters::GetCurrent (void) return parameters; } +InterfaceId +RandomWaypointMobilityModel::iid (void) +{ + static InterfaceId iid = InterfaceId ("RandomWaypointMobilityModel") + .SetParent () + .AddConstructor () + .AddConstructor > (); + return iid; +} + RandomWaypointMobilityModel::RandomWaypointMobilityModel () : m_parameters (RandomWaypointMobilityModelParameters::GetCurrent ()) { diff --git a/src/mobility/random-waypoint-mobility-model.h b/src/mobility/random-waypoint-mobility-model.h index 273d38a02..53822258f 100644 --- a/src/mobility/random-waypoint-mobility-model.h +++ b/src/mobility/random-waypoint-mobility-model.h @@ -86,8 +86,7 @@ private: class RandomWaypointMobilityModel : public MobilityModel { public: - static const ClassId cid; - + static InterfaceId iid (void); /** * Default parameters from \valueref{RandomWaypointPause}, * and, \valueref{RandomWaypointPosition}. diff --git a/src/mobility/static-mobility-model.cc b/src/mobility/static-mobility-model.cc index b8d07c7fd..11ed4ed84 100644 --- a/src/mobility/static-mobility-model.cc +++ b/src/mobility/static-mobility-model.cc @@ -21,8 +21,17 @@ namespace ns3 { -const ClassId StaticMobilityModel::cid = MakeClassId ("StaticMobilityModel", - MobilityModel::iid ()); +NS_OBJECT_ENSURE_REGISTERED (StaticMobilityModel); + +InterfaceId +StaticMobilityModel::iid (void) +{ + static InterfaceId iid = InterfaceId ("StaticMobilityModel") + .SetParent () + .AddConstructor () + .AddConstructor (); + return iid; +} StaticMobilityModel::StaticMobilityModel () {} diff --git a/src/mobility/static-mobility-model.h b/src/mobility/static-mobility-model.h index 995cad598..764d37d29 100644 --- a/src/mobility/static-mobility-model.h +++ b/src/mobility/static-mobility-model.h @@ -20,7 +20,6 @@ #ifndef STATIC_MOBILITY_MODEL_H #define STATIC_MOBILITY_MODEL_H -#include "ns3/component-manager.h" #include "mobility-model.h" namespace ns3 { @@ -33,7 +32,7 @@ namespace ns3 { class StaticMobilityModel : public MobilityModel { public: - static const ClassId cid; + static InterfaceId iid (void); /** * Create a position located at coordinates (0,0,0) */ diff --git a/src/mobility/static-speed-mobility-model.cc b/src/mobility/static-speed-mobility-model.cc index 002f6af4d..42f94e085 100644 --- a/src/mobility/static-speed-mobility-model.cc +++ b/src/mobility/static-speed-mobility-model.cc @@ -22,13 +22,15 @@ namespace ns3 { -const ClassId StaticSpeedMobilityModel::cid = - MakeClassId ("StaticSpeedMobilityModel", - StaticSpeedMobilityModel::iid ()); +NS_OBJECT_ENSURE_REGISTERED (StaticSpeedMobilityModel); + InterfaceId StaticSpeedMobilityModel::iid (void) { static InterfaceId iid = InterfaceId ("StaticSpeedMobilityModel") - .SetParent (); + .SetParent () + .AddConstructor () + .AddConstructor () + .AddConstructor (); return iid; } diff --git a/src/mobility/static-speed-mobility-model.h b/src/mobility/static-speed-mobility-model.h index dd06f9288..6ba020107 100644 --- a/src/mobility/static-speed-mobility-model.h +++ b/src/mobility/static-speed-mobility-model.h @@ -23,7 +23,6 @@ #include #include "mobility-model.h" #include "ns3/nstime.h" -#include "ns3/component-manager.h" #include "static-speed-helper.h" namespace ns3 { @@ -36,7 +35,6 @@ namespace ns3 { class StaticSpeedMobilityModel : public MobilityModel { public: - static const ClassId cid; static InterfaceId iid (void); /** * Create position located at coordinates (0,0,0) with diff --git a/src/node/channel.cc b/src/node/channel.cc index b931667bd..cd5202ed7 100644 --- a/src/node/channel.cc +++ b/src/node/channel.cc @@ -24,6 +24,8 @@ NS_LOG_COMPONENT_DEFINE ("Channel"); namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (Channel); + InterfaceId Channel::iid (void) { diff --git a/src/node/drop-tail-queue.cc b/src/node/drop-tail-queue.cc index f0900703d..872f0859d 100644 --- a/src/node/drop-tail-queue.cc +++ b/src/node/drop-tail-queue.cc @@ -24,9 +24,15 @@ NS_LOG_COMPONENT_DEFINE ("DropTailQueue"); namespace ns3 { -const ClassId DropTailQueue::cid = - MakeClassId ("DropTailQueue", Queue::iid ()); +NS_OBJECT_ENSURE_REGISTERED (DropTailQueue); +InterfaceId DropTailQueue::iid (void) +{ + static InterfaceId iid = InterfaceId ("DropTailQueue") + .SetParent () + .AddConstructor (); + return iid; +} DropTailQueue::DropTailQueue () : Queue (), diff --git a/src/node/drop-tail-queue.h b/src/node/drop-tail-queue.h index 3569db468..ceed313c4 100644 --- a/src/node/drop-tail-queue.h +++ b/src/node/drop-tail-queue.h @@ -23,7 +23,6 @@ #include #include "ns3/packet.h" #include "ns3/queue.h" -#include "ns3/component-manager.h" namespace ns3 { @@ -36,7 +35,7 @@ const int DTQ_NPACKETS_MAX_DEFAULT = 100; */ class DropTailQueue : public Queue { public: - static const ClassId cid; + static InterfaceId iid (void); /** * \brief DropTailQueue Constructor * diff --git a/src/node/ipv4.cc b/src/node/ipv4.cc index 76908dda4..410766584 100644 --- a/src/node/ipv4.cc +++ b/src/node/ipv4.cc @@ -25,6 +25,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (Ipv4); + InterfaceId Ipv4::iid (void) { diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 1e9e2adbf..9485ee894 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -33,6 +33,8 @@ NS_LOG_COMPONENT_DEFINE ("NetDevice"); namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (NetDevice); + InterfaceId NetDevice::iid (void) { static InterfaceId iid = InterfaceId ("NetDevice") diff --git a/src/node/node.cc b/src/node/node.cc index b8fd96227..d7a2c3f6c 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -29,6 +29,8 @@ namespace ns3{ +NS_OBJECT_ENSURE_REGISTERED (Node); + InterfaceId Node::iid (void) { diff --git a/src/node/packet-socket-factory.cc b/src/node/packet-socket-factory.cc index 6a088c33a..5c82611f6 100644 --- a/src/node/packet-socket-factory.cc +++ b/src/node/packet-socket-factory.cc @@ -24,6 +24,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (PacketSocketFactory); + InterfaceId PacketSocketFactory::iid (void) { diff --git a/src/node/queue.cc b/src/node/queue.cc index 2b69abee2..0f27b514d 100644 --- a/src/node/queue.cc +++ b/src/node/queue.cc @@ -20,15 +20,17 @@ #include "ns3/log.h" #include "ns3/composite-trace-resolver.h" #include "ns3/default-value.h" -#include "ns3/component-manager.h" +#include "ns3/interface-id-default-value.h" #include "queue.h" NS_LOG_COMPONENT_DEFINE ("Queue"); namespace ns3 { -static ClassIdDefaultValue g_classIdDefaultValue ("Queue", "Packet Queue", - Queue::iid (), "DropTailQueue"); +static InterfaceIdDefaultValue g_interfaceIdDefaultValue ("Queue", "Packet Queue", + Queue::iid (), "DropTailQueue"); + +NS_OBJECT_ENSURE_REGISTERED (Queue); std::string @@ -281,8 +283,8 @@ Ptr Queue::CreateDefault (void) { NS_LOG_FUNCTION; - ClassId classId = g_classIdDefaultValue.GetValue (); - Ptr queue = ComponentManager::Create (classId); + InterfaceId interfaceId = g_interfaceIdDefaultValue.GetValue (); + Ptr queue = interfaceId.CreateObject ()->QueryInterface (); return queue; } diff --git a/src/node/socket-factory.cc b/src/node/socket-factory.cc index 537153f33..4ae3733fe 100644 --- a/src/node/socket-factory.cc +++ b/src/node/socket-factory.cc @@ -22,6 +22,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (SocketFactory); + InterfaceId SocketFactory::iid (void) { static InterfaceId iid = InterfaceId ("SocketFactory") diff --git a/src/node/udp.cc b/src/node/udp.cc index 5d58849be..03de61448 100644 --- a/src/node/udp.cc +++ b/src/node/udp.cc @@ -22,6 +22,8 @@ namespace ns3 { +NS_OBJECT_ENSURE_REGISTERED (Udp); + InterfaceId Udp::iid (void) { static InterfaceId iid = InterfaceId ("Udp") diff --git a/src/routing/global-routing/global-router-interface.cc b/src/routing/global-routing/global-router-interface.cc index 9e9806096..0cf86ffa7 100644 --- a/src/routing/global-routing/global-router-interface.cc +++ b/src/routing/global-routing/global-router-interface.cc @@ -431,6 +431,8 @@ std::ostream& operator<< (std::ostream& os, GlobalRoutingLSA& lsa) // // --------------------------------------------------------------------------- +NS_OBJECT_ENSURE_REGISTERED (GlobalRouter); + InterfaceId GlobalRouter::iid (void) { diff --git a/src/routing/olsr/olsr-agent-impl.cc b/src/routing/olsr/olsr-agent-impl.cc index 56642325f..32f84dcab 100644 --- a/src/routing/olsr/olsr-agent-impl.cc +++ b/src/routing/olsr/olsr-agent-impl.cc @@ -148,6 +148,17 @@ NS_LOG_COMPONENT_DEFINE ("OlsrAgent"); /********** OLSR class **********/ +NS_OBJECT_ENSURE_REGISTERED (AgentImpl); + +InterfaceId +AgentImpl::iid (void) +{ + static InterfaceId iid = InterfaceId ("OlsrAgentImpl") + .SetParent () + .AddConstructor > (); + return iid; +} + AgentImpl::AgentImpl (Ptr node) : diff --git a/src/routing/olsr/olsr-agent-impl.h b/src/routing/olsr/olsr-agent-impl.h index ab22927f2..ab67b2039 100644 --- a/src/routing/olsr/olsr-agent-impl.h +++ b/src/routing/olsr/olsr-agent-impl.h @@ -49,6 +49,8 @@ namespace olsr { class AgentImpl : public Agent { public: + static InterfaceId iid (void); + AgentImpl (Ptr node); virtual void Start (); diff --git a/src/routing/olsr/olsr-agent.cc b/src/routing/olsr/olsr-agent.cc index ad710bda3..6b736a29e 100644 --- a/src/routing/olsr/olsr-agent.cc +++ b/src/routing/olsr/olsr-agent.cc @@ -19,12 +19,18 @@ */ #include "olsr-agent.h" -#include "olsr-agent-impl.h" +#include "ns3/interface-id-default-value.h" namespace ns3 { namespace olsr { -const ClassId Agent::cid = MakeClassId< AgentImpl, Ptr > ("OlsrAgent", Agent::iid ()); +static InterfaceIdDefaultValue g_defaultImpl = + InterfaceIdDefaultValue ("OlsrAgentType", + "The type of OlsrAgent implementation", + Agent::iid (), + "OlsrAgentImpl"); + +NS_OBJECT_ENSURE_REGISTERED (Agent); InterfaceId Agent::iid (void) @@ -34,5 +40,13 @@ Agent::iid (void) return iid; } +Ptr +Agent::CreateDefault (Ptr node) +{ + InterfaceId iid = g_defaultImpl.GetValue (); + Ptr agent = iid.CreateObject (node)->QueryInterface (); + return agent; +} + }} diff --git a/src/routing/olsr/olsr-agent.h b/src/routing/olsr/olsr-agent.h index 58c030bdd..a3b0a0d67 100644 --- a/src/routing/olsr/olsr-agent.h +++ b/src/routing/olsr/olsr-agent.h @@ -22,7 +22,6 @@ #define OLSR_AGENT_H #include "ns3/node.h" -#include "ns3/component-manager.h" namespace ns3 { namespace olsr { @@ -38,7 +37,7 @@ namespace olsr { * Example: * * \code - * Ptr olsr = ComponentManager::Create > (olsr::Agent::cid, olsr::Agent::iid, node); + * Ptr olsr = Agend::CreateDefault (); * agent->SetMainInterface (2); * agent->Start (); * \endcode @@ -47,7 +46,8 @@ class Agent : public Object { public: static InterfaceId iid (void); - static const ClassId cid; + + static Ptr CreateDefault (Ptr node); /** * \brief Sets the main interface to be used by OLSR diff --git a/src/routing/olsr/olsr.cc b/src/routing/olsr/olsr.cc index 2d461717a..c6829dc25 100644 --- a/src/routing/olsr/olsr.cc +++ b/src/routing/olsr/olsr.cc @@ -33,8 +33,7 @@ EnableAllNodes (void) void EnableNode (Ptr node) { - ComponentManager::Create > - (olsr::Agent::cid, node)->Start (); + olsr::Agent::CreateDefault (node); }