sample code for component manager
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 25 May 2007 21:53:24 +0200
changeset 727 3bcec84f9f54
parent 726 5bdc2c399117
child 728 95c426b1cb60
sample code for component manager
SConstruct
samples/main-component-manager.cc
--- a/SConstruct	Fri May 25 21:47:59 2007 +0200
+++ b/SConstruct	Fri May 25 21:53:24 2007 +0200
@@ -434,6 +434,12 @@
 sample_object.add_deps(['core'])
 sample_object.add_source('main-object.cc')
 
+sample_component_manager = build.Ns3Module('sample-component-manager', 'samples')
+sample_component_manager.set_executable()
+ns3.add(sample_component_manager)
+sample_component_manager.add_deps(['core'])
+sample_component_manager.add_source('main-component-manager.cc')
+
 # examples
 example_simple_p2p = build.Ns3Module('simple-p2p', 'examples')
 example_simple_p2p.set_executable()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/samples/main-component-manager.cc	Fri May 25 21:53:24 2007 +0200
@@ -0,0 +1,38 @@
+#include "ns3/object.h"
+#include "ns3/component-manager.h"
+
+using namespace ns3;
+
+class AnObject : public Object
+{
+public:
+  static const InterfaceId iid;
+  static const ClassId cid;
+  AnObject (int a, double b);
+protected:
+  virtual void DoDispose (void);
+};
+
+const InterfaceId AnObject::iid = MakeInterfaceId ("AnObject", Object::iid);
+const ClassId AnObject::cid = MakeClassId<AnObject, int, double> ("AnObject", AnObject::iid);
+
+AnObject::AnObject (int a, double b)
+{
+  // enable our interface
+  SetInterfaceId (AnObject::iid);
+}
+void
+AnObject::DoDispose (void)
+{
+  // Do your work here.
+  // chain up
+  Object::DoDispose ();
+}
+
+
+int main (int argc, char *argv[])
+{
+  Ptr<AnObject> anObject = ComponentManager::Create<AnObject,int,double> (AnObject::cid, AnObject::iid, 10, 20.0);
+  NS_ASSERT (anObject != 0);
+  return 0;
+}