samples/main-simulator.cc
changeset 36 e622fb7a8262
parent 28 fd4ad927cbd7
child 53 ae406f4957d5
equal deleted inserted replaced
35:113798f021fe 36:e622fb7a8262
    13 };
    13 };
    14 
    14 
    15 void 
    15 void 
    16 MyModel::start (void)
    16 MyModel::start (void)
    17 {
    17 {
    18 	Simulator::schedule (RelTimeS (10.0), 
    18 	Simulator::schedule (Time::rel_s (10.0), 
    19 			     &MyModel::deal_with_event, 
    19 			     &MyModel::deal_with_event, 
    20 			     this, Simulator::now ().s ());
    20 			     this, Simulator::now ().s ());
    21 }
    21 }
    22 void
    22 void
    23 MyModel::deal_with_event (double value)
    23 MyModel::deal_with_event (double value)
    24 {
    24 {
    25 	std::cout << "Member method received event at " << Simulator::now ().s () << " started at " << value << std::endl;
    25 	std::cout << "Member method received event at " << Simulator::now ().s () << 
       
    26 		"s started at " << value << "s" << std::endl;
    26 }
    27 }
    27 
    28 
    28 static void 
    29 static void 
    29 random_function (MyModel *model)
    30 random_function (MyModel *model)
    30 {
    31 {
    31 	std::cout << "random function received event at " << Simulator::now ().s () << std::endl;
    32 	std::cout << "random function received event at " << 
       
    33 		Simulator::now ().s () << "s" << std::endl;
    32 	model->start ();
    34 	model->start ();
    33 }
    35 }
    34 
    36 
    35 
    37 
    36 int main (int argc, char *argv[])
    38 int main (int argc, char *argv[])
    37 {
    39 {
    38 	MyModel model;
    40 	MyModel model;
    39 
    41 
    40 	Simulator::schedule (AbsTimeS (10.0), &random_function, &model);
    42 	Simulator::schedule (Time::abs_s (10.0), &random_function, &model);
    41 
    43 
    42 	Simulator::run ();
    44 	Simulator::run ();
    43 
    45 
    44 	Simulator::destroy ();
    46 	Simulator::destroy ();
    45 }
    47 }