src/core/model/simulator.cc
changeset 9134 7a750f032acd
parent 9063 32755d0516f4
child 9186 8934b7c0c1cb
equal deleted inserted replaced
9133:bcf7cef191c1 9134:7a750f032acd
    52                                            MakeTypeIdChecker ());
    52                                            MakeTypeIdChecker ());
    53 
    53 
    54 static void
    54 static void
    55 TimePrinter (std::ostream &os)
    55 TimePrinter (std::ostream &os)
    56 {
    56 {
       
    57   NS_LOG_FUNCTION_NOARGS ();
    57   os << Simulator::Now ().GetSeconds () << "s";
    58   os << Simulator::Now ().GetSeconds () << "s";
    58 }
    59 }
    59 
    60 
    60 static void
    61 static void
    61 NodePrinter (std::ostream &os)
    62 NodePrinter (std::ostream &os)
    62 {
    63 {
       
    64   NS_LOG_FUNCTION_NOARGS ();
    63   if (Simulator::GetContext () == 0xffffffff)
    65   if (Simulator::GetContext () == 0xffffffff)
    64     {
    66     {
    65       os << "-1";
    67       os << "-1";
    66     }
    68     }
    67   else
    69   else
    70     }
    72     }
    71 }
    73 }
    72 
    74 
    73 static SimulatorImpl **PeekImpl (void)
    75 static SimulatorImpl **PeekImpl (void)
    74 {
    76 {
       
    77   NS_LOG_FUNCTION_NOARGS ();
    75   static SimulatorImpl *impl = 0;
    78   static SimulatorImpl *impl = 0;
    76   return &impl;
    79   return &impl;
    77 }
    80 }
    78 
    81 
    79 static SimulatorImpl * GetImpl (void)
    82 static SimulatorImpl * GetImpl (void)
    80 {
    83 {
       
    84   NS_LOG_FUNCTION_NOARGS ();
    81   SimulatorImpl **pimpl = PeekImpl ();
    85   SimulatorImpl **pimpl = PeekImpl ();
    82   /* Please, don't include any calls to logging macros in this function
    86   /* Please, don't include any calls to logging macros in this function
    83    * or pay the price, that is, stack explosions.
    87    * or pay the price, that is, stack explosions.
    84    */
    88    */
    85   if (*pimpl == 0)
    89   if (*pimpl == 0)
   157 }
   161 }
   158 
   162 
   159 void 
   163 void 
   160 Simulator::Stop (void)
   164 Simulator::Stop (void)
   161 {
   165 {
       
   166   NS_LOG_FUNCTION_NOARGS ();
   162   NS_LOG_LOGIC ("stop");
   167   NS_LOG_LOGIC ("stop");
   163   GetImpl ()->Stop ();
   168   GetImpl ()->Stop ();
   164 }
   169 }
   165 
   170 
   166 void 
   171 void 
   174 Simulator::Now (void)
   179 Simulator::Now (void)
   175 {
   180 {
   176   /* Please, don't include any calls to logging macros in this function
   181   /* Please, don't include any calls to logging macros in this function
   177    * or pay the price, that is, stack explosions.
   182    * or pay the price, that is, stack explosions.
   178    */
   183    */
       
   184   NS_LOG_FUNCTION_NOARGS ();
   179   return GetImpl ()->Now ();
   185   return GetImpl ()->Now ();
   180 }
   186 }
   181 
   187 
   182 Time
   188 Time
   183 Simulator::GetDelayLeft (const EventId &id)
   189 Simulator::GetDelayLeft (const EventId &id)
   200   return DoScheduleNow (GetPointer (ev));
   206   return DoScheduleNow (GetPointer (ev));
   201 }
   207 }
   202 void
   208 void
   203 Simulator::ScheduleWithContext (uint32_t context, const Time &time, EventImpl *impl)
   209 Simulator::ScheduleWithContext (uint32_t context, const Time &time, EventImpl *impl)
   204 {
   210 {
       
   211   NS_LOG_FUNCTION (context << time << impl);
   205   return GetImpl ()->ScheduleWithContext (context, time, impl);
   212   return GetImpl ()->ScheduleWithContext (context, time, impl);
   206 }
   213 }
   207 EventId
   214 EventId
   208 Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
   215 Simulator::ScheduleDestroy (const Ptr<EventImpl> &ev)
   209 {
   216 {
   211   return DoScheduleDestroy (GetPointer (ev));
   218   return DoScheduleDestroy (GetPointer (ev));
   212 }
   219 }
   213 EventId 
   220 EventId 
   214 Simulator::DoSchedule (Time const &time, EventImpl *impl)
   221 Simulator::DoSchedule (Time const &time, EventImpl *impl)
   215 {
   222 {
       
   223   NS_LOG_FUNCTION (time << impl);
   216   return GetImpl ()->Schedule (time, impl);
   224   return GetImpl ()->Schedule (time, impl);
   217 }
   225 }
   218 EventId 
   226 EventId 
   219 Simulator::DoScheduleNow (EventImpl *impl)
   227 Simulator::DoScheduleNow (EventImpl *impl)
   220 {
   228 {
       
   229   NS_LOG_FUNCTION (impl);
   221   return GetImpl ()->ScheduleNow (impl);
   230   return GetImpl ()->ScheduleNow (impl);
   222 }
   231 }
   223 EventId 
   232 EventId 
   224 Simulator::DoScheduleDestroy (EventImpl *impl)
   233 Simulator::DoScheduleDestroy (EventImpl *impl)
   225 {
   234 {
       
   235   NS_LOG_FUNCTION (impl);
   226   return GetImpl ()->ScheduleDestroy (impl);
   236   return GetImpl ()->ScheduleDestroy (impl);
   227 }
   237 }
   228 
   238 
   229 
   239 
   230 EventId
   240 EventId
   302 }
   312 }
   303 
   313 
   304 uint32_t
   314 uint32_t
   305 Simulator::GetContext (void)
   315 Simulator::GetContext (void)
   306 {
   316 {
       
   317   NS_LOG_FUNCTION_NOARGS ();
   307   return GetImpl ()->GetContext ();
   318   return GetImpl ()->GetContext ();
   308 }
   319 }
   309 
   320 
   310 uint32_t
   321 uint32_t
   311 Simulator::GetSystemId (void)
   322 Simulator::GetSystemId (void)
   323 }
   334 }
   324 
   335 
   325 void
   336 void
   326 Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
   337 Simulator::SetImplementation (Ptr<SimulatorImpl> impl)
   327 {
   338 {
       
   339   NS_LOG_FUNCTION (impl);
   328   if (*PeekImpl () != 0)
   340   if (*PeekImpl () != 0)
   329     {
   341     {
   330       NS_FATAL_ERROR ("It is not possible to set the implementation after calling any Simulator:: function. Call Simulator::SetImplementation earlier or after Simulator::Destroy.");
   342       NS_FATAL_ERROR ("It is not possible to set the implementation after calling any Simulator:: function. Call Simulator::SetImplementation earlier or after Simulator::Destroy.");
   331     }
   343     }
   332   *PeekImpl () = GetPointer (impl);
   344   *PeekImpl () = GetPointer (impl);
   347   LogSetNodePrinter (&NodePrinter);
   359   LogSetNodePrinter (&NodePrinter);
   348 }
   360 }
   349 Ptr<SimulatorImpl>
   361 Ptr<SimulatorImpl>
   350 Simulator::GetImplementation (void)
   362 Simulator::GetImplementation (void)
   351 {
   363 {
       
   364   NS_LOG_FUNCTION_NOARGS ();
   352   return GetImpl ();
   365   return GetImpl ();
   353 }
   366 }
   354 
   367 
   355 
   368 
   356 
   369