move MakeEvent out of Simulator
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 15 Oct 2008 14:35:28 +0200
changeset 3809 5e007004402e
parent 3808 ace932ee6eef
child 3810 ca47c7015ea4
move MakeEvent out of Simulator
src/simulator/default-simulator-impl.cc
src/simulator/default-simulator-impl.h
src/simulator/make-event.cc
src/simulator/make-event.h
src/simulator/realtime-simulator-impl.cc
src/simulator/realtime-simulator-impl.h
src/simulator/realtime-simulator.h
src/simulator/simulator-impl.h
src/simulator/simulator.cc
src/simulator/simulator.h
src/simulator/wscript
--- a/src/simulator/default-simulator-impl.cc	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/default-simulator-impl.cc	Wed Oct 15 14:35:28 2008 +0200
@@ -320,6 +320,17 @@
   return TimeStep (0x7fffffffffffffffLL);
 }
 
+void 
+DefaultSimulatorImpl::ScheduleRealtime (Time const &time, EventImpl *event)
+{
+  NS_FATAL_ERROR ("not implemented");
+}
+void 
+DefaultSimulatorImpl::ScheduleRealtimeNow (EventImpl *event)
+{
+  NS_FATAL_ERROR ("not implemented");
+}
+
 } // namespace ns3
 
 
--- a/src/simulator/default-simulator-impl.h	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/default-simulator-impl.h	Wed Oct 15 14:35:28 2008 +0200
@@ -61,6 +61,8 @@
   virtual Time GetMaximumSimulationTime (void) const;
   virtual void SetScheduler (Ptr<Scheduler> scheduler);
   virtual Ptr<Scheduler> GetScheduler (void) const;
+  virtual void ScheduleRealtime (Time const &time, EventImpl *event);
+  virtual void ScheduleRealtimeNow (EventImpl *event);
 
 private:
   void ProcessOneEvent (void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/simulator/make-event.cc	Wed Oct 15 14:35:28 2008 +0200
@@ -0,0 +1,27 @@
+#include "make-event.h"
+
+namespace ns3 {
+
+EventImpl *MakeEvent (void (*f) (void))
+{
+  // zero arg version
+  class EventFunctionImpl0 : public EventImpl
+  {
+  public:
+    typedef void (*F)(void);
+      
+    EventFunctionImpl0 (F function) 
+      : m_function (function)
+    {}
+    virtual ~EventFunctionImpl0 () {}
+  protected:
+    virtual void Notify (void) { 
+      (*m_function) (); 
+    }
+  private:
+  	F m_function;
+  } *ev = new EventFunctionImpl0 (f);
+  return ev;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/simulator/make-event.h	Wed Oct 15 14:35:28 2008 +0200
@@ -0,0 +1,388 @@
+#ifndef MAKE_EVENT_H
+#define MAKE_EVENT_H
+
+namespace ns3 {
+
+class EventImpl;
+
+template <typename MEM, typename OBJ>
+EventImpl *MakeEvent (MEM mem_ptr, OBJ obj);
+
+template <typename MEM, typename OBJ, 
+          typename T1>
+EventImpl *MakeEvent (MEM mem_ptr, OBJ obj, T1 a1);
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3, typename T4>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3, typename T4, typename T5>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, 
+		       T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+
+EventImpl * MakeEvent (void (*f) (void));
+template <typename U1, 
+          typename T1>
+EventImpl * MakeEvent (void (*f) (U1), T1 a1);
+
+template <typename U1, typename U2, 
+          typename T1, typename T2>
+EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2);
+
+template <typename U1, typename U2, typename U3,
+          typename T1, typename T2, typename T3>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
+
+template <typename U1, typename U2, typename U3, typename U4,
+          typename T1, typename T2, typename T3, typename T4>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
+
+template <typename U1, typename U2, typename U3, typename U4, typename U5,
+          typename T1, typename T2, typename T3, typename T4, typename T5>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+
+} // namespace ns3
+
+/********************************************************************
+   Implementation of templates defined above
+ ********************************************************************/
+
+#include "event-impl.h"
+#include "ns3/type-traits.h"
+
+namespace ns3 {
+
+template <typename T>
+struct EventMemberImplObjTraits;
+
+template <typename T>
+struct EventMemberImplObjTraits<T *>
+{
+  static T &GetReference (T *p) {
+    return *p;
+  }
+};
+
+template <typename MEM, typename OBJ>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj) 
+{
+  // zero argument version
+  class EventMemberImpl0 : public EventImpl {
+  public:
+    EventMemberImpl0 (OBJ obj, MEM function) 
+      : m_obj (obj), 
+        m_function (function)
+    {}
+    virtual ~EventMemberImpl0 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (); 
+    }
+    OBJ m_obj;
+    MEM m_function;
+  } * ev = new EventMemberImpl0 (obj, mem_ptr);
+  return ev;
+}
+
+
+template <typename MEM, typename OBJ, 
+          typename T1>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
+{
+  // one argument version
+  class EventMemberImpl1 : public EventImpl {
+  public:
+    EventMemberImpl1 (OBJ obj, MEM function, T1 a1) 
+      : m_obj (obj), 
+        m_function (function),
+        m_a1 (a1)
+    {}
+  protected:
+    virtual ~EventMemberImpl1 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1);
+    }
+    OBJ m_obj;
+    MEM m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
+  return ev;
+}
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
+{
+  // two argument version
+  class EventMemberImpl2 : public EventImpl {
+  public:
+    EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2) 
+      : m_obj (obj), 
+        m_function (function),
+        m_a1 (a1),
+        m_a2 (a2)
+    { }
+  protected:
+    virtual ~EventMemberImpl2 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2);
+    }
+    OBJ m_obj;
+    MEM m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
+  return ev;
+}
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
+{
+  // three argument version
+  class EventMemberImpl3 : public EventImpl {
+  public:
+    EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3) 
+      : m_obj (obj), 
+        m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3)
+    { }
+  protected:
+    virtual ~EventMemberImpl3 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3);
+    }
+    OBJ m_obj;
+    MEM m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
+  return ev;
+}
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3, typename T4>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
+{
+  // four argument version
+  class EventMemberImpl4 : public EventImpl {
+  public:
+    EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4) 
+      : m_obj (obj), 
+        m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3),
+        m_a4 (a4)
+    { }
+  protected:
+    virtual ~EventMemberImpl4 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4);
+    }
+    OBJ m_obj;
+    MEM m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+    typename TypeTraits<T4>::ReferencedType m_a4;
+  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
+  return ev;
+}
+
+template <typename MEM, typename OBJ, 
+          typename T1, typename T2, typename T3, typename T4, typename T5>
+EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, 
+                                     T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+{
+  // five argument version
+  class EventMemberImpl5 : public EventImpl {
+  public:
+    EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+      : m_obj (obj), 
+        m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3),
+        m_a4 (a4),
+        m_a5 (a5)
+    { }
+  protected:
+    virtual ~EventMemberImpl5 () {}
+  private:
+    virtual void Notify (void) { 
+      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
+    }
+    OBJ m_obj;
+    MEM m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+    typename TypeTraits<T4>::ReferencedType m_a4;
+    typename TypeTraits<T5>::ReferencedType m_a5;
+  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
+  return ev;
+}
+
+template <typename U1, typename T1>
+EventImpl * MakeEvent (void (*f) (U1), T1 a1) 
+{
+  // one arg version
+  class EventFunctionImpl1 : public EventImpl {
+  public:
+    typedef void (*F)(U1);
+      
+    EventFunctionImpl1 (F function, T1 a1) 
+      : m_function (function),
+        m_a1 (a1)
+    { }
+  protected:
+    virtual ~EventFunctionImpl1 () {}
+  private:
+    virtual void Notify (void) { 
+      (*m_function) (m_a1);
+    }
+    F m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+  } *ev = new EventFunctionImpl1 (f, a1);
+  return ev;
+}
+
+template <typename U1, typename U2, typename T1, typename T2>
+EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2) 
+{
+  // two arg version
+  class EventFunctionImpl2 : public EventImpl {
+  public:
+    typedef void (*F)(U1, U2);
+      
+    EventFunctionImpl2 (F function, T1 a1, T2 a2) 
+      : m_function (function),
+        m_a1 (a1),
+        m_a2 (a2)
+    {}
+  protected:
+    virtual ~EventFunctionImpl2 () {}
+  private:
+    virtual void Notify (void) { 
+      (*m_function) (m_a1, m_a2);
+    }
+    F m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+  } *ev = new EventFunctionImpl2 (f, a1, a2);
+  return ev;
+}
+
+template <typename U1, typename U2, typename U3,
+          typename T1, typename T2, typename T3>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
+{
+  // three arg version
+  class EventFunctionImpl3 : public EventImpl {
+  public:
+    typedef void (*F)(U1, U2, U3);
+      
+    EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) 
+      : m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3)
+    { }
+  protected:
+    virtual ~EventFunctionImpl3 () {}
+  private:
+    virtual void Notify (void) { 
+      (*m_function) (m_a1, m_a2, m_a3);
+    }
+    F m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
+  return ev;
+}
+
+template <typename U1, typename U2, typename U3, typename U4,
+          typename T1, typename T2, typename T3, typename T4>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
+{
+  // four arg version
+  class EventFunctionImpl4 : public EventImpl {
+  public:
+    typedef void (*F)(U1, U2, U3, U4);
+      
+    EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) 
+      : m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3),
+        m_a4 (a4)
+    { }
+  protected:
+    virtual ~EventFunctionImpl4 () {}
+  private:
+    virtual void Notify (void) { 
+      (*m_function) (m_a1, m_a2, m_a3, m_a4);
+    }
+    F m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+    typename TypeTraits<T4>::ReferencedType m_a4;
+  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
+  return ev;
+}
+
+template <typename U1, typename U2, typename U3, typename U4, typename U5,
+          typename T1, typename T2, typename T3, typename T4, typename T5>
+EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+{
+  // five arg version
+  class EventFunctionImpl5 : public EventImpl {
+  public:
+    typedef void (*F)(U1,U2,U3,U4,U5);
+      
+    EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+      : m_function (function),
+        m_a1 (a1),
+        m_a2 (a2),
+        m_a3 (a3),
+        m_a4 (a4),
+        m_a5 (a5)
+    {}
+  protected:
+    virtual ~EventFunctionImpl5 () {}
+  private:
+    virtual void Notify (void) { 
+      (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
+    }
+    F m_function;
+    typename TypeTraits<T1>::ReferencedType m_a1;
+    typename TypeTraits<T2>::ReferencedType m_a2;
+    typename TypeTraits<T3>::ReferencedType m_a3;
+    typename TypeTraits<T4>::ReferencedType m_a4;
+    typename TypeTraits<T5>::ReferencedType m_a5;
+  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
+  return ev;
+}
+
+} // namespace ns3
+
+#endif /* MAKE_EVENT_H */
--- a/src/simulator/realtime-simulator-impl.cc	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/realtime-simulator-impl.cc	Wed Oct 15 14:35:28 2008 +0200
@@ -646,18 +646,19 @@
 //
 // Schedule an event for a _relative_ time in the future.
 //
-EventId
-RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, const Ptr<EventImpl> &impl)
+void
+RealtimeSimulatorImpl::ScheduleRealtime (Time const &time, EventImpl *impl)
 {
   NS_LOG_FUNCTION (time << impl);
 
-  Scheduler::Event ev;
+  
   {
     CriticalSection cs (m_mutex);
 
     uint64_t ts = m_synchronizer->GetCurrentRealtime () + time.GetTimeStep ();
     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
-    ev.impl = GetPointer (impl);
+    Scheduler::Event ev;
+    ev.impl = impl;
     ev.key.m_ts = ts;
     ev.key.m_uid = m_uid;
     m_uid++;
@@ -666,14 +667,12 @@
     m_synchronizer->Signal ();
   }
 
-  return EventId (impl, ev.key.m_ts, ev.key.m_uid);
 }
 
-EventId
-RealtimeSimulatorImpl::ScheduleRealtimeNow (const Ptr<EventImpl> &impl)
+void
+RealtimeSimulatorImpl::ScheduleRealtimeNow (EventImpl *impl)
 {
   NS_LOG_FUNCTION_NOARGS ();
-  Scheduler::Event ev;
   {
     CriticalSection cs (m_mutex);
 
@@ -683,7 +682,8 @@
     // 
     uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime () : m_currentTs;
     NS_ASSERT_MSG (ts >= m_currentTs, "RealtimeSimulatorImpl::ScheduleRealrimeNow(): schedule for time < m_currentTs");
-    ev.impl = GetPointer (impl);
+    Scheduler::Event ev;
+    ev.impl = impl;
     ev.key.m_ts = ts;
     ev.key.m_uid = m_uid;
     m_uid++;
@@ -691,8 +691,6 @@
     m_events->Insert (ev);
     m_synchronizer->Signal ();
   }
-
-  return EventId (impl, ev.key.m_ts, ev.key.m_uid);
 }
 
 Time
--- a/src/simulator/realtime-simulator-impl.h	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/realtime-simulator-impl.h	Wed Oct 15 14:35:28 2008 +0200
@@ -79,8 +79,9 @@
   virtual Time GetMaximumSimulationTime (void) const;
   virtual void SetScheduler (Ptr<Scheduler> scheduler);
   virtual Ptr<Scheduler> GetScheduler (void) const;
-  EventId ScheduleRealtime (Time const &time, const Ptr<EventImpl> &event);
-  EventId ScheduleRealtimeNow (const Ptr<EventImpl> &event);
+  virtual void ScheduleRealtime (Time const &time, EventImpl *event);
+  virtual void ScheduleRealtimeNow (EventImpl *event);
+
   Time RealtimeNow (void) const;
 
   void SetSynchronizationMode (RealtimeSimulatorImpl::SynchronizationMode mode);
--- a/src/simulator/realtime-simulator.h	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/realtime-simulator.h	Wed Oct 15 14:35:28 2008 +0200
@@ -20,7 +20,7 @@
 #define REALTIME_SIMULATOR_H
 
 #include "simulator.h"
-#include "realtime-simulator-impl.h"
+#include "make-event.h"
 
 namespace ns3 {
 
@@ -49,7 +49,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename MEM, typename OBJ>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj);
+  static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj);
 
   /**
    * @param time the relative expiration time of the event.
@@ -59,7 +59,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename MEM, typename OBJ, typename T1>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
+  static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
 
   /**
    * @param time the relative expiration time of the event.
@@ -70,7 +70,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename MEM, typename OBJ, typename T1, typename T2>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
+  static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
 
   /**
    * @param time the relative expiration time of the event.
@@ -83,7 +83,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
+  static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
 
   /**
    * @param time the relative expiration time of the event.
@@ -97,7 +97,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3, typename T4>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
+  static void ScheduleRealtime (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.
@@ -112,14 +112,14 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventId ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
+  static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
                            T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   /**
    * @param time the relative expiration time of the event.
    * @param f the function to invoke
    * @returns an id for the scheduled event.
    */
-  static EventId ScheduleRealtime (Time const &time, void (*f) (void));
+  static void ScheduleRealtime (Time const &time, void (*f) (void));
 
   /**
    * @param time the relative expiration time of the event.
@@ -128,7 +128,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename U1, typename T1>
-  static EventId ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1);
+  static void ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1);
 
   /**
    * @param time the relative expiration time of the event.
@@ -138,7 +138,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename U1, typename U2, typename T1, typename T2>
-  static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2);
+  static void ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2);
 
   /**
    * @param time the relative expiration time of the event.
@@ -149,7 +149,7 @@
    * @returns an id for the scheduled event.
    */
   template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
-  static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
+  static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
 
   /**
    * @param time the relative expiration time of the event.
@@ -162,7 +162,7 @@
    */
   template <typename U1, typename U2, typename U3, typename U4, 
             typename T1, typename T2, typename T3, typename T4>
-  static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
+  static void ScheduleRealtime (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.
@@ -176,7 +176,7 @@
    */
   template <typename U1, typename U2, typename U3, typename U4, typename U5,
             typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventId ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+  static void ScheduleRealtime (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
@@ -187,7 +187,7 @@
    * @param obj the object on which to invoke the member method
    */
   template <typename MEM, typename OBJ>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj);
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj);
 
   /**
    * @param mem_ptr member method pointer to invoke
@@ -196,7 +196,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1);
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1);
 
   /**
    * @param mem_ptr member method pointer to invoke
@@ -206,7 +206,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
 
   /**
    * @param mem_ptr member method pointer to invoke
@@ -217,7 +217,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
 
   /**
    * @param mem_ptr member method pointer to invoke
@@ -229,7 +229,7 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3, typename T4>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
                               T1 a1, T2 a2, T3 a3, T4 a4);
   /**
    * @param mem_ptr member method pointer to invoke
@@ -242,12 +242,12 @@
    */
   template <typename MEM, typename OBJ, 
             typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventId ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
+  static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
                               T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   /**
    * @param f the function to invoke
    */
-  static EventId ScheduleRealtimeNow (void (*f) (void));
+  static void ScheduleRealtimeNow (void (*f) (void));
 
   /**
    * @param f the function to invoke
@@ -255,7 +255,7 @@
    */
   template <typename U1,
             typename T1>
-  static EventId ScheduleRealtimeNow (void (*f) (U1), T1 a1);
+  static void ScheduleRealtimeNow (void (*f) (U1), T1 a1);
 
   /**
    * @param f the function to invoke
@@ -264,7 +264,7 @@
    */
   template <typename U1, typename U2,
             typename T1, typename T2>
-  static EventId ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2);
+  static void ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2);
 
   /**
    * @param f the function to invoke
@@ -274,7 +274,7 @@
    */
   template <typename U1, typename U2, typename U3,
             typename T1, typename T2, typename T3>
-  static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
+  static void ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
 
   /**
    * @param f the function to invoke
@@ -285,7 +285,7 @@
    */
   template <typename U1, typename U2, typename U3, typename U4,
             typename T1, typename T2, typename T3, typename T4>
-  static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
+  static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
 
   /**
    * @param f the function to invoke
@@ -297,177 +297,179 @@
    */
   template <typename U1, typename U2, typename U3, typename U4, typename U5,
             typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventId ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
+  static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
 
 private:
   RealtimeSimulator ();
   ~RealtimeSimulator ();
+  static void ScheduleRealtime (const Time &delay, EventImpl *impl);
+  static void ScheduleRealtimeNow (EventImpl *impl);
 };
 
 template <typename MEM, typename OBJ>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj) 
+void RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj));
 }
 
 template <typename MEM, typename OBJ,
           typename T1>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) 
+void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
+void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2));
 }
 
 template <typename MEM, typename OBJ,
           typename T1, typename T2, typename T3>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
+void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2, typename T3, typename T4>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
+void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2, typename T3, typename T4, typename T5>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
+void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
                              T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
+  return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
 }
 
 template <typename U1, typename T1>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1) 
+void RealtimeScheduleRealtime (Time const &time, void (*f) (U1), T1 a1) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (f, a1));
+  return ScheduleRealtime (time, MakeEvent (f, a1));
 }
 
 template <typename U1, typename U2, 
           typename T1, typename T2>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) 
+void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2));
+  return ScheduleRealtime (time, MakeEvent (f, a1, a2));
 }
 
 template <typename U1, typename U2, typename U3,
           typename T1, typename T2, typename T3>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
+void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3));
+  return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3));
 }
 
 template <typename U1, typename U2, typename U3, typename U4,
           typename T1, typename T2, typename T3, typename T4>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
+void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3, a4));
+  return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4));
 }
 
 template <typename U1, typename U2, typename U3, typename U4, typename U5,
           typename T1, typename T2, typename T3, typename T4, typename T5>
-EventId RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
 {
-  return ScheduleRealtime (time, Simulator::MakeEvent (f, a1, a2, a3, a4, a5));
+  return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4, a5));
 }
 
 template <typename MEM, typename OBJ>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj) 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1) 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2, typename T3>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2, typename T3, typename T4>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
 }
 
 template <typename MEM, typename OBJ, 
           typename T1, typename T2, typename T3, typename T4, typename T5>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
+void
+RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
                         T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
+  return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
 }
 
 template <typename U1,
           typename T1>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1), T1 a1) 
+void
+RealtimeScheduleRealtimeNow (void (*f) (U1), T1 a1) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1));
+  return ScheduleRealtimeNow (MakeEvent (f, a1));
 }
 
 template <typename U1, typename U2,
           typename T1, typename T2>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2) 
+void
+RealtimeScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2));
+  return ScheduleRealtimeNow (MakeEvent (f, a1, a2));
 }
 
 template <typename U1, typename U2, typename U3,
           typename T1, typename T2, typename T3>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
+void
+RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3));
+  return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3));
 }
 
 template <typename U1, typename U2, typename U3, typename U4,
           typename T1, typename T2, typename T3, typename T4>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
+void
+RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3, a4));
+  return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4));
 }
 
 template <typename U1, typename U2, typename U3, typename U4, typename U5,
           typename T1, typename T2, typename T3, typename T4, typename T5>
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
+void
+RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
 {
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f, a1, a2, a3, a4, a5));
+  return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4, a5));
 }
 
-}; // namespace ns3
+} // namespace ns3
 
 #endif /* REALTIME_SIMULATOR_H */
--- a/src/simulator/simulator-impl.h	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/simulator-impl.h	Wed Oct 15 14:35:28 2008 +0200
@@ -21,20 +21,16 @@
 #ifndef SIMULATOR_IMPL_H
 #define SIMULATOR_IMPL_H
 
-#include "scheduler.h"
 #include "event-impl.h"
 #include "event-id.h"
 #include "nstime.h"
-
+#include "ns3/object.h"
 #include "ns3/ptr.h"
-#include "ns3/assert.h"
-#include "ns3/log.h"
-
-#include <list>
-#include <fstream>
 
 namespace ns3 {
 
+class Scheduler;
+
 class SimulatorImpl : public Object
 {
 public:
@@ -56,6 +52,8 @@
   virtual Time GetMaximumSimulationTime (void) const = 0;
   virtual void SetScheduler (Ptr<Scheduler> scheduler) = 0;
   virtual Ptr<Scheduler> GetScheduler (void) const = 0;
+  virtual void ScheduleRealtime (Time const &time, EventImpl *event) = 0;
+  virtual void ScheduleRealtimeNow (EventImpl *event) = 0;
 };
 
 } // namespace ns3
--- a/src/simulator/simulator.cc	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/simulator.cc	Wed Oct 15 14:35:28 2008 +0200
@@ -49,8 +49,6 @@
   StringValue ("ns3::DefaultSimulatorImpl"),
   MakeStringChecker ());
 
-Ptr<SimulatorImpl> Simulator::m_impl = 0;
-
 #ifdef NS3_LOG_ENABLE
 
 //
@@ -66,23 +64,29 @@
 
 #endif /* NS3_LOG_ENABLE */
 
-SimulatorImpl *
-Simulator::GetImpl (void)
+static Ptr<SimulatorImpl> *PeekImpl (void)
 {
+  static Ptr<SimulatorImpl> impl = 0;
+  return &impl;
+}
+
+static SimulatorImpl * GetImpl (void)
+{
+  Ptr<SimulatorImpl> &impl = *PeekImpl ();
   /* Please, don't include any calls to logging macros in this function
    * or pay the price, that is, stack explosions.
    */
-  if (m_impl == 0) 
+  if (impl == 0) 
     {
       ObjectFactory factory;
       StringValue s;
 
       g_simTypeImpl.GetValue (s);
       factory.SetTypeId (s.Get ());
-      m_impl = factory.Create<SimulatorImpl> ();
+      impl = factory.Create<SimulatorImpl> ();
 
       Ptr<Scheduler> scheduler = CreateObject<MapScheduler> ();
-      m_impl->SetScheduler (scheduler);
+      impl->SetScheduler (scheduler);
 
 //
 // Note: we call LogSetTimePrinter _after_ creating the implementation
@@ -93,7 +97,7 @@
 //
       LogSetTimePrinter (&TimePrinter);
     }
-  return PeekPointer (m_impl);
+  return PeekPointer (impl);
 }
 
 void
@@ -101,7 +105,8 @@
 {
   NS_LOG_FUNCTION_NOARGS ();
 
-  if (m_impl == 0)
+  Ptr<SimulatorImpl> &impl = *PeekImpl (); 
+  if (impl == 0)
     {
       return;
     }
@@ -111,8 +116,8 @@
    * the stack explodes.
    */
   LogSetTimePrinter (0);
-  m_impl->Destroy ();
-  m_impl = 0;
+  impl->Destroy ();
+  impl = 0;
 }
 
 void
@@ -184,30 +189,6 @@
   return GetImpl ()->GetDelayLeft (id);
 }
 
-EventImpl *
-Simulator::MakeEvent (void (*f) (void))
-{
-  NS_LOG_FUNCTION (f);
-  // zero arg version
-  class EventFunctionImpl0 : public EventImpl
-  {
-  public:
-    typedef void (*F)(void);
-      
-    EventFunctionImpl0 (F function) 
-      : m_function (function)
-    {}
-    virtual ~EventFunctionImpl0 () {}
-  protected:
-    virtual void Notify (void) { 
-      (*m_function) (); 
-    }
-  private:
-  	F m_function;
-  } *ev = new EventFunctionImpl0 (f);
-  return ev;
-}
-
 EventId
 Simulator::Schedule (Time const &time, const Ptr<EventImpl> &ev)
 {
@@ -306,47 +287,33 @@
   NS_FATAL_ERROR ("TODO");
 }
 
-RealtimeSimulatorImpl *
-RealtimeSimulator::GetRealtimeImpl (void)
+
+void
+RealtimeSimulator::ScheduleRealtime (Time const &time, EventImpl *ev)
 {
-  RealtimeSimulatorImpl *impl = dynamic_cast<RealtimeSimulatorImpl *>(Simulator::GetImpl ());
-  NS_ASSERT_MSG (impl, 
-                 "RealtimeSimulator::GetImpl (): Underlying simulator implementation not realtime");
-  return impl;
-}
-
-Time
-RealtimeSimulator::RealtimeNow (void)
-{
-  return GetRealtimeImpl ()->RealtimeNow ();
+  NS_LOG_FUNCTION (time << ev);
+  return GetImpl ()->ScheduleRealtime (time, ev);
 }
 
-EventId
-RealtimeSimulator::ScheduleRealtime (Time const &time, const Ptr<EventImpl> &ev)
+void
+RealtimeSimulator::ScheduleRealtimeNow (EventImpl *ev)
 {
-  NS_LOG_FUNCTION (time << ev);
-  return GetRealtimeImpl ()->ScheduleRealtime (time, ev);
+  NS_LOG_FUNCTION (ev);
+  return GetImpl ()->ScheduleRealtimeNow (ev);
 }
 
-EventId
-RealtimeSimulator::ScheduleRealtimeNow (const Ptr<EventImpl> &ev)
-{
-  NS_LOG_FUNCTION (ev);
-  return GetRealtimeImpl ()->ScheduleRealtimeNow (ev);
-}
-
-EventId
+void
 RealtimeSimulator::ScheduleRealtime (Time const &time, void (*f) (void))
 {
   NS_LOG_FUNCTION (time << f);
-  return ScheduleRealtime (time, Simulator::MakeEvent (f));
+  return ScheduleRealtime (time, MakeEvent (f));
 }
 
-EventId
+void
 RealtimeSimulator::ScheduleRealtimeNow (void (*f) (void))
 {
   NS_LOG_FUNCTION (f);
-  return ScheduleRealtimeNow (Simulator::MakeEvent (f));
+  return ScheduleRealtimeNow (MakeEvent (f));
 }
 
 
--- a/src/simulator/simulator.h	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/simulator.h	Wed Oct 15 14:35:28 2008 +0200
@@ -23,9 +23,9 @@
 
 #include "event-id.h"
 #include "event-impl.h"
+#include "make-event.h"
 #include "nstime.h"
 
-#include "ns3/type-traits.h"
 #include "ns3/deprecated.h"
 
 #include <stdint.h>
@@ -56,8 +56,6 @@
  */
 class Simulator 
 {
-  friend class RealtimeSimulator;
-
 public:
   /**
    * \param impl a new simulator implementation
@@ -622,46 +620,6 @@
   static EventId DoSchedule (Time const &time, EventImpl *event);  
   static EventId DoScheduleNow (EventImpl *event);
   static EventId DoScheduleDestroy (EventImpl *event);
-
-  template <typename MEM, typename OBJ>
-  static EventImpl *MakeEvent (MEM mem_ptr, OBJ obj);
-  template <typename MEM, typename OBJ, 
-            typename T1>
-  static EventImpl *MakeEvent (MEM mem_ptr, OBJ obj, T1 a1);
-  template <typename MEM, typename OBJ, 
-            typename T1, typename T2>
-  static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
-  template <typename MEM, typename OBJ, 
-            typename T1, typename T2, typename T3>
-  static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
-  template <typename MEM, typename OBJ, 
-            typename T1, typename T2, typename T3, typename T4>
-  static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
-  template <typename MEM, typename OBJ, 
-            typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventImpl * MakeEvent (MEM mem_ptr, OBJ obj, 
-                                   T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
-  static EventImpl * MakeEvent (void (*f) (void));
-  template <typename U1, 
-            typename T1>
-  static EventImpl * MakeEvent (void (*f) (U1), T1 a1);
-  template <typename U1, typename U2, 
-            typename T1, typename T2>
-  static EventImpl * MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2);
-  template <typename U1, typename U2, typename U3,
-            typename T1, typename T2, typename T3>
-  static EventImpl * MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
-  template <typename U1, typename U2, typename U3, typename U4,
-            typename T1, typename T2, typename T3, typename T4>
-  static EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
-  template <typename U1, typename U2, typename U3, typename U4, typename U5,
-            typename T1, typename T2, typename T3, typename T4, typename T5>
-  static EventImpl * MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
-
-  static SimulatorImpl *GetImpl (void);
-  static Ptr<SimulatorImpl> m_impl;
-  static std::string m_typeImpl;
-  static std::string m_typeSched;
 };
 
 /**
@@ -679,335 +637,8 @@
 
 } // namespace ns3
 
-
-/********************************************************************
-   Implementation of templates defined above
- ********************************************************************/
-
 namespace ns3 {
 
-template <typename T>
-struct EventMemberImplObjTraits;
-
-template <typename T>
-struct EventMemberImplObjTraits<T *>
-{
-  static T &GetReference (T *p) {
-    return *p;
-  }
-};
-
-template <typename MEM, typename OBJ>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj) 
-{
-  // zero argument version
-  class EventMemberImpl0 : public EventImpl {
-  public:
-    EventMemberImpl0 (OBJ obj, MEM function) 
-      : m_obj (obj), 
-        m_function (function)
-    {}
-    virtual ~EventMemberImpl0 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (); 
-    }
-    OBJ m_obj;
-    MEM m_function;
-  } * ev = new EventMemberImpl0 (obj, mem_ptr);
-  return ev;
-}
-
-
-template <typename MEM, typename OBJ, 
-          typename T1>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1)
-{
-  // one argument version
-  class EventMemberImpl1 : public EventImpl {
-  public:
-    EventMemberImpl1 (OBJ obj, MEM function, T1 a1) 
-      : m_obj (obj), 
-        m_function (function),
-        m_a1 (a1)
-    {}
-  protected:
-    virtual ~EventMemberImpl1 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1);
-    }
-    OBJ m_obj;
-    MEM m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-  } *ev = new EventMemberImpl1 (obj, mem_ptr, a1);
-  return ev;
-}
-
-template <typename MEM, typename OBJ, 
-          typename T1, typename T2>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
-{
-  // two argument version
-  class EventMemberImpl2 : public EventImpl {
-  public:
-    EventMemberImpl2 (OBJ obj, MEM function, T1 a1, T2 a2) 
-      : m_obj (obj), 
-        m_function (function),
-        m_a1 (a1),
-        m_a2 (a2)
-    { }
-  protected:
-    virtual ~EventMemberImpl2 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2);
-    }
-    OBJ m_obj;
-    MEM m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-  } *ev = new EventMemberImpl2 (obj, mem_ptr, a1, a2);
-  return ev;
-}
-
-template <typename MEM, typename OBJ, 
-          typename T1, typename T2, typename T3>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
-{
-  // three argument version
-  class EventMemberImpl3 : public EventImpl {
-  public:
-    EventMemberImpl3 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3) 
-      : m_obj (obj), 
-        m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3)
-    { }
-  protected:
-    virtual ~EventMemberImpl3 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3);
-    }
-    OBJ m_obj;
-    MEM m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-  } *ev = new EventMemberImpl3 (obj, mem_ptr, a1, a2, a3);
-  return ev;
-}
-
-template <typename MEM, typename OBJ, 
-          typename T1, typename T2, typename T3, typename T4>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
-{
-  // four argument version
-  class EventMemberImpl4 : public EventImpl {
-  public:
-    EventMemberImpl4 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4) 
-      : m_obj (obj), 
-        m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3),
-        m_a4 (a4)
-    { }
-  protected:
-    virtual ~EventMemberImpl4 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4);
-    }
-    OBJ m_obj;
-    MEM m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-    typename TypeTraits<T4>::ReferencedType m_a4;
-  } *ev = new EventMemberImpl4 (obj, mem_ptr, a1, a2, a3, a4);
-  return ev;
-}
-
-template <typename MEM, typename OBJ, 
-          typename T1, typename T2, typename T3, typename T4, typename T5>
-EventImpl * Simulator::MakeEvent (MEM mem_ptr, OBJ obj, 
-                                     T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
-{
-  // five argument version
-  class EventMemberImpl5 : public EventImpl {
-  public:
-    EventMemberImpl5 (OBJ obj, MEM function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
-      : m_obj (obj), 
-        m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3),
-        m_a4 (a4),
-        m_a5 (a5)
-    { }
-  protected:
-    virtual ~EventMemberImpl5 () {}
-  private:
-    virtual void Notify (void) { 
-      (EventMemberImplObjTraits<OBJ>::GetReference (m_obj).*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
-    }
-    OBJ m_obj;
-    MEM m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-    typename TypeTraits<T4>::ReferencedType m_a4;
-    typename TypeTraits<T5>::ReferencedType m_a5;
-  } *ev = new EventMemberImpl5 (obj, mem_ptr, a1, a2, a3, a4, a5);
-  return ev;
-}
-
-template <typename U1, typename T1>
-EventImpl * Simulator::MakeEvent (void (*f) (U1), T1 a1) 
-{
-  // one arg version
-  class EventFunctionImpl1 : public EventImpl {
-  public:
-    typedef void (*F)(U1);
-      
-    EventFunctionImpl1 (F function, T1 a1) 
-      : m_function (function),
-        m_a1 (a1)
-    { }
-  protected:
-    virtual ~EventFunctionImpl1 () {}
-  private:
-    virtual void Notify (void) { 
-      (*m_function) (m_a1);
-    }
-    F m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-  } *ev = new EventFunctionImpl1 (f, a1);
-  return ev;
-}
-
-template <typename U1, typename U2, typename T1, typename T2>
-EventImpl * Simulator::MakeEvent (void (*f) (U1,U2), T1 a1, T2 a2) 
-{
-  // two arg version
-  class EventFunctionImpl2 : public EventImpl {
-  public:
-    typedef void (*F)(U1, U2);
-      
-    EventFunctionImpl2 (F function, T1 a1, T2 a2) 
-      : m_function (function),
-        m_a1 (a1),
-        m_a2 (a2)
-    {}
-  protected:
-    virtual ~EventFunctionImpl2 () {}
-  private:
-    virtual void Notify (void) { 
-      (*m_function) (m_a1, m_a2);
-    }
-    F m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-  } *ev = new EventFunctionImpl2 (f, a1, a2);
-  return ev;
-}
-
-template <typename U1, typename U2, typename U3,
-          typename T1, typename T2, typename T3>
-EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
-{
-  // three arg version
-  class EventFunctionImpl3 : public EventImpl {
-  public:
-    typedef void (*F)(U1, U2, U3);
-      
-    EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) 
-      : m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3)
-    { }
-  protected:
-    virtual ~EventFunctionImpl3 () {}
-  private:
-    virtual void Notify (void) { 
-      (*m_function) (m_a1, m_a2, m_a3);
-    }
-    F m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-  } *ev = new EventFunctionImpl3 (f, a1, a2, a3);
-  return ev;
-}
-
-template <typename U1, typename U2, typename U3, typename U4,
-          typename T1, typename T2, typename T3, typename T4>
-EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
-{
-  // four arg version
-  class EventFunctionImpl4 : public EventImpl {
-  public:
-    typedef void (*F)(U1, U2, U3, U4);
-      
-    EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) 
-      : m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3),
-        m_a4 (a4)
-    { }
-  protected:
-    virtual ~EventFunctionImpl4 () {}
-  private:
-    virtual void Notify (void) { 
-      (*m_function) (m_a1, m_a2, m_a3, m_a4);
-    }
-    F m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-    typename TypeTraits<T4>::ReferencedType m_a4;
-  } *ev = new EventFunctionImpl4 (f, a1, a2, a3, a4);
-  return ev;
-}
-
-template <typename U1, typename U2, typename U3, typename U4, typename U5,
-          typename T1, typename T2, typename T3, typename T4, typename T5>
-EventImpl * Simulator::MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
-{
-  // five arg version
-  class EventFunctionImpl5 : public EventImpl {
-  public:
-    typedef void (*F)(U1,U2,U3,U4,U5);
-      
-    EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
-      : m_function (function),
-        m_a1 (a1),
-        m_a2 (a2),
-        m_a3 (a3),
-        m_a4 (a4),
-        m_a5 (a5)
-    {}
-  protected:
-    virtual ~EventFunctionImpl5 () {}
-  private:
-    virtual void Notify (void) { 
-      (*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
-    }
-    F m_function;
-    typename TypeTraits<T1>::ReferencedType m_a1;
-    typename TypeTraits<T2>::ReferencedType m_a2;
-    typename TypeTraits<T3>::ReferencedType m_a3;
-    typename TypeTraits<T4>::ReferencedType m_a4;
-    typename TypeTraits<T5>::ReferencedType m_a5;
-  } *ev = new EventFunctionImpl5 (f, a1, a2, a3, a4, a5);
-  return ev;
-}
-
 template <typename MEM, typename OBJ>
 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj) 
 {
--- a/src/simulator/wscript	Wed Oct 15 13:35:49 2008 +0200
+++ b/src/simulator/wscript	Wed Oct 15 14:35:28 2008 +0200
@@ -65,6 +65,7 @@
         'timer.cc',
         'watchdog.cc',
         'synchronizer.cc',
+        'make-event.cc',
         ]
 
     headers = bld.create_obj('ns3header')
@@ -87,6 +88,7 @@
         'timer-impl.h',
         'watchdog.h',
         'synchronizer.h',
+        'make-event.h',
         ]
 
     env = bld.env_of_name('default')