port ComponentManager to Object from Interface
This commit is contained in:
@@ -49,10 +49,10 @@ bool operator == (const ClassId &a, const ClassId &b)
|
||||
return a.m_classId == b.m_classId;
|
||||
}
|
||||
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::Create (ClassId classId)
|
||||
{
|
||||
Callback<Ptr<Interface> > callback = DoGetCallback<empty,empty,empty,empty,empty> (classId);
|
||||
Callback<Ptr<Object> > callback = DoGetCallback<empty,empty,empty,empty,empty> (classId);
|
||||
return callback ();
|
||||
}
|
||||
|
||||
@@ -91,26 +91,27 @@ ComponentManager::Register (std::string name, CallbackBase *callback)
|
||||
#ifdef RUN_SELF_TESTS
|
||||
|
||||
#include "test.h"
|
||||
#include "interface.h"
|
||||
#include "object.h"
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
class B : public ns3::Interface
|
||||
class B : public ns3::Object
|
||||
{
|
||||
public:
|
||||
static const ns3::InterfaceId iid;
|
||||
B ();
|
||||
};
|
||||
|
||||
const ns3::InterfaceId B::iid ("IB");
|
||||
const ns3::InterfaceId B::iid = MakeInterfaceId ("B", Object::iid);
|
||||
|
||||
B::B ()
|
||||
: Interface (B::iid)
|
||||
{}
|
||||
{
|
||||
SetInterfaceId (B::iid);
|
||||
}
|
||||
|
||||
|
||||
class A : public ns3::Interface
|
||||
class A : public ns3::Object
|
||||
{
|
||||
public:
|
||||
static const ns3::ClassId cidZero;
|
||||
@@ -133,36 +134,36 @@ public:
|
||||
const ns3::ClassId A::cidZero = ns3::ComponentManager::RegisterConstructor <A> ("A");
|
||||
const ns3::ClassId A::cidOneBool = ns3::ComponentManager::RegisterConstructor <A,bool> ("ABool");
|
||||
const ns3::ClassId A::cidOneUi32 = ns3::ComponentManager::RegisterConstructor <A,uint32_t> ("AUi32");
|
||||
const ns3::InterfaceId A::iid ("IA");
|
||||
const ns3::InterfaceId A::iid = MakeInterfaceId ("A", Object::iid);
|
||||
|
||||
A::A ()
|
||||
: Interface (A::iid),
|
||||
m_zeroInvoked (true),
|
||||
: m_zeroInvoked (true),
|
||||
m_oneBoolInvoked (false),
|
||||
m_oneUi32Invoked (false)
|
||||
{
|
||||
SetInterfaceId (A::iid);
|
||||
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
|
||||
AddInterface (b);
|
||||
}
|
||||
|
||||
A::A (bool bo)
|
||||
: Interface (A::iid),
|
||||
m_zeroInvoked (false),
|
||||
: m_zeroInvoked (false),
|
||||
m_oneBoolInvoked (true),
|
||||
m_oneUi32Invoked (false),
|
||||
m_bool (bo)
|
||||
{
|
||||
SetInterfaceId (A::iid);
|
||||
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
|
||||
AddInterface (b);
|
||||
}
|
||||
|
||||
A::A (uint32_t i)
|
||||
: Interface (A::iid),
|
||||
m_zeroInvoked (false),
|
||||
: m_zeroInvoked (false),
|
||||
m_oneBoolInvoked (false),
|
||||
m_oneUi32Invoked (true),
|
||||
m_ui32 (i)
|
||||
{
|
||||
SetInterfaceId (A::iid);
|
||||
ns3::Ptr<B> b = ns3::MakeNewObject<B> ();
|
||||
AddInterface (b);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include "callback.h"
|
||||
#include "interface.h"
|
||||
#include "object.h"
|
||||
#include "fatal-error.h"
|
||||
#include "ptr.h"
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
* Create an instance of the object identified by its
|
||||
* ClassId. This method invokes the default constructor.
|
||||
*/
|
||||
static Ptr<Interface> Create (ClassId classId);
|
||||
static Ptr<Object> Create (ClassId classId);
|
||||
|
||||
/**
|
||||
* \param classId class id of the constructor to invoke.
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
* ClassId.
|
||||
*/
|
||||
template <typename T1>
|
||||
static Ptr<Interface> Create (ClassId classId, T1 a1);
|
||||
static Ptr<Object> Create (ClassId classId, T1 a1);
|
||||
|
||||
/**
|
||||
* \param classId class id of the constructor to invoke.
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
* ClassId.
|
||||
*/
|
||||
template <typename T1, typename T2>
|
||||
static Ptr<Interface> Create (ClassId classId, T1 a1, T2 a2);
|
||||
static Ptr<Object> Create (ClassId classId, T1 a1, T2 a2);
|
||||
|
||||
/**
|
||||
* \param classId class id of the constructor to invoke.
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
template <typename T>
|
||||
static ClassId RegisterConstructor (std::string name)
|
||||
{
|
||||
static Callback<Ptr<Interface> > callback =
|
||||
static Callback<Ptr<Object> > callback =
|
||||
MakeCallback (&ComponentManager::MakeObjectZero<T>);
|
||||
return ComponentManager::Register (name, &callback);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
template <typename T, typename T1>
|
||||
static ClassId RegisterConstructor (std::string name)
|
||||
{
|
||||
static Callback<Ptr<Interface> ,T1> callback = MakeCallback (&ComponentManager::MakeObjectOne<T,T1>);
|
||||
static Callback<Ptr<Object> ,T1> callback = MakeCallback (&ComponentManager::MakeObjectOne<T,T1>);
|
||||
return ComponentManager::Register (name, &callback);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
template <typename T, typename T1, typename T2>
|
||||
static ClassId RegisterConstructor (std::string name)
|
||||
{
|
||||
static Callback<Ptr<Interface>,T1,T2> callback = MakeCallback (&ComponentManager::MakeObjectTwo<T,T1,T2>);
|
||||
static Callback<Ptr<Object>,T1,T2> callback = MakeCallback (&ComponentManager::MakeObjectTwo<T,T1,T2>);
|
||||
return ComponentManager::Register (name, &callback);
|
||||
}
|
||||
private:
|
||||
@@ -168,16 +168,16 @@ private:
|
||||
template <typename T1, typename T2,
|
||||
typename T3, typename T4,
|
||||
typename T5>
|
||||
static Callback<Ptr<Interface>,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId);
|
||||
static Callback<Ptr<Object>,T1,T2,T3,T4,T5> DoGetCallback (ClassId classId);
|
||||
|
||||
template <typename T>
|
||||
static Ptr<Interface> MakeObjectZero (void);
|
||||
static Ptr<Object> MakeObjectZero (void);
|
||||
|
||||
template <typename T, typename T1>
|
||||
static Ptr<Interface> MakeObjectOne (T1 a1);
|
||||
static Ptr<Object> MakeObjectOne (T1 a1);
|
||||
|
||||
template <typename T, typename T1, typename T2>
|
||||
static Ptr<Interface> MakeObjectTwo (T1 a1, T2 a2);
|
||||
static Ptr<Object> MakeObjectTwo (T1 a1, T2 a2);
|
||||
|
||||
typedef std::vector<std::pair<ClassId, CallbackBase *> > List;
|
||||
static List *GetList (void);
|
||||
@@ -192,7 +192,7 @@ namespace ns3 {
|
||||
template <typename T1, typename T2,
|
||||
typename T3, typename T4,
|
||||
typename T5>
|
||||
Callback<Ptr<Interface>,T1,T2,T3,T4,T5>
|
||||
Callback<Ptr<Object>,T1,T2,T3,T4,T5>
|
||||
ComponentManager::DoGetCallback (ClassId classId)
|
||||
{
|
||||
CallbackBase *callback = Lookup (classId);
|
||||
@@ -200,25 +200,25 @@ ComponentManager::DoGetCallback (ClassId classId)
|
||||
{
|
||||
NS_FATAL_ERROR ("Invalid Class Id.");
|
||||
}
|
||||
Callback<Ptr<Interface>, T1,T2,T3,T4,T5> reference;
|
||||
Callback<Ptr<Object>, T1,T2,T3,T4,T5> reference;
|
||||
reference.Assign (*callback);
|
||||
return reference;
|
||||
}
|
||||
|
||||
|
||||
template <typename T1>
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::Create (ClassId classId, T1 a1)
|
||||
{
|
||||
Callback<Ptr<Interface>, T1> callback = DoGetCallback<T1,empty,empty,empty,empty> (classId);
|
||||
Callback<Ptr<Object>, T1> callback = DoGetCallback<T1,empty,empty,empty,empty> (classId);
|
||||
return callback (a1);
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::Create (ClassId classId, T1 a1, T2 a2)
|
||||
{
|
||||
Callback<Ptr<Interface> , T1,T2> callback = DoGetCallback<T1,T2,empty,empty,empty> (classId);
|
||||
Callback<Ptr<Object> , T1,T2> callback = DoGetCallback<T1,T2,empty,empty,empty> (classId);
|
||||
return callback (a1, a2);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ template <typename T>
|
||||
Ptr<T>
|
||||
ComponentManager::Create (ClassId classId, InterfaceId iid)
|
||||
{
|
||||
Ptr<Interface> obj = Create (classId);
|
||||
Ptr<Object> obj = Create (classId);
|
||||
Ptr<T> i = obj->QueryInterface<T> (iid);
|
||||
return i;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ template <typename T, typename T1>
|
||||
Ptr<T>
|
||||
ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1)
|
||||
{
|
||||
Ptr<Interface> obj = Create (classId, a1);
|
||||
Ptr<Object> obj = Create (classId, a1);
|
||||
Ptr<T> i = obj->QueryInterface<T> (iid);
|
||||
return i;
|
||||
}
|
||||
@@ -244,26 +244,26 @@ template <typename T, typename T1, typename T2>
|
||||
Ptr<T>
|
||||
ComponentManager::Create (ClassId classId, InterfaceId iid, T1 a1, T2 a2)
|
||||
{
|
||||
Ptr<Interface> obj = Create (classId, a1, a2);
|
||||
Ptr<Object> obj = Create (classId, a1, a2);
|
||||
Ptr<T> i = obj->QueryInterface<T> (iid);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::MakeObjectZero (void)
|
||||
{
|
||||
return MakeNewObject<T> ();
|
||||
}
|
||||
template <typename T, typename T1>
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::MakeObjectOne (T1 a1)
|
||||
{
|
||||
return MakeNewObject<T> (a1);
|
||||
}
|
||||
template <typename T, typename T1, typename T2>
|
||||
Ptr<Interface>
|
||||
Ptr<Object>
|
||||
ComponentManager::MakeObjectTwo (T1 a1, T2 a2)
|
||||
{
|
||||
return MakeNewObject<T> (a1, a2);
|
||||
|
||||
@@ -54,50 +54,50 @@ IidTree::LookupParent (uint32_t child)
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
MyInterfaceId::MyInterfaceId (uint32_t iid)
|
||||
InterfaceId::InterfaceId (uint32_t iid)
|
||||
: m_iid (iid)
|
||||
{}
|
||||
MyInterfaceId::~MyInterfaceId ()
|
||||
InterfaceId::~InterfaceId ()
|
||||
{}
|
||||
MyInterfaceId
|
||||
MyInterfaceId::LookupByName (std::string name)
|
||||
InterfaceId
|
||||
InterfaceId::LookupByName (std::string name)
|
||||
{
|
||||
return MyInterfaceId (Singleton<IidManager>::Get ()->LookupByName (name));
|
||||
return InterfaceId (Singleton<IidManager>::Get ()->LookupByName (name));
|
||||
}
|
||||
MyInterfaceId
|
||||
MyInterfaceId::LookupParent (MyInterfaceId iid)
|
||||
InterfaceId
|
||||
InterfaceId::LookupParent (InterfaceId iid)
|
||||
{
|
||||
return Singleton<IidTree>::Get ()->LookupParent (iid.m_iid);
|
||||
}
|
||||
|
||||
bool operator == (const MyInterfaceId &a, const MyInterfaceId &b)
|
||||
bool operator == (const InterfaceId &a, const InterfaceId &b)
|
||||
{
|
||||
return a.m_iid == b.m_iid;
|
||||
}
|
||||
|
||||
bool operator != (const MyInterfaceId &a, const MyInterfaceId &b)
|
||||
bool operator != (const InterfaceId &a, const InterfaceId &b)
|
||||
{
|
||||
return a.m_iid != b.m_iid;
|
||||
}
|
||||
|
||||
MyInterfaceId
|
||||
MakeInterfaceId (std::string name, const MyInterfaceId &parent)
|
||||
InterfaceId
|
||||
MakeInterfaceId (std::string name, const InterfaceId &parent)
|
||||
{
|
||||
MyInterfaceId iid = Singleton<IidManager>::Get ()->Allocate (name);
|
||||
InterfaceId iid = Singleton<IidManager>::Get ()->Allocate (name);
|
||||
Singleton<IidTree>::Get ()->SetParent (iid.m_iid, &parent.m_iid);
|
||||
return iid;
|
||||
}
|
||||
|
||||
MyInterfaceId
|
||||
InterfaceId
|
||||
MakeObjectInterfaceId (void)
|
||||
{
|
||||
MyInterfaceId iid = Singleton<IidManager>::Get ()->Allocate ("Object");
|
||||
InterfaceId iid = Singleton<IidManager>::Get ()->Allocate ("Object");
|
||||
Singleton<IidTree>::Get ()->SetParent (iid.m_iid, &iid.m_iid);
|
||||
return iid;
|
||||
}
|
||||
|
||||
|
||||
const MyInterfaceId Object::iid = MakeObjectInterfaceId ();
|
||||
const InterfaceId Object::iid = MakeObjectInterfaceId ();
|
||||
|
||||
|
||||
Object::Object ()
|
||||
@@ -110,16 +110,16 @@ Object::~Object ()
|
||||
m_next = 0;
|
||||
}
|
||||
Ptr<Object>
|
||||
Object::DoQueryInterface (MyInterfaceId iid)
|
||||
Object::DoQueryInterface (InterfaceId iid)
|
||||
{
|
||||
NS_ASSERT (Check ());
|
||||
Object *currentObject = this;
|
||||
do {
|
||||
NS_ASSERT (currentObject != 0);
|
||||
MyInterfaceId cur = currentObject->m_iid;
|
||||
InterfaceId cur = currentObject->m_iid;
|
||||
while (cur != iid && cur != Object::iid)
|
||||
{
|
||||
cur = MyInterfaceId::LookupParent (cur);
|
||||
cur = InterfaceId::LookupParent (cur);
|
||||
}
|
||||
if (cur == iid)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ Object::AddInterface (Ptr<Object> o)
|
||||
}
|
||||
|
||||
void
|
||||
Object::SetInterfaceId (MyInterfaceId iid)
|
||||
Object::SetInterfaceId (InterfaceId iid)
|
||||
{
|
||||
NS_ASSERT (Check ());
|
||||
m_iid = iid;
|
||||
@@ -212,7 +212,7 @@ namespace {
|
||||
class BaseA : public ns3::Object
|
||||
{
|
||||
public:
|
||||
static const ns3::MyInterfaceId iid;
|
||||
static const ns3::InterfaceId iid;
|
||||
BaseA ()
|
||||
{
|
||||
SetInterfaceId (BaseA::iid);
|
||||
@@ -223,7 +223,7 @@ public:
|
||||
class DerivedA : public BaseA
|
||||
{
|
||||
public:
|
||||
static const ns3::MyInterfaceId iid;
|
||||
static const ns3::InterfaceId iid;
|
||||
DerivedA (int v)
|
||||
{
|
||||
SetInterfaceId (DerivedA::iid);
|
||||
@@ -233,15 +233,15 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
const ns3::MyInterfaceId BaseA::iid =
|
||||
const ns3::InterfaceId BaseA::iid =
|
||||
ns3::MakeInterfaceId ("BaseA", Object::iid);
|
||||
const ns3::MyInterfaceId DerivedA::iid =
|
||||
const ns3::InterfaceId DerivedA::iid =
|
||||
ns3::MakeInterfaceId ("DerivedA", BaseA::iid);;
|
||||
|
||||
class BaseB : public ns3::Object
|
||||
{
|
||||
public:
|
||||
static const ns3::MyInterfaceId iid;
|
||||
static const ns3::InterfaceId iid;
|
||||
BaseB ()
|
||||
{
|
||||
SetInterfaceId (BaseB::iid);
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
class DerivedB : public BaseB
|
||||
{
|
||||
public:
|
||||
static const ns3::MyInterfaceId iid;
|
||||
static const ns3::InterfaceId iid;
|
||||
DerivedB (int v)
|
||||
{
|
||||
SetInterfaceId (DerivedB::iid);
|
||||
@@ -262,9 +262,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
const ns3::MyInterfaceId BaseB::iid =
|
||||
const ns3::InterfaceId BaseB::iid =
|
||||
ns3::MakeInterfaceId ("BaseB", Object::iid);
|
||||
const ns3::MyInterfaceId DerivedB::iid =
|
||||
const ns3::InterfaceId DerivedB::iid =
|
||||
ns3::MakeInterfaceId ("DerivedB", BaseB::iid);;
|
||||
|
||||
} // namespace anonymous
|
||||
|
||||
@@ -27,46 +27,46 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class MyInterfaceId
|
||||
class InterfaceId
|
||||
{
|
||||
public:
|
||||
static MyInterfaceId LookupByName (std::string name);
|
||||
static MyInterfaceId LookupParent (MyInterfaceId iid);
|
||||
~MyInterfaceId ();
|
||||
static InterfaceId LookupByName (std::string name);
|
||||
static InterfaceId LookupParent (InterfaceId iid);
|
||||
~InterfaceId ();
|
||||
private:
|
||||
MyInterfaceId (uint32_t iid);
|
||||
friend MyInterfaceId MakeInterfaceId (std::string name, const MyInterfaceId &parent);
|
||||
friend MyInterfaceId MakeObjectInterfaceId (void);
|
||||
friend bool operator == (const MyInterfaceId &a, const MyInterfaceId &b);
|
||||
friend bool operator != (const MyInterfaceId &a, const MyInterfaceId &b);
|
||||
InterfaceId (uint32_t iid);
|
||||
friend InterfaceId MakeInterfaceId (std::string name, const InterfaceId &parent);
|
||||
friend InterfaceId MakeObjectInterfaceId (void);
|
||||
friend bool operator == (const InterfaceId &a, const InterfaceId &b);
|
||||
friend bool operator != (const InterfaceId &a, const InterfaceId &b);
|
||||
uint32_t m_iid;
|
||||
};
|
||||
|
||||
MyInterfaceId
|
||||
MakeInterfaceId (std::string name, const MyInterfaceId &parent);
|
||||
InterfaceId
|
||||
MakeInterfaceId (std::string name, const InterfaceId &parent);
|
||||
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
static const MyInterfaceId iid;
|
||||
static const InterfaceId iid;
|
||||
|
||||
Object ();
|
||||
virtual ~Object ();
|
||||
inline void Ref (void) const;
|
||||
inline void Unref (void) const;
|
||||
template <typename T>
|
||||
Ptr<T> QueryInterface (MyInterfaceId iid);
|
||||
Ptr<T> QueryInterface (InterfaceId iid);
|
||||
void Dispose (void);
|
||||
void AddInterface (Ptr<Object> other);
|
||||
protected:
|
||||
void SetInterfaceId (MyInterfaceId iid);
|
||||
void SetInterfaceId (InterfaceId iid);
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
Ptr<Object> DoQueryInterface (MyInterfaceId iid);
|
||||
Ptr<Object> DoQueryInterface (InterfaceId iid);
|
||||
bool Check (void) const;
|
||||
void MaybeDelete (void) const;
|
||||
mutable uint32_t m_count;
|
||||
MyInterfaceId m_iid;
|
||||
InterfaceId m_iid;
|
||||
Object *m_next;
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ Object::Unref (void) const
|
||||
|
||||
template <typename T>
|
||||
Ptr<T>
|
||||
Object::QueryInterface (MyInterfaceId iid)
|
||||
Object::QueryInterface (InterfaceId iid)
|
||||
{
|
||||
Ptr<Object> found = DoQueryInterface (iid);
|
||||
if (found != 0)
|
||||
|
||||
Reference in New Issue
Block a user