make simulator implementation replaceable via global default value

This commit is contained in:
Craig Dowell
2008-07-18 21:51:31 -07:00
parent b1af5815b0
commit 9c8ee223b3
6 changed files with 230 additions and 93 deletions

View File

@@ -19,7 +19,7 @@
*/
#include "simulator.h"
#include "simulator-impl.h"
#include "default-simulator-impl.h"
#include "scheduler.h"
#include "event-impl.h"
@@ -30,23 +30,23 @@
#include <math.h>
NS_LOG_COMPONENT_DEFINE ("SimulatorImpl");
NS_LOG_COMPONENT_DEFINE ("DefaultSimulatorImpl");
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (SimulatorImpl);
NS_OBJECT_ENSURE_REGISTERED (DefaultSimulatorImpl);
TypeId
SimulatorImpl::GetTypeId (void)
DefaultSimulatorImpl::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::SimulatorImpl")
static TypeId tid = TypeId ("ns3::DefaultSimulatorImpl")
.SetParent<Object> ()
.AddConstructor<SimulatorImpl> ()
.AddConstructor<DefaultSimulatorImpl> ()
;
return tid;
}
SimulatorImpl::SimulatorImpl ()
DefaultSimulatorImpl::DefaultSimulatorImpl ()
{
m_stop = false;
m_stopAt = 0;
@@ -62,7 +62,7 @@ SimulatorImpl::SimulatorImpl ()
m_unscheduledEvents = 0;
}
SimulatorImpl::~SimulatorImpl ()
DefaultSimulatorImpl::~DefaultSimulatorImpl ()
{
while (!m_events->IsEmpty ())
{
@@ -72,7 +72,7 @@ SimulatorImpl::~SimulatorImpl ()
}
void
SimulatorImpl::Destroy ()
DefaultSimulatorImpl::Destroy ()
{
while (!m_destroyEvents.empty ())
{
@@ -87,7 +87,7 @@ SimulatorImpl::Destroy ()
}
void
SimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
DefaultSimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
{
if (m_events != 0)
{
@@ -101,20 +101,20 @@ SimulatorImpl::SetScheduler (Ptr<Scheduler> scheduler)
}
Ptr<Scheduler>
SimulatorImpl::GetScheduler (void) const
DefaultSimulatorImpl::GetScheduler (void) const
{
return m_events;
}
void
SimulatorImpl::EnableLogTo (char const *filename)
DefaultSimulatorImpl::EnableLogTo (char const *filename)
{
m_log.open (filename);
m_logEnable = true;
}
void
SimulatorImpl::ProcessOneEvent (void)
DefaultSimulatorImpl::ProcessOneEvent (void)
{
EventId next = m_events->RemoveNext ();
@@ -133,13 +133,13 @@ SimulatorImpl::ProcessOneEvent (void)
}
bool
SimulatorImpl::IsFinished (void) const
DefaultSimulatorImpl::IsFinished (void) const
{
return m_events->IsEmpty ();
}
uint64_t
SimulatorImpl::NextTs (void) const
DefaultSimulatorImpl::NextTs (void) const
{
NS_ASSERT (!m_events->IsEmpty ());
EventId id = m_events->PeekNext ();
@@ -147,13 +147,13 @@ SimulatorImpl::NextTs (void) const
}
Time
SimulatorImpl::Next (void) const
DefaultSimulatorImpl::Next (void) const
{
return TimeStep (NextTs ());
}
void
SimulatorImpl::Run (void)
DefaultSimulatorImpl::Run (void)
{
while (!m_events->IsEmpty () && !m_stop &&
@@ -170,13 +170,13 @@ SimulatorImpl::Run (void)
}
void
SimulatorImpl::Stop (void)
DefaultSimulatorImpl::Stop (void)
{
m_stop = true;
}
void
SimulatorImpl::Stop (Time const &time)
DefaultSimulatorImpl::Stop (Time const &time)
{
NS_ASSERT (time.IsPositive ());
Time absolute = Simulator::Now () + time;
@@ -184,7 +184,7 @@ SimulatorImpl::Stop (Time const &time)
}
EventId
SimulatorImpl::Schedule (Time const &time, const Ptr<EventImpl> &event)
DefaultSimulatorImpl::Schedule (Time const &time, const Ptr<EventImpl> &event)
{
NS_ASSERT (time.IsPositive ());
NS_ASSERT (time >= TimeStep (m_currentTs));
@@ -202,7 +202,7 @@ SimulatorImpl::Schedule (Time const &time, const Ptr<EventImpl> &event)
}
EventId
SimulatorImpl::ScheduleNow (const Ptr<EventImpl> &event)
DefaultSimulatorImpl::ScheduleNow (const Ptr<EventImpl> &event)
{
EventId id (event, m_currentTs, m_uid);
if (m_logEnable)
@@ -217,7 +217,7 @@ SimulatorImpl::ScheduleNow (const Ptr<EventImpl> &event)
}
EventId
SimulatorImpl::ScheduleDestroy (const Ptr<EventImpl> &event)
DefaultSimulatorImpl::ScheduleDestroy (const Ptr<EventImpl> &event)
{
EventId id (event, m_currentTs, 2);
m_destroyEvents.push_back (id);
@@ -231,13 +231,13 @@ SimulatorImpl::ScheduleDestroy (const Ptr<EventImpl> &event)
}
Time
SimulatorImpl::Now (void) const
DefaultSimulatorImpl::Now (void) const
{
return TimeStep (m_currentTs);
}
Time
SimulatorImpl::GetDelayLeft (const EventId &id) const
DefaultSimulatorImpl::GetDelayLeft (const EventId &id) const
{
if (IsExpired (id))
{
@@ -250,7 +250,7 @@ SimulatorImpl::GetDelayLeft (const EventId &id) const
}
void
SimulatorImpl::Remove (const EventId &ev)
DefaultSimulatorImpl::Remove (const EventId &ev)
{
if (ev.GetUid () == 2)
{
@@ -281,7 +281,7 @@ SimulatorImpl::Remove (const EventId &ev)
}
void
SimulatorImpl::Cancel (const EventId &id)
DefaultSimulatorImpl::Cancel (const EventId &id)
{
if (!IsExpired (id))
{
@@ -290,7 +290,7 @@ SimulatorImpl::Cancel (const EventId &id)
}
bool
SimulatorImpl::IsExpired (const EventId &ev) const
DefaultSimulatorImpl::IsExpired (const EventId &ev) const
{
if (ev.GetUid () == 2)
{
@@ -319,7 +319,7 @@ SimulatorImpl::IsExpired (const EventId &ev) const
}
Time
SimulatorImpl::GetMaximumSimulationTime (void) const
DefaultSimulatorImpl::GetMaximumSimulationTime (void) const
{
// XXX: I am fairly certain other compilers use other non-standard
// post-fixes to indicate 64 bit constants.

View File

@@ -0,0 +1,90 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2005,2006 INRIA
*
* 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 <mathieu.lacage@sophia.inria.fr>
*/
#ifndef DEFAULT_SIMULATOR_IMPL_H
#define DEFAULT_SIMULATOR_IMPL_H
#include "simulator-impl.h"
#include "scheduler.h"
#include "event-impl.h"
#include "ns3/ptr.h"
#include "ns3/assert.h"
#include "ns3/log.h"
#include <list>
#include <fstream>
namespace ns3 {
class DefaultSimulatorImpl : public SimulatorImpl
{
public:
static TypeId GetTypeId (void);
DefaultSimulatorImpl ();
~DefaultSimulatorImpl ();
void Destroy ();
void EnableLogTo (char const *filename);
bool IsFinished (void) const;
Time Next (void) const;
void Stop (void);
void Stop (Time const &time);
EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
EventId ScheduleNow (const Ptr<EventImpl> &event);
EventId ScheduleDestroy (const Ptr<EventImpl> &event);
void Remove (const EventId &ev);
void Cancel (const EventId &ev);
bool IsExpired (const EventId &ev) const;
void Run (void);
Time Now (void) const;
Time GetDelayLeft (const EventId &id) const;
Time GetMaximumSimulationTime (void) const;
void SetScheduler (Ptr<Scheduler> scheduler);
Ptr<Scheduler> GetScheduler (void) const;
private:
void ProcessOneEvent (void);
uint64_t NextTs (void) const;
typedef std::list<EventId> DestroyEvents;
DestroyEvents m_destroyEvents;
uint64_t m_stopAt;
bool m_stop;
Ptr<Scheduler> m_events;
uint32_t m_uid;
uint32_t m_currentUid;
uint64_t m_currentTs;
std::ofstream m_log;
std::ifstream m_inputLog;
bool m_logEnable;
// number of events that have been inserted but not yet scheduled,
// not counting the "destroy" events; this is used for validation
int m_unscheduledEvents;
};
} // namespace ns3
#endif /* DEFAULT_SIMULATOR_IMPL_H */

View File

@@ -23,6 +23,7 @@
#include "scheduler.h"
#include "event-impl.h"
#include "nstime.h"
#include "ns3/ptr.h"
#include "ns3/assert.h"
@@ -36,51 +37,24 @@ namespace ns3 {
class SimulatorImpl : public Object
{
public:
static TypeId GetTypeId (void);
SimulatorImpl ();
~SimulatorImpl ();
void Destroy ();
void EnableLogTo (char const *filename);
bool IsFinished (void) const;
Time Next (void) const;
void Stop (void);
void Stop (Time const &time);
EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
EventId ScheduleNow (const Ptr<EventImpl> &event);
EventId ScheduleDestroy (const Ptr<EventImpl> &event);
void Remove (const EventId &ev);
void Cancel (const EventId &ev);
bool IsExpired (const EventId &ev) const;
void Run (void);
Time Now (void) const;
Time GetDelayLeft (const EventId &id) const;
Time GetMaximumSimulationTime (void) const;
void SetScheduler (Ptr<Scheduler> scheduler);
Ptr<Scheduler> GetScheduler (void) const;
private:
void ProcessOneEvent (void);
uint64_t NextTs (void) const;
typedef std::list<EventId> DestroyEvents;
DestroyEvents m_destroyEvents;
uint64_t m_stopAt;
bool m_stop;
Ptr<Scheduler> m_events;
uint32_t m_uid;
uint32_t m_currentUid;
uint64_t m_currentTs;
std::ofstream m_log;
std::ifstream m_inputLog;
bool m_logEnable;
// number of events that have been inserted but not yet scheduled,
// not counting the "destroy" events; this is used for validation
int m_unscheduledEvents;
virtual void Destroy () = 0;
virtual void EnableLogTo (char const *filename) = 0;
virtual bool IsFinished (void) const = 0;
virtual Time Next (void) const = 0;
virtual void Stop (void) = 0;
virtual void Stop (Time const &time) = 0;
virtual EventId Schedule (Time const &time, const Ptr<EventImpl> &event) = 0;
virtual EventId ScheduleNow (const Ptr<EventImpl> &event) = 0;
virtual EventId ScheduleDestroy (const Ptr<EventImpl> &event) = 0;
virtual void Remove (const EventId &ev) = 0;
virtual void Cancel (const EventId &ev) = 0;
virtual bool IsExpired (const EventId &ev) const = 0;
virtual void Run (void) = 0;
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 Ptr<Scheduler> GetScheduler (void) const = 0;
};
} // namespace ns3

View File

@@ -20,12 +20,15 @@
#include "simulator.h"
#include "simulator-impl.h"
#include "default-simulator-impl.h"
#include "scheduler.h"
#include "map-scheduler.h"
#include "event-impl.h"
#include "ns3/ptr.h"
#include "ns3/pointer.h"
#include "ns3/string.h"
#include "ns3/object-factory.h"
#include "ns3/global-value.h"
#include "ns3/assert.h"
#include "ns3/log.h"
@@ -39,38 +42,56 @@ NS_LOG_COMPONENT_DEFINE ("Simulator");
namespace ns3 {
GlobalValue g_simTypeImpl = GlobalValue ("SimulatorImplementationType",
"The object class to use as the simulator implementation",
StringValue ("ns3::DefaultSimulatorImpl"),
MakeStringChecker ());
Ptr<SimulatorImpl> Simulator::m_impl = 0;
#ifdef NS3_LOG_ENABLE
//
// Note: Calls that take TimePrinter as a parameter are defined as nothing
// in the logging module if NS3_LOG_ENABLE is not defined.
//
static void
TimePrinter (std::ostream &os)
{
os << Simulator::Now ();
}
#endif /* NS3_LOG_ENABLE */
Ptr<SimulatorImpl> Simulator::m_impl = 0;
Ptr<SimulatorImpl>
SimulatorImpl *
Simulator::GetImpl (void)
{
NS_LOG_FUNCTION_NOARGS ();
if (m_impl == 0)
{
/* Note: we call LogSetTimePrinter below _after_ calling CreateObject
* because CreateObject can trigger calls to the logging framework which
* would call the TimePrinter function above which would call
* Simulator::Now which would call Simulator::GetImpl, and, thus, get
* us in an infinite recursion until the stack explodes.
*/
m_impl = CreateObject<SimulatorImpl> ();
ObjectFactory factory;
StringValue s;
g_simTypeImpl.GetValue (s);
factory.SetTypeId (s.Get ());
m_impl = factory.Create<SimulatorImpl> ();
Ptr<Scheduler> scheduler = CreateObject<MapScheduler> ();
m_impl->SetScheduler (scheduler);
//
// Note: we call LogSetTimePrinter _after_ creating the implementation
// object because the act of creation can trigger calls to the logging
// framework which would call the TimePrinter function which would call
// Simulator::Now which would call Simulator::GetImpl, and, thus, get us
// in an infinite recursion until the stack explodes.
//
LogSetTimePrinter (&TimePrinter);
}
NS_LOG_LOGIC ("priv " << m_impl);
return m_impl;
return PeekPointer (m_impl);
}
void

View File

@@ -21,18 +21,19 @@
#ifndef SIMULATOR_H
#define SIMULATOR_H
#include <stdint.h>
#include "event-id.h"
#include "event-impl.h"
#include "nstime.h"
#include "scheduler.h"
#include "ns3/type-traits.h"
#include <stdint.h>
#include <string>
namespace ns3 {
class SimulatorImpl;
class SchedulerFactory;
/**
* \ingroup simulator
@@ -55,6 +56,20 @@ class SchedulerFactory;
class Simulator
{
public:
/**
* \param impl a new simulator implementation
*
* The simulator provides a mechanism to swap out different implementations.
* For example, the default implementation is a single-threaded simulator
* that performs no realtime synchronization. By calling this method, you
* can substitute in a new simulator implementation that might be multi-
* threaded and synchronize events to a realtime clock.
*
* The simulator implementation can be set when the simulator is not
* running.
*/
static void SetImplementation (Ptr<SimulatorImpl> impl);
/**
* \param scheduler a new event scheduler
*
@@ -91,7 +106,6 @@ public:
*/
static void Destroy (void);
/**
* If there any any events lefts to be scheduled, return
* true. Return false otherwise.
@@ -113,12 +127,14 @@ public:
* is greater than or equal to the stop time.
*/
static void Run (void);
/**
* If an event invokes this method, it will be the last
* event scheduled by the Simulator::run method before
* returning to the caller.
*/
static void Stop (void);
/**
* Force the Simulator::run method to return to the caller when the
* expiration time of the next event to be processed is greater than
@@ -140,6 +156,7 @@ public:
*/
template <typename MEM, typename OBJ>
static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj);
/**
* @param time the relative expiration time of the event.
* @param mem_ptr member method pointer to invoke
@@ -149,6 +166,7 @@ public:
*/
template <typename MEM, typename OBJ, typename T1>
static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
/**
* @param time the relative expiration time of the event.
* @param mem_ptr member method pointer to invoke
@@ -159,6 +177,7 @@ public:
*/
template <typename MEM, typename OBJ, typename T1, typename T2>
static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
/**
* @param time the relative expiration time of the event.
* @param mem_ptr member method pointer to invoke
@@ -171,6 +190,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2, typename T3>
static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
/**
* @param time the relative expiration time of the event.
* @param mem_ptr member method pointer to invoke
@@ -184,6 +204,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2, typename T3, typename T4>
static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param time the relative expiration time of the event.
* @param mem_ptr member method pointer to invoke
@@ -205,6 +226,7 @@ public:
* @returns an id for the scheduled event.
*/
static EventId Schedule (Time const &time, void (*f) (void));
/**
* @param time the relative expiration time of the event.
* @param f the function to invoke
@@ -213,6 +235,7 @@ public:
*/
template <typename U1, typename T1>
static EventId Schedule (Time const &time, void (*f) (U1), T1 a1);
/**
* @param time the relative expiration time of the event.
* @param f the function to invoke
@@ -222,6 +245,7 @@ public:
*/
template <typename U1, typename U2, typename T1, typename T2>
static EventId Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2);
/**
* @param time the relative expiration time of the event.
* @param f the function to invoke
@@ -232,6 +256,7 @@ public:
*/
template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
static EventId Schedule (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
/**
* @param time the relative expiration time of the event.
* @param f the function to invoke
@@ -244,6 +269,7 @@ public:
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param time the relative expiration time of the event.
* @param f the function to invoke
@@ -258,7 +284,6 @@ public:
typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Schedule an event to expire Now. All events scheduled to
* to expire "Now" are scheduled FIFO, after all normal events
@@ -269,6 +294,7 @@ public:
*/
template <typename MEM, typename OBJ>
static EventId ScheduleNow (MEM mem_ptr, OBJ obj);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -277,6 +303,7 @@ public:
template <typename MEM, typename OBJ,
typename T1>
static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -286,6 +313,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2>
static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -296,6 +324,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2, typename T3>
static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -325,6 +354,7 @@ public:
* @param f the function to invoke
*/
static EventId ScheduleNow (void (*f) (void));
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -332,6 +362,7 @@ public:
template <typename U1,
typename T1>
static EventId ScheduleNow (void (*f) (U1), T1 a1);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -340,6 +371,7 @@ public:
template <typename U1, typename U2,
typename T1, typename T2>
static EventId ScheduleNow (void (*f) (U1,U2), T1 a1, T2 a2);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -349,6 +381,7 @@ public:
template <typename U1, typename U2, typename U3,
typename T1, typename T2, typename T3>
static EventId ScheduleNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -359,6 +392,7 @@ public:
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
static EventId ScheduleNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -371,7 +405,6 @@ public:
typename T1, typename T2, typename T3, typename T4, typename T5>
static EventId ScheduleNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
/**
* Schedule an event to expire at Destroy time. All events
* scheduled to expire at "Destroy" time are scheduled FIFO,
@@ -383,6 +416,7 @@ public:
*/
template <typename MEM, typename OBJ>
static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -391,6 +425,7 @@ public:
template <typename MEM, typename OBJ,
typename T1>
static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -400,6 +435,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2>
static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -410,6 +446,7 @@ public:
template <typename MEM, typename OBJ,
typename T1, typename T2, typename T3>
static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
/**
* @param mem_ptr member method pointer to invoke
* @param obj the object on which to invoke the member method
@@ -439,6 +476,7 @@ public:
* @param f the function to invoke
*/
static EventId ScheduleDestroy (void (*f) (void));
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -446,6 +484,7 @@ public:
template <typename U1,
typename T1>
static EventId ScheduleDestroy (void (*f) (U1), T1 a1);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -454,6 +493,7 @@ public:
template <typename U1, typename U2,
typename T1, typename T2>
static EventId ScheduleDestroy (void (*f) (U1,U2), T1 a1, T2 a2);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -463,6 +503,7 @@ public:
template <typename U1, typename U2, typename U3,
typename T1, typename T2, typename T3>
static EventId ScheduleDestroy (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -473,6 +514,7 @@ public:
template <typename U1, typename U2, typename U3, typename U4,
typename T1, typename T2, typename T3, typename T4>
static EventId ScheduleDestroy (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
/**
* @param f the function to invoke
* @param a1 the first argument to pass to the function to invoke
@@ -497,6 +539,7 @@ public:
* @param id the event to remove from the list of scheduled events.
*/
static void Remove (const EventId &id);
/**
* Set the cancel bit on this event: the event's associated function
* will not be invoked when it expires.
@@ -510,6 +553,7 @@ public:
* @param id the event to cancel
*/
static void Cancel (const EventId &id);
/**
* This method has O(1) complexity.
* Note that it is not possible to test for the expiration of
@@ -523,10 +567,12 @@ public:
* @returns true if the event has expired, false otherwise.
*/
static bool IsExpired (const EventId &id);
/**
* Return the "current simulation time".
*/
static Time Now (void);
/**
* \param id the event id to analyse
* \returns the delay left until the input event id expires.
@@ -542,6 +588,7 @@ public:
* The returned value will always be bigger than or equal to Simulator::Now.
*/
static Time GetMaximumSimulationTime (void);
/**
* \param time delay until the event expires
* \param event the event to schedule
@@ -551,6 +598,7 @@ public:
* to delegate events to their own subclass of the EventImpl base class.
*/
static EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
/**
* \param event the event to schedule
* \returns a unique identifier for the newly-scheduled event.
@@ -559,6 +607,7 @@ public:
* to delegate events to their own subclass of the EventImpl base class.
*/
static EventId ScheduleDestroy (const Ptr<EventImpl> &event);
/**
* \param event the event to schedule
* \returns a unique identifier for the newly-scheduled event.
@@ -606,8 +655,10 @@ private:
typename T1, typename T2, typename T3, typename T4, typename T5>
static Ptr<EventImpl> MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
static Ptr<SimulatorImpl> GetImpl (void);
static SimulatorImpl *GetImpl (void);
static Ptr<SimulatorImpl> m_impl;
static std::string m_typeImpl;
static std::string m_typeSched;
};
/**

View File

@@ -58,7 +58,7 @@ def build(bld):
'heap-scheduler.cc',
'event-impl.cc',
'simulator.cc',
'simulator-impl.cc',
'default-simulator-impl.cc',
'timer.cc',
'watchdog.cc',
]
@@ -72,6 +72,7 @@ def build(bld):
'event-impl.h',
'simulator.h',
'simulator-impl.h',
'default-simulator-impl.h',
'scheduler.h',
'list-scheduler.h',
'map-scheduler.h',