Simulator::SetScheduler now takes an ObjectFactory

This commit is contained in:
Guillaume Seguin
2009-11-12 13:19:35 +01:00
parent cdaa394512
commit 0289746207
9 changed files with 71 additions and 25 deletions

View File

@@ -61,6 +61,28 @@ can be found <a href="http://www.nsnam.org/bugzilla/show_bug.cgi?id=689">
here</a>.
</ul>
<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&lt;Scheduler&gt; sched = CreateObject&lt;ListScheduler&gt; ();
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>

View File

@@ -86,8 +86,10 @@ DefaultSimulatorImpl::Destroy ()
}
void
DefaultSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
DefaultSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
if (m_events != 0)
{
while (!m_events->IsEmpty ())

View File

@@ -56,7 +56,7 @@ public:
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);

View File

@@ -122,10 +122,12 @@ RealtimeSimulatorImpl::Destroy ()
}
void
RealtimeSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
RealtimeSimulatorImpl::SetScheduler (ObjectFactory schedulerFactory)
{
NS_LOG_FUNCTION_NOARGS ();
Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler> ();
{
CriticalSection cs (m_mutex);

View File

@@ -66,7 +66,7 @@ public:
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);

View File

@@ -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 @@ public:
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

View File

@@ -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_simTypeImpl = GlobalValue ("SimulatorImplementationType",
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 @@ static SimulatorImpl * GetImpl (void)
StringValue s;
g_schedTypeImpl.GetValue (s);
factory.SetTypeId (s.Get ());
impl->SetScheduler (factory.Create<Scheduler> ());
impl->SetScheduler (factory);
}
//
@@ -133,10 +134,10 @@ Simulator::Destroy (void)
}
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
@@ -302,7 +303,7 @@ Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
StringValue s;
g_schedTypeImpl.GetValue (s);
factory.SetTypeId (s.Get ());
impl->SetScheduler (factory.Create<Scheduler> ());
impl->SetScheduler (factory);
//
// Note: we call LogSetTimePrinter _after_ creating the implementation
// object because the act of creation can trigger calls to the logging
@@ -334,7 +335,7 @@ namespace ns3 {
class SimulatorEventsTestCase : public TestCase
{
public:
SimulatorEventsTestCase (Ptr<Scheduler> scheduler);
SimulatorEventsTestCase (ObjectFactory schedulerFactory);
virtual bool DoRun (void);
void A (int a);
void B (int b);
@@ -350,10 +351,13 @@ public:
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)
@@ -422,6 +426,8 @@ SimulatorEventsTestCase::DoRun (void)
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);
@@ -767,11 +773,18 @@ public:
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;

View File

@@ -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 @@ public:
* 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

View File

@@ -162,21 +162,26 @@ int main (int argc, char *argv[])
}
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)
{