34 print (
"RandomFunction received event at", ns.core.Simulator.Now().GetSeconds(),
"s")
39 print (
"I should never be called... ")
45 /** Simple model object to illustrate event handling. */
49 /** Start model execution by scheduling a HandleEvent. */
54 * Simple event handler.
56 * \param [
in] eventValue Event argument.
58 void HandleEvent (double eventValue);
64 Simulator::Schedule (Seconds (10.0),
65 &MyModel::HandleEvent,
66 this, Simulator::Now ().GetSeconds ());
69 MyModel::HandleEvent (double value)
71 std::cout <<
"Member method received event at "
72 << Simulator::Now ().GetSeconds ()
73 <<
"s started at " << value <<
"s" << std::endl;
77 std::cout <<
"ExampleFunction received event at " << Simulator::
Now().GetSeconds() <<
"s" << std::endl;
81 EventImpl* ExampleFunctionEvent(MyModel& model)
83 return MakeEvent(&ExampleFunction, model);
86 void RandomFunctionCpp(MyModel& model) {
87 CPyCppyy::Eval(
"RandomFunction()");
90 EventImpl* RandomFunctionEvent(MyModel& model)
92 return MakeEvent(&RandomFunctionCpp, model);
95 void CancelledFunctionCpp(void) {
96 CPyCppyy::Eval(
"CancelledEvent()");
99 EventImpl* CancelledFunctionEvent()
107 cmd = ns.CommandLine(__file__)
110 model = ns.cppyy.gbl.MyModel()
111 v = ns.CreateObject("UniformRandomVariable")
112 v.SetAttribute(
"Min", ns.core.DoubleValue(10))
113 v.SetAttribute(
"Max", ns.core.DoubleValue(20))
115 ev = ns.cppyy.gbl.ExampleFunctionEvent(model)
116 ns.core.Simulator.Schedule(ns.core.Seconds(10.0), ev)
118 ev2 = ns.cppyy.gbl.RandomFunctionEvent(model)
119 ns.core.Simulator.Schedule(ns.core.Seconds(v.GetValue()), ev2)
121 ev3 = ns.cppyy.gbl.CancelledFunctionEvent()
122 id = ns.core.Simulator.Schedule(ns.core.Seconds(30.0), ev3)
123 ns.core.Simulator.Cancel(id)
125 ns.core.Simulator.Run()
127 ns.core.Simulator.Destroy()
129if __name__ ==
'__main__':
EventImpl * MakeEvent(void(*f)())
Make an EventImpl from a function pointer taking varying numbers of arguments.
Time Now()
create an ns3::Time instance which contains the current simulation time.
void ExampleFunction(MyModel *model)
Simple function event handler which Starts a MyModel object.
def CancelledEvent()
Example function - triggered if an event is canceled (should not be called).
def RandomFunction()
Example function - triggered at a random time.