src/simulator/simulator.h
author Guillaume Seguin <guillaume@segu.in>
Thu Nov 12 13:19:35 2009 +0100 (2009-11-12)
changeset 5507 915abd2b907b
parent 4448 641b88d1e131
child 5521 37c6c83d4252
permissions -rw-r--r--
Simulator::SetScheduler now takes an ObjectFactory
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2005 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 
    21 #ifndef SIMULATOR_H
    22 #define SIMULATOR_H
    23 
    24 #include "event-id.h"
    25 #include "event-impl.h"
    26 #include "make-event.h"
    27 #include "nstime.h"
    28 
    29 #include "ns3/deprecated.h"
    30 #include "ns3/object-factory.h"
    31 
    32 #include <stdint.h>
    33 #include <string>
    34 
    35 namespace ns3 {
    36 
    37 class SimulatorImpl;
    38 class Scheduler;
    39 
    40 /**
    41  * \ingroup simulator
    42  *
    43  * \brief Control the scheduling of simulation events. 
    44  *
    45  * The internal simulation clock is maintained
    46  * as a 64-bit integer in a unit specified by the user
    47  * through the TimeStepPrecision::Set function. This means that it is
    48  * not possible to specify event expiration times with anything better
    49  * than this user-specified accuracy. Events whose expiration time is
    50  * the same modulo this accuracy are scheduled in FIFO order: the 
    51  * first event inserted in the scheduling queue is scheduled to 
    52  * expire first.
    53  * 
    54  * A simple example of how to use the Simulator class to schedule events
    55  * is shown below:
    56  * \include samples/main-simulator.cc
    57  */
    58 class Simulator 
    59 {
    60 public:
    61   /**
    62    * \param impl a new simulator implementation
    63    *
    64    * The simulator provides a mechanism to swap out different implementations.
    65    * For example, the default implementation is a single-threaded simulator
    66    * that performs no realtime synchronization.  By calling this method, you
    67    * can substitute in a new simulator implementation that might be multi-
    68    * threaded and synchronize events to a realtime clock.
    69    *
    70    * The simulator implementation can be set when the simulator is not 
    71    * running.
    72    */
    73   static void SetImplementation (Ptr<SimulatorImpl> impl);
    74 
    75   static Ptr<SimulatorImpl> GetImplementation (void);
    76 
    77   /**
    78    * \param scheduler a new event scheduler
    79    *
    80    * The event scheduler can be set at any time: the events scheduled
    81    * in the previous scheduler will be transfered to the new scheduler
    82    * before we start to use it.
    83    */
    84   static void SetScheduler (ObjectFactory schedulerFactory);
    85 
    86   /**
    87    * Every event scheduled by the Simulator::insertAtDestroy method is
    88    * invoked. Then, we ensure that any memory allocated by the 
    89    * Simulator is freed.
    90    * This method is typically invoked at the end of a simulation
    91    * to avoid false-positive reports by a leak checker.
    92    * After this method has been invoked, it is actually possible
    93    * to restart a new simulation with a set of calls to Simulator::run
    94    * and Simulator::insert_*.
    95    */
    96   static void Destroy (void);
    97 
    98   /**
    99    * If there are no more events lefts to be scheduled, or if simulation
   100    * time has already reached the "stop time" (see Simulator::Stop()),
   101    * return true. Return false otherwise.
   102    */
   103   static bool IsFinished (void);
   104   /**
   105    * If Simulator::isFinished returns true, the behavior of this
   106    * method is undefined. Otherwise, it returns the microsecond-based
   107    * time of the next event expected to be scheduled.
   108    */
   109   static Time Next (void);
   110 
   111   /**
   112    * Run the simulation until one of:
   113    *   - no events are present anymore
   114    *   - the user called Simulator::stop
   115    *   - the user called Simulator::stopAtUs and the
   116    *     expiration time of the next event to be processed
   117    *     is greater than or equal to the stop time.
   118    */
   119   static void Run (void);
   120 
   121   /**
   122    * Process only the next simulation event, then return immediately.
   123    */
   124   static void RunOneEvent (void);
   125 
   126   /**
   127    * If an event invokes this method, it will be the last
   128    * event scheduled by the Simulator::run method before
   129    * returning to the caller.
   130    */
   131   static void Stop (void);
   132 
   133   /**
   134    * Force the Simulator::run method to return to the caller when the
   135    * expiration time of the next event to be processed is greater than
   136    * or equal to the stop time.  The stop time is relative to the
   137    * current simulation time.
   138    * @param time the stop time, relative to the current time.
   139    */
   140   static void Stop (Time const &time);
   141 
   142   /**
   143    * Schedule an event to expire at the relative time "time"
   144    * is reached.  This can be thought of as scheduling an event
   145    * for the current simulation time plus the Time passed as a
   146    * parameter
   147    *
   148    * When the event expires (when it becomes due to be run), the 
   149    * input method will be invoked on the input object.  
   150    *
   151    * @param time the relative expiration time of the event.
   152    * @param mem_ptr member method pointer to invoke
   153    * @param obj the object on which to invoke the member method
   154    * @returns an id for the scheduled event.
   155    */
   156   template <typename MEM, typename OBJ>
   157   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj);
   158 
   159   /**
   160    * @param time the relative expiration time of the event.
   161    * @param mem_ptr member method pointer to invoke
   162    * @param obj the object on which to invoke the member method
   163    * @param a1 the first argument to pass to the invoked method
   164    * @returns an id for the scheduled event.
   165    */
   166   template <typename MEM, typename OBJ, typename T1>
   167   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
   168 
   169   /**
   170    * @param time the relative expiration time of the event.
   171    * @param mem_ptr member method pointer to invoke
   172    * @param obj the object on which to invoke the member method
   173    * @param a1 the first argument to pass to the invoked method
   174    * @param a2 the second argument to pass to the invoked method
   175    * @returns an id for the scheduled event.
   176    */
   177   template <typename MEM, typename OBJ, typename T1, typename T2>
   178   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
   179 
   180   /**
   181    * @param time the relative expiration time of the event.
   182    * @param mem_ptr member method pointer to invoke
   183    * @param obj the object on which to invoke the member method
   184    * @param a1 the first argument to pass to the invoked method
   185    * @param a2 the second argument to pass to the invoked method
   186    * @param a3 the third argument to pass to the invoked method
   187    * @returns an id for the scheduled event.
   188    */
   189   template <typename MEM, typename OBJ, 
   190             typename T1, typename T2, typename T3>
   191   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
   192 
   193   /**
   194    * @param time the relative expiration time of the event.
   195    * @param mem_ptr member method pointer to invoke
   196    * @param obj the object on which to invoke the member method
   197    * @param a1 the first argument to pass to the invoked method
   198    * @param a2 the second argument to pass to the invoked method
   199    * @param a3 the third argument to pass to the invoked method
   200    * @param a4 the fourth argument to pass to the invoked method
   201    * @returns an id for the scheduled event.
   202    */
   203   template <typename MEM, typename OBJ, 
   204             typename T1, typename T2, typename T3, typename T4>
   205   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
   206 
   207   /**
   208    * @param time the relative expiration time of the event.
   209    * @param mem_ptr member method pointer to invoke
   210    * @param obj the object on which to invoke the member method
   211    * @param a1 the first argument to pass to the invoked method
   212    * @param a2 the second argument to pass to the invoked method
   213    * @param a3 the third argument to pass to the invoked method
   214    * @param a4 the fourth argument to pass to the invoked method
   215    * @param a5 the fifth argument to pass to the invoked method
   216    * @returns an id for the scheduled event.
   217    */
   218   template <typename MEM, typename OBJ, 
   219             typename T1, typename T2, typename T3, typename T4, typename T5>
   220   static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, 
   221                            T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   222   /**
   223    * @param time the relative expiration time of the event.
   224    * @param f the function to invoke
   225    * @returns an id for the scheduled event.
   226    */
   227   static EventId Schedule (Time const &time, void (*f) (void));
   228 
   229   /**
   230    * @param time the relative expiration time of the event.
   231    * @param f the function to invoke
   232    * @param a1 the first argument to pass to the function to invoke
   233    * @returns an id for the scheduled event.
   234    */
   235   template <typename U1, typename T1>
   236   static EventId Schedule (Time const &time, void (*f) (U1), T1 a1);
   237 
   238   /**
   239    * @param time the relative expiration time of the event.
   240    * @param f the function to invoke
   241    * @param a1 the first argument to pass to the function to invoke
   242    * @param a2 the second argument to pass to the function to invoke
   243    * @returns an id for the scheduled event.
   244    */
   245   template <typename U1, typename U2, typename T1, typename T2>
   246   static EventId Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2);
   247 
   248   /**
   249    * @param time the relative expiration time of the event.
   250    * @param f the function to invoke
   251    * @param a1 the first argument to pass to the function to invoke
   252    * @param a2 the second argument to pass to the function to invoke
   253    * @param a3 the third argument to pass to the function to invoke
   254    * @returns an id for the scheduled event.
   255    */
   256   template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
   257   static EventId Schedule (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
   258 
   259   /**
   260    * @param time the relative expiration time of the event.
   261    * @param f the function to invoke
   262    * @param a1 the first argument to pass to the function to invoke
   263    * @param a2 the second argument to pass to the function to invoke
   264    * @param a3 the third argument to pass to the function to invoke
   265    * @param a4 the fourth argument to pass to the function to invoke
   266    * @returns an id for the scheduled event.
   267    */
   268   template <typename U1, typename U2, typename U3, typename U4, 
   269             typename T1, typename T2, typename T3, typename T4>
   270   static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
   271 
   272   /**
   273    * @param time the relative expiration time of the event.
   274    * @param f the function to invoke
   275    * @param a1 the first argument to pass to the function to invoke
   276    * @param a2 the second argument to pass to the function to invoke
   277    * @param a3 the third argument to pass to the function to invoke
   278    * @param a4 the fourth argument to pass to the function to invoke
   279    * @param a5 the fifth argument to pass to the function to invoke
   280    * @returns an id for the scheduled event.
   281    */
   282   template <typename U1, typename U2, typename U3, typename U4, typename U5,
   283             typename T1, typename T2, typename T3, typename T4, typename T5>
   284   static EventId Schedule (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   285 
   286   /**
   287    * Schedule an event to expire Now. All events scheduled to
   288    * to expire "Now" are scheduled FIFO, after all normal events
   289    * have expired. 
   290    *
   291    * @param mem_ptr member method pointer to invoke
   292    * @param obj the object on which to invoke the member method
   293    */
   294   template <typename MEM, typename OBJ>
   295   static EventId ScheduleNow (MEM mem_ptr, OBJ obj);
   296 
   297   /**
   298    * @param mem_ptr member method pointer to invoke
   299    * @param obj the object on which to invoke the member method
   300    * @param a1 the first argument to pass to the invoked method
   301    */
   302   template <typename MEM, typename OBJ, 
   303             typename T1>
   304   static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1);
   305 
   306   /**
   307    * @param mem_ptr member method pointer to invoke
   308    * @param obj the object on which to invoke the member method
   309    * @param a1 the first argument to pass to the invoked method
   310    * @param a2 the second argument to pass to the invoked method
   311    */
   312   template <typename MEM, typename OBJ, 
   313             typename T1, typename T2>
   314   static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
   315 
   316   /**
   317    * @param mem_ptr member method pointer to invoke
   318    * @param obj the object on which to invoke the member method
   319    * @param a1 the first argument to pass to the invoked method
   320    * @param a2 the second argument to pass to the invoked method
   321    * @param a3 the third argument to pass to the invoked method
   322    */
   323   template <typename MEM, typename OBJ, 
   324             typename T1, typename T2, typename T3>
   325   static EventId ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
   326 
   327   /**
   328    * @param mem_ptr member method pointer to invoke
   329    * @param obj the object on which to invoke the member method
   330    * @param a1 the first argument to pass to the invoked method
   331    * @param a2 the second argument to pass to the invoked method
   332    * @param a3 the third argument to pass to the invoked method
   333    * @param a4 the fourth argument to pass to the invoked method
   334    */
   335   template <typename MEM, typename OBJ, 
   336             typename T1, typename T2, typename T3, typename T4>
   337   static EventId ScheduleNow (MEM mem_ptr, OBJ obj, 
   338                               T1 a1, T2 a2, T3 a3, T4 a4);
   339   /**
   340    * @param mem_ptr member method pointer to invoke
   341    * @param obj the object on which to invoke the member method
   342    * @param a1 the first argument to pass to the invoked method
   343    * @param a2 the second argument to pass to the invoked method
   344    * @param a3 the third argument to pass to the invoked method
   345    * @param a4 the fourth argument to pass to the invoked method
   346    * @param a5 the fifth argument to pass to the invoked method
   347    */
   348   template <typename MEM, typename OBJ, 
   349             typename T1, typename T2, typename T3, typename T4, typename T5>
   350   static EventId ScheduleNow (MEM mem_ptr, OBJ obj, 
   351                               T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   352   /**
   353    * @param f the function to invoke
   354    */
   355   static EventId ScheduleNow (void (*f) (void));
   356 
   357   /**
   358    * @param f the function to invoke
   359    * @param a1 the first argument to pass to the function to invoke
   360    */
   361   template <typename U1,
   362             typename T1>
   363   static EventId ScheduleNow (void (*f) (U1), T1 a1);
   364 
   365   /**
   366    * @param f the function to invoke
   367    * @param a1 the first argument to pass to the function to invoke
   368    * @param a2 the second argument to pass to the function to invoke
   369    */
   370   template <typename U1, typename U2,
   371             typename T1, typename T2>
   372   static EventId ScheduleNow (void (*f) (U1,U2), T1 a1, T2 a2);
   373 
   374   /**
   375    * @param f the function to invoke
   376    * @param a1 the first argument to pass to the function to invoke
   377    * @param a2 the second argument to pass to the function to invoke
   378    * @param a3 the third argument to pass to the function to invoke
   379    */
   380   template <typename U1, typename U2, typename U3,
   381             typename T1, typename T2, typename T3>
   382   static EventId ScheduleNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
   383 
   384   /**
   385    * @param f the function to invoke
   386    * @param a1 the first argument to pass to the function to invoke
   387    * @param a2 the second argument to pass to the function to invoke
   388    * @param a3 the third argument to pass to the function to invoke
   389    * @param a4 the fourth argument to pass to the function to invoke
   390    */
   391   template <typename U1, typename U2, typename U3, typename U4,
   392             typename T1, typename T2, typename T3, typename T4>
   393   static EventId ScheduleNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
   394 
   395   /**
   396    * @param f the function to invoke
   397    * @param a1 the first argument to pass to the function to invoke
   398    * @param a2 the second argument to pass to the function to invoke
   399    * @param a3 the third argument to pass to the function to invoke
   400    * @param a4 the fourth argument to pass to the function to invoke
   401    * @param a5 the fifth argument to pass to the function to invoke
   402    */
   403   template <typename U1, typename U2, typename U3, typename U4, typename U5,
   404             typename T1, typename T2, typename T3, typename T4, typename T5>
   405   static EventId ScheduleNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   406 
   407   /**
   408    * Schedule an event to expire at Destroy time. All events 
   409    * scheduled to expire at "Destroy" time are scheduled FIFO, 
   410    * after all normal events have expired and only when 
   411    * Simulator::Destroy is invoked.
   412    *
   413    * @param mem_ptr member method pointer to invoke
   414    * @param obj the object on which to invoke the member method
   415    */
   416   template <typename MEM, typename OBJ>
   417   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj);
   418 
   419   /**
   420    * @param mem_ptr member method pointer to invoke
   421    * @param obj the object on which to invoke the member method
   422    * @param a1 the first argument to pass to the invoked method
   423    */
   424   template <typename MEM, typename OBJ, 
   425             typename T1>
   426   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1);
   427 
   428   /**
   429    * @param mem_ptr member method pointer to invoke
   430    * @param obj the object on which to invoke the member method
   431    * @param a1 the first argument to pass to the invoked method
   432    * @param a2 the second argument to pass to the invoked method
   433    */
   434   template <typename MEM, typename OBJ,
   435             typename T1, typename T2>
   436   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
   437 
   438   /**
   439    * @param mem_ptr member method pointer to invoke
   440    * @param obj the object on which to invoke the member method
   441    * @param a1 the first argument to pass to the invoked method
   442    * @param a2 the second argument to pass to the invoked method
   443    * @param a3 the third argument to pass to the invoked method
   444    */
   445   template <typename MEM, typename OBJ, 
   446             typename T1, typename T2, typename T3>
   447   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
   448 
   449   /**
   450    * @param mem_ptr member method pointer to invoke
   451    * @param obj the object on which to invoke the member method
   452    * @param a1 the first argument to pass to the invoked method
   453    * @param a2 the second argument to pass to the invoked method
   454    * @param a3 the third argument to pass to the invoked method
   455    * @param a4 the fourth argument to pass to the invoked method
   456    */
   457   template <typename MEM, typename OBJ, 
   458             typename T1, typename T2, typename T3, typename T4>
   459   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, 
   460                                   T1 a1, T2 a2, T3 a3, T4 a4);
   461   /**
   462    * @param mem_ptr member method pointer to invoke
   463    * @param obj the object on which to invoke the member method
   464    * @param a1 the first argument to pass to the invoked method
   465    * @param a2 the second argument to pass to the invoked method
   466    * @param a3 the third argument to pass to the invoked method
   467    * @param a4 the fourth argument to pass to the invoked method
   468    * @param a5 the fifth argument to pass to the invoked method
   469    */
   470   template <typename MEM, typename OBJ, 
   471             typename T1, typename T2, typename T3, typename T4, typename T5>
   472   static EventId ScheduleDestroy (MEM mem_ptr, OBJ obj, 
   473                                   T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   474   /**
   475    * @param f the function to invoke
   476    */
   477   static EventId ScheduleDestroy (void (*f) (void));
   478 
   479   /**
   480    * @param f the function to invoke
   481    * @param a1 the first argument to pass to the function to invoke
   482    */
   483   template <typename U1,
   484             typename T1>
   485   static EventId ScheduleDestroy (void (*f) (U1), T1 a1);
   486 
   487   /**
   488    * @param f the function to invoke
   489    * @param a1 the first argument to pass to the function to invoke
   490    * @param a2 the second argument to pass to the function to invoke
   491    */
   492   template <typename U1, typename U2,
   493             typename T1, typename T2>
   494   static EventId ScheduleDestroy (void (*f) (U1,U2), T1 a1, T2 a2);
   495 
   496   /**
   497    * @param f the function to invoke
   498    * @param a1 the first argument to pass to the function to invoke
   499    * @param a2 the second argument to pass to the function to invoke
   500    * @param a3 the third argument to pass to the function to invoke
   501    */
   502   template <typename U1, typename U2, typename U3,
   503             typename T1, typename T2, typename T3>
   504   static EventId ScheduleDestroy (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
   505 
   506   /**
   507    * @param f the function to invoke
   508    * @param a1 the first argument to pass to the function to invoke
   509    * @param a2 the second argument to pass to the function to invoke
   510    * @param a3 the third argument to pass to the function to invoke
   511    * @param a4 the fourth argument to pass to the function to invoke
   512    */
   513   template <typename U1, typename U2, typename U3, typename U4,
   514             typename T1, typename T2, typename T3, typename T4>
   515   static EventId ScheduleDestroy (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
   516 
   517   /**
   518    * @param f the function to invoke
   519    * @param a1 the first argument to pass to the function to invoke
   520    * @param a2 the second argument to pass to the function to invoke
   521    * @param a3 the third argument to pass to the function to invoke
   522    * @param a4 the fourth argument to pass to the function to invoke
   523    * @param a5 the fifth argument to pass to the function to invoke
   524    */
   525   template <typename U1, typename U2, typename U3, typename U4, typename U5,
   526             typename T1, typename T2, typename T3, typename T4, typename T5>
   527   static EventId ScheduleDestroy (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
   528 
   529   /**
   530    * Remove an event from the event list. 
   531    * This method has the same visible effect as the 
   532    * ns3::EventId::Cancel method
   533    * but its algorithmic complexity is much higher: it has often 
   534    * O(log(n)) complexity, sometimes O(n), sometimes worse.
   535    * Note that it is not possible to remove events which were scheduled
   536    * for the "destroy" time. Doing so will result in a program error (crash).
   537    *
   538    * @param id the event to remove from the list of scheduled events.
   539    */
   540   static void Remove (const EventId &id);
   541 
   542   /**
   543    * Set the cancel bit on this event: the event's associated function
   544    * will not be invoked when it expires. 
   545    * This method has the same visible effect as the 
   546    * ns3::Simulator::remove method but its algorithmic complexity is 
   547    * much lower: it has O(1) complexity.
   548    * This method has the exact same semantics as ns3::EventId::cancel.
   549    * Note that it is not possible to cancel events which were scheduled
   550    * for the "destroy" time. Doing so will result in a program error (crash).
   551    * 
   552    * @param id the event to cancel
   553    */
   554   static void Cancel (const EventId &id);
   555 
   556   /**
   557    * This method has O(1) complexity.
   558    * Note that it is not possible to test for the expiration of
   559    * events which were scheduled for the "destroy" time. Doing so
   560    * will result in a program error (crash).
   561    * An event is said to "expire" when it starts being scheduled
   562    * which means that if the code executed by the event calls
   563    * this function, it will get true.
   564    *
   565    * @param id the event to test for expiration
   566    * @returns true if the event has expired, false otherwise.
   567    */
   568   static bool IsExpired (const EventId &id);
   569 
   570   /**
   571    * Return the "current simulation time".
   572    */
   573   static Time Now (void);
   574 
   575   /**
   576    * \param id the event id to analyse
   577    * \returns the delay left until the input event id expires.
   578    *          if the event is not running, this method returns
   579    *          zero.
   580    */
   581   static Time GetDelayLeft (const EventId &id);
   582 
   583   /**
   584    * \returns the maximum simulation time at which an event 
   585    *          can be scheduled.
   586    *
   587    * The returned value will always be bigger than or equal to Simulator::Now.
   588    */
   589   static Time GetMaximumSimulationTime (void);
   590 
   591   /**
   592    * \param time delay until the event expires
   593    * \param event the event to schedule
   594    * \returns a unique identifier for the newly-scheduled event.
   595    *
   596    * This method will be typically used by language bindings
   597    * to delegate events to their own subclass of the EventImpl base class.
   598    */
   599   static EventId Schedule (Time const &time, const Ptr<EventImpl> &event);  
   600 
   601   /**
   602    * \param event the event to schedule
   603    * \returns a unique identifier for the newly-scheduled event.
   604    *
   605    * This method will be typically used by language bindings
   606    * to delegate events to their own subclass of the EventImpl base class.
   607    */
   608   static EventId ScheduleDestroy (const Ptr<EventImpl> &event);
   609 
   610   /**
   611    * \param event the event to schedule
   612    * \returns a unique identifier for the newly-scheduled event.
   613    *
   614    * This method will be typically used by language bindings
   615    * to delegate events to their own subclass of the EventImpl base class.
   616    */
   617   static EventId ScheduleNow (const Ptr<EventImpl> &event);
   618 private:
   619   Simulator ();
   620   ~Simulator ();
   621 
   622   static EventId DoSchedule (Time const &time, EventImpl *event);  
   623   static EventId DoScheduleNow (EventImpl *event);
   624   static EventId DoScheduleDestroy (EventImpl *event);
   625 };
   626 
   627 /**
   628  * \brief create an ns3::Time instance which contains the
   629  *        current simulation time.
   630  *
   631  * This is really a shortcut for the ns3::Simulator::Now method.
   632  * It is typically used as shown below to schedule an event
   633  * which expires at the absolute time "2 seconds":
   634  * \code
   635  * Simulator::Schedule (Seconds (2.0) - Now (), &my_function);
   636  * \endcode
   637  */
   638 Time Now (void);
   639 
   640 } // namespace ns3
   641 
   642 namespace ns3 {
   643 
   644 template <typename MEM, typename OBJ>
   645 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj) 
   646 {
   647   return DoSchedule (time, MakeEvent (mem_ptr, obj));
   648 }
   649 
   650 
   651 template <typename MEM, typename OBJ,
   652           typename T1>
   653 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) 
   654 {
   655   return DoSchedule (time, MakeEvent (mem_ptr, obj, a1));
   656 }
   657 
   658 template <typename MEM, typename OBJ, 
   659           typename T1, typename T2>
   660 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
   661 {
   662   return DoSchedule (time, MakeEvent (mem_ptr, obj, a1, a2));
   663 }
   664 
   665 template <typename MEM, typename OBJ,
   666           typename T1, typename T2, typename T3>
   667 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
   668 {
   669   return DoSchedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3));
   670 }
   671 
   672 template <typename MEM, typename OBJ, 
   673           typename T1, typename T2, typename T3, typename T4>
   674 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
   675 {
   676   return DoSchedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
   677 }
   678 
   679 template <typename MEM, typename OBJ, 
   680           typename T1, typename T2, typename T3, typename T4, typename T5>
   681 EventId Simulator::Schedule (Time const &time, MEM mem_ptr, OBJ obj, 
   682                              T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   683 {
   684   return DoSchedule (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
   685 }
   686 
   687 template <typename U1, typename T1>
   688 EventId Simulator::Schedule (Time const &time, void (*f) (U1), T1 a1) 
   689 {
   690   return DoSchedule (time, MakeEvent (f, a1));
   691 }
   692 
   693 template <typename U1, typename U2, 
   694           typename T1, typename T2>
   695 EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) 
   696 {
   697   return DoSchedule (time, MakeEvent (f, a1, a2));
   698 }
   699 
   700 template <typename U1, typename U2, typename U3,
   701           typename T1, typename T2, typename T3>
   702 EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
   703 {
   704   return DoSchedule (time, MakeEvent (f, a1, a2, a3));
   705 }
   706 
   707 template <typename U1, typename U2, typename U3, typename U4,
   708           typename T1, typename T2, typename T3, typename T4>
   709 EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
   710 {
   711   return DoSchedule (time, MakeEvent (f, a1, a2, a3, a4));
   712 }
   713 
   714 template <typename U1, typename U2, typename U3, typename U4, typename U5,
   715           typename T1, typename T2, typename T3, typename T4, typename T5>
   716 EventId Simulator::Schedule (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   717 {
   718   return DoSchedule (time, MakeEvent (f, a1, a2, a3, a4, a5));
   719 }
   720 
   721 
   722 
   723 
   724 template <typename MEM, typename OBJ>
   725 EventId
   726 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj) 
   727 {
   728   return DoScheduleNow (MakeEvent (mem_ptr, obj));
   729 }
   730 
   731 
   732 template <typename MEM, typename OBJ, 
   733           typename T1>
   734 EventId
   735 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1) 
   736 {
   737   return DoScheduleNow (MakeEvent (mem_ptr, obj, a1));
   738 }
   739 
   740 template <typename MEM, typename OBJ, 
   741           typename T1, typename T2>
   742 EventId
   743 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
   744 {
   745   return DoScheduleNow (MakeEvent (mem_ptr, obj, a1, a2));
   746 }
   747 
   748 template <typename MEM, typename OBJ, 
   749           typename T1, typename T2, typename T3>
   750 EventId
   751 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
   752 {
   753   return DoScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
   754 }
   755 
   756 template <typename MEM, typename OBJ, 
   757           typename T1, typename T2, typename T3, typename T4>
   758 EventId
   759 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
   760 {
   761   return DoScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
   762 }
   763 
   764 template <typename MEM, typename OBJ, 
   765           typename T1, typename T2, typename T3, typename T4, typename T5>
   766 EventId
   767 Simulator::ScheduleNow (MEM mem_ptr, OBJ obj, 
   768                         T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   769 {
   770   return DoScheduleNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
   771 }
   772 
   773 template <typename U1,
   774           typename T1>
   775 EventId
   776 Simulator::ScheduleNow (void (*f) (U1), T1 a1) 
   777 {
   778   return DoScheduleNow (MakeEvent (f, a1));
   779 }
   780 
   781 template <typename U1, typename U2,
   782           typename T1, typename T2>
   783 EventId
   784 Simulator::ScheduleNow (void (*f) (U1,U2), T1 a1, T2 a2) 
   785 {
   786   return DoScheduleNow (MakeEvent (f, a1, a2));
   787 }
   788 
   789 template <typename U1, typename U2, typename U3,
   790           typename T1, typename T2, typename T3>
   791 EventId
   792 Simulator::ScheduleNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
   793 {
   794   return DoScheduleNow (MakeEvent (f, a1, a2, a3));
   795 }
   796 
   797 template <typename U1, typename U2, typename U3, typename U4,
   798           typename T1, typename T2, typename T3, typename T4>
   799 EventId
   800 Simulator::ScheduleNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
   801 {
   802   return DoScheduleNow (MakeEvent (f, a1, a2, a3, a4));
   803 }
   804 
   805 template <typename U1, typename U2, typename U3, typename U4, typename U5,
   806           typename T1, typename T2, typename T3, typename T4, typename T5>
   807 EventId
   808 Simulator::ScheduleNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   809 {
   810   return DoScheduleNow (MakeEvent (f, a1, a2, a3, a4, a5));
   811 }
   812 
   813 
   814 
   815 template <typename MEM, typename OBJ>
   816 EventId
   817 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj) 
   818 {
   819   return DoScheduleDestroy (MakeEvent (mem_ptr, obj));
   820 }
   821 
   822 
   823 template <typename MEM, typename OBJ, 
   824           typename T1>
   825 EventId
   826 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1) 
   827 {
   828   return DoScheduleDestroy (MakeEvent (mem_ptr, obj, a1));
   829 }
   830 
   831 template <typename MEM, typename OBJ, 
   832           typename T1, typename T2>
   833 EventId
   834 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
   835 {
   836   return DoScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2));
   837 }
   838 
   839 template <typename MEM, typename OBJ, 
   840           typename T1, typename T2, typename T3>
   841 EventId
   842 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
   843 {
   844   return DoScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3));
   845 }
   846 
   847 template <typename MEM, typename OBJ,
   848           typename T1, typename T2, typename T3, typename T4>
   849 EventId
   850 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
   851 {
   852   return DoScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
   853 }
   854 
   855 template <typename MEM, typename OBJ, 
   856           typename T1, typename T2, typename T3, typename T4, typename T5>
   857 EventId
   858 Simulator::ScheduleDestroy (MEM mem_ptr, OBJ obj, 
   859                             T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   860 {
   861   return DoScheduleDestroy (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
   862 }
   863 
   864 template <typename U1,
   865           typename T1>
   866 EventId
   867 Simulator::ScheduleDestroy (void (*f) (U1), T1 a1) 
   868 {
   869   return DoScheduleDestroy (MakeEvent (f, a1));
   870 }
   871 
   872 template <typename U1, typename U2,
   873           typename T1, typename T2>
   874 EventId
   875 Simulator::ScheduleDestroy (void (*f) (U1,U2), T1 a1, T2 a2) 
   876 {
   877   return DoScheduleDestroy (MakeEvent (f, a1, a2));
   878 }
   879 
   880 template <typename U1, typename U2, typename U3,
   881           typename T1, typename T2, typename T3>
   882 EventId
   883 Simulator::ScheduleDestroy (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
   884 {
   885   return DoScheduleDestroy (MakeEvent (f, a1, a2, a3));
   886 }
   887 
   888 template <typename U1, typename U2, typename U3, typename U4,
   889           typename T1, typename T2, typename T3, typename T4>
   890 EventId
   891 Simulator::ScheduleDestroy (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
   892 {
   893   return DoScheduleDestroy (MakeEvent (f, a1, a2, a3, a4));
   894 }
   895 
   896 template <typename U1, typename U2, typename U3, typename U4, typename U5,
   897           typename T1, typename T2, typename T3, typename T4, typename T5>
   898 EventId
   899 Simulator::ScheduleDestroy (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
   900 {
   901   return DoScheduleDestroy (MakeEvent (f, a1, a2, a3, a4, a5));
   902 }
   903 
   904 } // namespace ns3
   905 
   906 #endif /* SIMULATOR_H */