hi,
Although minor (no users that I am aware of), this is an API break and
since I am not sure that this piece of the multithreading code guillaume
posted earlier did get a review ack, I decided to post this here for 2
or 3 days before committing it. Anyone has objections with the following
change ?
diff -r 5718e4171536 src/simulator/simulator.h
--- a/src/simulator/simulator.h Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/simulator.h Tue Nov 10 10:19:38 2009 +0100
- static void SetScheduler (Ptr<Scheduler> scheduler);
+ static void SetScheduler (ObjectFactory schedulerFactory);
Mathieu
[set-sched.patch]
diff -r 5718e4171536 CHANGES.html
--- a/CHANGES.html Tue Nov 10 07:45:32 2009 +0100
+++ b/CHANGES.html Tue Nov 10 10:19:38 2009 +0100
@@ -44,6 +44,28 @@
us a note on ns-developers mailing list. </p>
<hr>
+<h1>Changes from ns-3.6 to ns-3.7</h1>
+
+<h2>Changes to existing API:</h2>
+<ul>
+<li><b>Simulator::SetScheduler</b>: this method now takes an ObjectFactory
+instead of an object pointer directly. Existing callers can trivially be
+updated to use this new method.<br>
+Before:
+<pre>
+Ptr<Scheduler> sched = CreateObject<ListScheduler> ();
+Simulator::SetScheduler (sched);
+</pre>
+After:
+<pre>
+ObjectFactory sched;
+sched.SetTypeId ("ns3::ListScheduler");
+Simulator::SetScheduler (sched);
+</pre>
+
+</ul>
+
+<hr>
<h1>Changes from ns-3.5 to ns-3.6</h1>
<h2>Changes to build system:</h2>
diff -r 5718e4171536 src/simulator/default-simulator-impl.cc
--- a/src/simulator/default-simulator-impl.cc Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/default-simulator-impl.cc Tue Nov 10 10:19:38 2009 +0100
@@ -86,8 +86,10 @@
}
void
-DefaultSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
+DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
+ Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
+
if (m_events != 0)
{
while (!m_events->IsEmpty ())
diff -r 5718e4171536 src/simulator/default-simulator-impl.h
--- a/src/simulator/default-simulator-impl.h Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/default-simulator-impl.h Tue Nov 10 10:19:38 2009 +0100
@@ -56,7 +56,7 @@
virtual Time Now (void) const;
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
- virtual void SetScheduler (Ptr<Scheduler> scheduler);
+ virtual void SetScheduler (ObjectFactory schedulerFactory);
private:
void ProcessOneEvent (void);
diff -r 5718e4171536 src/simulator/realtime-simulator-impl.cc
--- a/src/simulator/realtime-simulator-impl.cc Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/realtime-simulator-impl.cc Tue Nov 10 10:19:38 2009 +0100
@@ -122,10 +122,12 @@
}
void
-RealtimeSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
+RealtimeSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
NS_LOG_FUNCTION_NOARGS ();
+ Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
+
{
CriticalSection cs (m_mutex);
diff -r 5718e4171536 src/simulator/realtime-simulator-impl.h
--- a/src/simulator/realtime-simulator-impl.h Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/realtime-simulator-impl.h Tue Nov 10 10:19:38 2009 +0100
@@ -66,7 +66,7 @@
virtual Time Now (void) const;
virtual Time GetDelayLeft (const EventId &id) const;
virtual Time GetMaximumSimulationTime (void) const;
- virtual void SetScheduler (Ptr<Scheduler> scheduler);
+ virtual void SetScheduler (ObjectFactory schedulerFactory);
void ScheduleRealtime (Time const &time, EventImpl *event);
void ScheduleRealtimeNow (EventImpl *event);
diff -r 5718e4171536 src/simulator/simulator-impl.h
--- a/src/simulator/simulator-impl.h Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/simulator-impl.h Tue Nov 10 10:19:38 2009 +0100
@@ -25,6 +25,7 @@
#include "event-id.h"
#include "nstime.h"
#include "ns3/object.h"
+#include "ns3/object-factory.h"
#include "ns3/ptr.h"
namespace ns3 {
@@ -49,7 +50,7 @@
virtual Time Now (void) const = 0;
virtual Time GetDelayLeft (const EventId &id) const = 0;
virtual Time GetMaximumSimulationTime (void) const = 0;
- virtual void SetScheduler (Ptr<Scheduler> scheduler) = 0;
+ virtual void SetScheduler (ObjectFactory schedulerFactory) = 0;
};
} // namespace ns3
diff -r 5718e4171536 src/simulator/simulator.cc
--- a/src/simulator/simulator.cc Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/simulator.cc Tue Nov 10 10:19:38 2009 +0100
@@ -25,6 +25,7 @@
# include "realtime-simulator-impl.h"
#endif
#include "scheduler.h"
+#include "map-scheduler.h"
#include "event-impl.h"
#include "ns3/ptr.h"
@@ -51,8 +52,8 @@
GlobalValue g_schedTypeImpl = GlobalValue ("SchedulerType",
"The object class to use as the scheduler implementation",
- StringValue ("ns3::MapScheduler"),
- MakeStringChecker ());
+ TypeIdValue (MapScheduler::GetTypeId ()),
+ MakeTypeIdChecker ());
#ifdef NS3_LOG_ENABLE
@@ -97,7 +98,7 @@
StringValue s;
g_schedTypeImpl.GetValue (s);
factory.SetTypeId (s.Get ());
- impl->SetScheduler (factory.Create<Scheduler> ());
+ impl->SetScheduler (factory);
}
//
@@ -133,10 +134,10 @@
}
void
-Simulator::SetScheduler (Ptr<Scheduler> scheduler)
+Simulator::SetScheduler (ObjectFactory schedulerFactory)
{
- NS_LOG_FUNCTION (scheduler);
- GetImpl ()->SetScheduler (scheduler);
+ NS_LOG_FUNCTION (schedulerFactory);
+ GetImpl ()->SetScheduler (schedulerFactory);
}
bool
@@ -328,7 +329,7 @@
class SimulatorEventsTestCase : public TestCase
{
public:
- SimulatorEventsTestCase (Ptr<Scheduler> scheduler);
+ SimulatorEventsTestCase (ObjectFactory schedulerFactory);
virtual bool DoRun (void);
void A (int a);
void B (int b);
@@ -344,10 +345,13 @@
EventId m_idC;
bool m_destroy;
EventId m_destroyId;
+ ObjectFactory m_schedulerFactory;
};
-SimulatorEventsTestCase::SimulatorEventsTestCase (Ptr<Scheduler> scheduler)
- : TestCase ("Check that basic event handling is working with " + scheduler->GetInstanceTypeId ().GetName ())
+SimulatorEventsTestCase::SimulatorEventsTestCase (ObjectFactory schedulerFactory)
+ : TestCase ("Check that basic event handling is working with " +
+ schedulerFactory.GetTypeId ().GetName ()),
+ m_schedulerFactory (schedulerFactory)
{}
uint64_t
SimulatorEventsTestCase::NowUs (void)
@@ -416,6 +420,8 @@
m_c = true;
m_d = false;
+ Simulator::SetScheduler (m_schedulerFactory);
+
EventId a = Simulator::Schedule (MicroSeconds (10), &SimulatorEventsTestCase::A, this, 1);
Simulator::Schedule (MicroSeconds (11), &SimulatorEventsTestCase::B, this, 2);
m_idC = Simulator::Schedule (MicroSeconds (12), &SimulatorEventsTestCase::C, this, 3);
@@ -761,11 +767,18 @@
SimulatorTestSuite ()
: TestSuite ("simulator")
{
- AddTestCase (new SimulatorEventsTestCase (CreateObject<ListScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<MapScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<HeapScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<CalendarScheduler> ()));
- AddTestCase (new SimulatorEventsTestCase (CreateObject<Ns2CalendarScheduler> ()));
+ ObjectFactory factory;
+ factory.SetTypeId (ListScheduler::GetTypeId ());
+
+ AddTestCase (new SimulatorEventsTestCase (factory));
+ factory.SetTypeId (MapScheduler::GetTypeId ());
+ AddTestCase (new SimulatorEventsTestCase (factory));
+ factory.SetTypeId (HeapScheduler::GetTypeId ());
+ AddTestCase (new SimulatorEventsTestCase (factory));
+ factory.SetTypeId (CalendarScheduler::GetTypeId ());
+ AddTestCase (new SimulatorEventsTestCase (factory));
+ factory.SetTypeId (Ns2CalendarScheduler::GetTypeId ());
+ AddTestCase (new SimulatorEventsTestCase (factory));
}
} g_simulatorTestSuite;
diff -r 5718e4171536 src/simulator/simulator.h
--- a/src/simulator/simulator.h Tue Nov 10 07:45:32 2009 +0100
+++ b/src/simulator/simulator.h Tue Nov 10 10:19:38 2009 +0100
@@ -27,6 +27,7 @@
#include "nstime.h"
#include "ns3/deprecated.h"
+#include "ns3/object-factory.h"
#include <stdint.h>
#include <string>
@@ -80,7 +81,7 @@
* in the previous scheduler will be transfered to the new scheduler
* before we start to use it.
*/
- static void SetScheduler (Ptr<Scheduler> scheduler);
+ static void SetScheduler (ObjectFactory schedulerFactory);
/**
* Every event scheduled by the Simulator::insertAtDestroy method is
diff -r 5718e4171536 utils/bench-simulator.cc
--- a/utils/bench-simulator.cc Tue Nov 10 07:45:32 2009 +0100
+++ b/utils/bench-simulator.cc Tue Nov 10 10:19:38 2009 +0100
@@ -162,21 +162,26 @@
}
while (argc > 0)
{
+ ObjectFactory factory;
if (strcmp ("--list", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<ListScheduler> ());
+ factory.SetTypeId ("ns3::ListScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--heap", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<HeapScheduler> ());
+ factory.SetTypeId ("ns3::HeapScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--map", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<MapScheduler> ());
+ factory.SetTypeId ("ns3::HeapScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--calendar", argv[0]) == 0)
{
- Simulator::SetScheduler (CreateObject<CalendarScheduler> ());
+ factory.SetTypeId ("ns3::CalendarScheduler");
+ Simulator::SetScheduler (factory);
}
else if (strcmp ("--debug", argv[0]) == 0)
{