src/simulator/realtime-simulator.h
changeset 3811 4eb8e926c6d7
parent 3810 ca47c7015ea4
child 3812 6cca59a0fca6
equal deleted inserted replaced
3810:ca47c7015ea4 3811:4eb8e926c6d7
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2008 University of Washington
       
     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 
       
    19 #ifndef REALTIME_SIMULATOR_H
       
    20 #define REALTIME_SIMULATOR_H
       
    21 
       
    22 #include "simulator.h"
       
    23 #include "make-event.h"
       
    24 
       
    25 namespace ns3 {
       
    26 
       
    27 /**
       
    28  * \ingroup simulator
       
    29  *
       
    30  * \brief Extension class to control the scheduling of real-time simulation 
       
    31  * events.  Intended to be used by threads driven by "external" system
       
    32  * events and will schedule events using the current real-time instead of 
       
    33  * the current simulation time.
       
    34  */
       
    35 class RealtimeSimulator 
       
    36 {
       
    37 public:
       
    38   /**
       
    39    * Schedule an event to expire at the relative real-time "time"
       
    40    * is reached.  This can be thought of as scheduling an event
       
    41    * for the current real-time plus the Time passed as a parameter
       
    42    *
       
    43    * When the event expires (when it becomes due to be run), the 
       
    44    * input method will be invoked on the input object.  
       
    45    *
       
    46    * @param time the relative expiration time of the event.
       
    47    * @param mem_ptr member method pointer to invoke
       
    48    * @param obj the object on which to invoke the member method
       
    49    * @returns an id for the scheduled event.
       
    50    */
       
    51   template <typename MEM, typename OBJ>
       
    52   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj);
       
    53 
       
    54   /**
       
    55    * @param time the relative expiration time of the event.
       
    56    * @param mem_ptr member method pointer to invoke
       
    57    * @param obj the object on which to invoke the member method
       
    58    * @param a1 the first argument to pass to the invoked method
       
    59    * @returns an id for the scheduled event.
       
    60    */
       
    61   template <typename MEM, typename OBJ, typename T1>
       
    62   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
       
    63 
       
    64   /**
       
    65    * @param time the relative expiration time of the event.
       
    66    * @param mem_ptr member method pointer to invoke
       
    67    * @param obj the object on which to invoke the member method
       
    68    * @param a1 the first argument to pass to the invoked method
       
    69    * @param a2 the second argument to pass to the invoked method
       
    70    * @returns an id for the scheduled event.
       
    71    */
       
    72   template <typename MEM, typename OBJ, typename T1, typename T2>
       
    73   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
       
    74 
       
    75   /**
       
    76    * @param time the relative expiration time of the event.
       
    77    * @param mem_ptr member method pointer to invoke
       
    78    * @param obj the object on which to invoke the member method
       
    79    * @param a1 the first argument to pass to the invoked method
       
    80    * @param a2 the second argument to pass to the invoked method
       
    81    * @param a3 the third argument to pass to the invoked method
       
    82    * @returns an id for the scheduled event.
       
    83    */
       
    84   template <typename MEM, typename OBJ, 
       
    85             typename T1, typename T2, typename T3>
       
    86   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
       
    87 
       
    88   /**
       
    89    * @param time the relative expiration time of the event.
       
    90    * @param mem_ptr member method pointer to invoke
       
    91    * @param obj the object on which to invoke the member method
       
    92    * @param a1 the first argument to pass to the invoked method
       
    93    * @param a2 the second argument to pass to the invoked method
       
    94    * @param a3 the third argument to pass to the invoked method
       
    95    * @param a4 the fourth argument to pass to the invoked method
       
    96    * @returns an id for the scheduled event.
       
    97    */
       
    98   template <typename MEM, typename OBJ, 
       
    99             typename T1, typename T2, typename T3, typename T4>
       
   100   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4);
       
   101 
       
   102   /**
       
   103    * @param time the relative expiration time of the event.
       
   104    * @param mem_ptr member method pointer to invoke
       
   105    * @param obj the object on which to invoke the member method
       
   106    * @param a1 the first argument to pass to the invoked method
       
   107    * @param a2 the second argument to pass to the invoked method
       
   108    * @param a3 the third argument to pass to the invoked method
       
   109    * @param a4 the fourth argument to pass to the invoked method
       
   110    * @param a5 the fifth argument to pass to the invoked method
       
   111    * @returns an id for the scheduled event.
       
   112    */
       
   113   template <typename MEM, typename OBJ, 
       
   114             typename T1, typename T2, typename T3, typename T4, typename T5>
       
   115   static void ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
       
   116                            T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   117   /**
       
   118    * @param time the relative expiration time of the event.
       
   119    * @param f the function to invoke
       
   120    * @returns an id for the scheduled event.
       
   121    */
       
   122   static void ScheduleRealtime (Time const &time, void (*f) (void));
       
   123 
       
   124   /**
       
   125    * @param time the relative expiration time of the event.
       
   126    * @param f the function to invoke
       
   127    * @param a1 the first argument to pass to the function to invoke
       
   128    * @returns an id for the scheduled event.
       
   129    */
       
   130   template <typename U1, typename T1>
       
   131   static void ScheduleRealtime (Time const &time, void (*f) (U1), T1 a1);
       
   132 
       
   133   /**
       
   134    * @param time the relative expiration time of the event.
       
   135    * @param f the function to invoke
       
   136    * @param a1 the first argument to pass to the function to invoke
       
   137    * @param a2 the second argument to pass to the function to invoke
       
   138    * @returns an id for the scheduled event.
       
   139    */
       
   140   template <typename U1, typename U2, typename T1, typename T2>
       
   141   static void ScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2);
       
   142 
       
   143   /**
       
   144    * @param time the relative expiration time of the event.
       
   145    * @param f the function to invoke
       
   146    * @param a1 the first argument to pass to the function to invoke
       
   147    * @param a2 the second argument to pass to the function to invoke
       
   148    * @param a3 the third argument to pass to the function to invoke
       
   149    * @returns an id for the scheduled event.
       
   150    */
       
   151   template <typename U1, typename U2, typename U3, typename T1, typename T2, typename T3>
       
   152   static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
       
   153 
       
   154   /**
       
   155    * @param time the relative expiration time of the event.
       
   156    * @param f the function to invoke
       
   157    * @param a1 the first argument to pass to the function to invoke
       
   158    * @param a2 the second argument to pass to the function to invoke
       
   159    * @param a3 the third argument to pass to the function to invoke
       
   160    * @param a4 the fourth argument to pass to the function to invoke
       
   161    * @returns an id for the scheduled event.
       
   162    */
       
   163   template <typename U1, typename U2, typename U3, typename U4, 
       
   164             typename T1, typename T2, typename T3, typename T4>
       
   165   static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
       
   166 
       
   167   /**
       
   168    * @param time the relative expiration time of the event.
       
   169    * @param f the function to invoke
       
   170    * @param a1 the first argument to pass to the function to invoke
       
   171    * @param a2 the second argument to pass to the function to invoke
       
   172    * @param a3 the third argument to pass to the function to invoke
       
   173    * @param a4 the fourth argument to pass to the function to invoke
       
   174    * @param a5 the fifth argument to pass to the function to invoke
       
   175    * @returns an id for the scheduled event.
       
   176    */
       
   177   template <typename U1, typename U2, typename U3, typename U4, typename U5,
       
   178             typename T1, typename T2, typename T3, typename T4, typename T5>
       
   179   static void ScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   180 
       
   181   /**
       
   182    * Schedule an event to expire Now. All events scheduled to
       
   183    * to expire "Now" are scheduled FIFO, after all normal events
       
   184    * have expired. 
       
   185    *
       
   186    * @param mem_ptr member method pointer to invoke
       
   187    * @param obj the object on which to invoke the member method
       
   188    */
       
   189   template <typename MEM, typename OBJ>
       
   190   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj);
       
   191 
       
   192   /**
       
   193    * @param mem_ptr member method pointer to invoke
       
   194    * @param obj the object on which to invoke the member method
       
   195    * @param a1 the first argument to pass to the invoked method
       
   196    */
       
   197   template <typename MEM, typename OBJ, 
       
   198             typename T1>
       
   199   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1);
       
   200 
       
   201   /**
       
   202    * @param mem_ptr member method pointer to invoke
       
   203    * @param obj the object on which to invoke the member method
       
   204    * @param a1 the first argument to pass to the invoked method
       
   205    * @param a2 the second argument to pass to the invoked method
       
   206    */
       
   207   template <typename MEM, typename OBJ, 
       
   208             typename T1, typename T2>
       
   209   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2);
       
   210 
       
   211   /**
       
   212    * @param mem_ptr member method pointer to invoke
       
   213    * @param obj the object on which to invoke the member method
       
   214    * @param a1 the first argument to pass to the invoked method
       
   215    * @param a2 the second argument to pass to the invoked method
       
   216    * @param a3 the third argument to pass to the invoked method
       
   217    */
       
   218   template <typename MEM, typename OBJ, 
       
   219             typename T1, typename T2, typename T3>
       
   220   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3);
       
   221 
       
   222   /**
       
   223    * @param mem_ptr member method pointer to invoke
       
   224    * @param obj the object on which to invoke the member method
       
   225    * @param a1 the first argument to pass to the invoked method
       
   226    * @param a2 the second argument to pass to the invoked method
       
   227    * @param a3 the third argument to pass to the invoked method
       
   228    * @param a4 the fourth argument to pass to the invoked method
       
   229    */
       
   230   template <typename MEM, typename OBJ, 
       
   231             typename T1, typename T2, typename T3, typename T4>
       
   232   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
       
   233                               T1 a1, T2 a2, T3 a3, T4 a4);
       
   234   /**
       
   235    * @param mem_ptr member method pointer to invoke
       
   236    * @param obj the object on which to invoke the member method
       
   237    * @param a1 the first argument to pass to the invoked method
       
   238    * @param a2 the second argument to pass to the invoked method
       
   239    * @param a3 the third argument to pass to the invoked method
       
   240    * @param a4 the fourth argument to pass to the invoked method
       
   241    * @param a5 the fifth argument to pass to the invoked method
       
   242    */
       
   243   template <typename MEM, typename OBJ, 
       
   244             typename T1, typename T2, typename T3, typename T4, typename T5>
       
   245   static void ScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
       
   246                               T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   247   /**
       
   248    * @param f the function to invoke
       
   249    */
       
   250   static void ScheduleRealtimeNow (void (*f) (void));
       
   251 
       
   252   /**
       
   253    * @param f the function to invoke
       
   254    * @param a1 the first argument to pass to the function to invoke
       
   255    */
       
   256   template <typename U1,
       
   257             typename T1>
       
   258   static void ScheduleRealtimeNow (void (*f) (U1), T1 a1);
       
   259 
       
   260   /**
       
   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    */
       
   265   template <typename U1, typename U2,
       
   266             typename T1, typename T2>
       
   267   static void ScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2);
       
   268 
       
   269   /**
       
   270    * @param f the function to invoke
       
   271    * @param a1 the first argument to pass to the function to invoke
       
   272    * @param a2 the second argument to pass to the function to invoke
       
   273    * @param a3 the third argument to pass to the function to invoke
       
   274    */
       
   275   template <typename U1, typename U2, typename U3,
       
   276             typename T1, typename T2, typename T3>
       
   277   static void ScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3);
       
   278 
       
   279   /**
       
   280    * @param f the function to invoke
       
   281    * @param a1 the first argument to pass to the function to invoke
       
   282    * @param a2 the second argument to pass to the function to invoke
       
   283    * @param a3 the third argument to pass to the function to invoke
       
   284    * @param a4 the fourth argument to pass to the function to invoke
       
   285    */
       
   286   template <typename U1, typename U2, typename U3, typename U4,
       
   287             typename T1, typename T2, typename T3, typename T4>
       
   288   static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4);
       
   289 
       
   290   /**
       
   291    * @param f the function to invoke
       
   292    * @param a1 the first argument to pass to the function to invoke
       
   293    * @param a2 the second argument to pass to the function to invoke
       
   294    * @param a3 the third argument to pass to the function to invoke
       
   295    * @param a4 the fourth argument to pass to the function to invoke
       
   296    * @param a5 the fifth argument to pass to the function to invoke
       
   297    */
       
   298   template <typename U1, typename U2, typename U3, typename U4, typename U5,
       
   299             typename T1, typename T2, typename T3, typename T4, typename T5>
       
   300   static void ScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
       
   301 
       
   302 private:
       
   303   RealtimeSimulator ();
       
   304   ~RealtimeSimulator ();
       
   305   static void ScheduleRealtime (const Time &delay, EventImpl *impl);
       
   306   static void ScheduleRealtimeNow (EventImpl *impl);
       
   307 };
       
   308 
       
   309 template <typename MEM, typename OBJ>
       
   310 void RealtimeSimulator::ScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj) 
       
   311 {
       
   312   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj));
       
   313 }
       
   314 
       
   315 template <typename MEM, typename OBJ,
       
   316           typename T1>
       
   317 void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1) 
       
   318 {
       
   319   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1));
       
   320 }
       
   321 
       
   322 template <typename MEM, typename OBJ, 
       
   323           typename T1, typename T2>
       
   324 void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2)
       
   325 {
       
   326   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2));
       
   327 }
       
   328 
       
   329 template <typename MEM, typename OBJ,
       
   330           typename T1, typename T2, typename T3>
       
   331 void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
       
   332 {
       
   333   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3));
       
   334 }
       
   335 
       
   336 template <typename MEM, typename OBJ, 
       
   337           typename T1, typename T2, typename T3, typename T4>
       
   338 void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
       
   339 {
       
   340   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
       
   341 }
       
   342 
       
   343 template <typename MEM, typename OBJ, 
       
   344           typename T1, typename T2, typename T3, typename T4, typename T5>
       
   345 void RealtimeScheduleRealtime (Time const &time, MEM mem_ptr, OBJ obj, 
       
   346                              T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
       
   347 {
       
   348   return ScheduleRealtime (time, MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
       
   349 }
       
   350 
       
   351 template <typename U1, typename T1>
       
   352 void RealtimeScheduleRealtime (Time const &time, void (*f) (U1), T1 a1) 
       
   353 {
       
   354   return ScheduleRealtime (time, MakeEvent (f, a1));
       
   355 }
       
   356 
       
   357 template <typename U1, typename U2, 
       
   358           typename T1, typename T2>
       
   359 void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2), T1 a1, T2 a2) 
       
   360 {
       
   361   return ScheduleRealtime (time, MakeEvent (f, a1, a2));
       
   362 }
       
   363 
       
   364 template <typename U1, typename U2, typename U3,
       
   365           typename T1, typename T2, typename T3>
       
   366 void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
       
   367 {
       
   368   return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3));
       
   369 }
       
   370 
       
   371 template <typename U1, typename U2, typename U3, typename U4,
       
   372           typename T1, typename T2, typename T3, typename T4>
       
   373 void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
       
   374 {
       
   375   return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4));
       
   376 }
       
   377 
       
   378 template <typename U1, typename U2, typename U3, typename U4, typename U5,
       
   379           typename T1, typename T2, typename T3, typename T4, typename T5>
       
   380 void RealtimeScheduleRealtime (Time const &time, void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
       
   381 {
       
   382   return ScheduleRealtime (time, MakeEvent (f, a1, a2, a3, a4, a5));
       
   383 }
       
   384 
       
   385 template <typename MEM, typename OBJ>
       
   386 void
       
   387 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj) 
       
   388 {
       
   389   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj));
       
   390 }
       
   391 
       
   392 template <typename MEM, typename OBJ, 
       
   393           typename T1>
       
   394 void
       
   395 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1) 
       
   396 {
       
   397   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1));
       
   398 }
       
   399 
       
   400 template <typename MEM, typename OBJ, 
       
   401           typename T1, typename T2>
       
   402 void
       
   403 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2) 
       
   404 {
       
   405   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2));
       
   406 }
       
   407 
       
   408 template <typename MEM, typename OBJ, 
       
   409           typename T1, typename T2, typename T3>
       
   410 void
       
   411 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3) 
       
   412 {
       
   413   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3));
       
   414 }
       
   415 
       
   416 template <typename MEM, typename OBJ, 
       
   417           typename T1, typename T2, typename T3, typename T4>
       
   418 void
       
   419 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, T1 a1, T2 a2, T3 a3, T4 a4) 
       
   420 {
       
   421   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4));
       
   422 }
       
   423 
       
   424 template <typename MEM, typename OBJ, 
       
   425           typename T1, typename T2, typename T3, typename T4, typename T5>
       
   426 void
       
   427 RealtimeScheduleRealtimeNow (MEM mem_ptr, OBJ obj, 
       
   428                         T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
       
   429 {
       
   430   return ScheduleRealtimeNow (MakeEvent (mem_ptr, obj, a1, a2, a3, a4, a5));
       
   431 }
       
   432 
       
   433 template <typename U1,
       
   434           typename T1>
       
   435 void
       
   436 RealtimeScheduleRealtimeNow (void (*f) (U1), T1 a1) 
       
   437 {
       
   438   return ScheduleRealtimeNow (MakeEvent (f, a1));
       
   439 }
       
   440 
       
   441 template <typename U1, typename U2,
       
   442           typename T1, typename T2>
       
   443 void
       
   444 RealtimeScheduleRealtimeNow (void (*f) (U1,U2), T1 a1, T2 a2) 
       
   445 {
       
   446   return ScheduleRealtimeNow (MakeEvent (f, a1, a2));
       
   447 }
       
   448 
       
   449 template <typename U1, typename U2, typename U3,
       
   450           typename T1, typename T2, typename T3>
       
   451 void
       
   452 RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3), T1 a1, T2 a2, T3 a3)
       
   453 {
       
   454   return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3));
       
   455 }
       
   456 
       
   457 template <typename U1, typename U2, typename U3, typename U4,
       
   458           typename T1, typename T2, typename T3, typename T4>
       
   459 void
       
   460 RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4), T1 a1, T2 a2, T3 a3, T4 a4) 
       
   461 {
       
   462   return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4));
       
   463 }
       
   464 
       
   465 template <typename U1, typename U2, typename U3, typename U4, typename U5,
       
   466           typename T1, typename T2, typename T3, typename T4, typename T5>
       
   467 void
       
   468 RealtimeScheduleRealtimeNow (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
       
   469 {
       
   470   return ScheduleRealtimeNow (MakeEvent (f, a1, a2, a3, a4, a5));
       
   471 }
       
   472 
       
   473 } // namespace ns3
       
   474 
       
   475 #endif /* REALTIME_SIMULATOR_H */