next up previous contents index
Next: 4.2 Callbacks Up: 4.1 Event Scheduling Previous: 4.1.1 Simulation time   Contents   Index

4.1.2 Event creation and expiration

To schedule an event, users can call any of the Simulator::Schedule functions:

void MyEvent (double a)
{
  ...
}

EventId id = Simulator::Schedule (Seconds (10.0), &MyEvent, 3.1415);

NS_ASSERT (is.IsRunning ());
id.Cancel ();
NS_ASSERT (is.IsExpired ());
Simulator::Remove (id);

Simulator::Run ();

These Schedule functions all take as first argument a Time variable. Their second argument is always a function pointer and the other arguments are the values which will be passed to the user event function when the event expires. There can be up to 5 values to be passed to the user function.

Once scheduled, any event can be canceled (its cancel bit is set to true) or removed (it is removed from the event list): both operations will ensure that the event never expires.



Tom Henderson 2007-06-17