1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
12 simgrid::s4u::Host* other_host = simgrid::s4u::Host::by_name("Fafard");
14 simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("First callback"); });
16 simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("Second callback"); });
18 simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("Third callback"); });
20 XBT_INFO("Turning off: Three callbacks should be triggered");
21 other_host->turn_off();
23 XBT_INFO("Disconnect the second callback");
24 simgrid::s4u::Host::on_state_change.disconnect(second);
26 XBT_INFO("Turning on: Two callbacks should be triggered");
27 other_host->turn_on();
29 XBT_INFO("Disconnect the first callback");
30 simgrid::s4u::Host::on_state_change.disconnect(first);
32 XBT_INFO("Turning off: One callback should be triggered");
33 other_host->turn_off();
35 XBT_INFO("Disconnect the third callback");
36 simgrid::s4u::Host::on_state_change.disconnect(third);
37 XBT_INFO("Turning on: No more callbacks");
38 other_host->turn_on();
41 int main(int argc, char* argv[])
43 simgrid::s4u::Engine e(&argc, argv);
44 e.load_platform(argv[1]);
46 simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker);