Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / xbt / signals / signals.cpp
1 /* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
9
10 static void worker()
11 {
12   simgrid::s4u::Host* other_host = simgrid::s4u::Host::by_name("Fafard");
13   unsigned int first =
14       simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("First callback"); });
15   unsigned int second =
16       simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("Second callback"); });
17   unsigned int third =
18       simgrid::s4u::Host::on_state_change.connect([](simgrid::s4u::Host const&) { XBT_INFO("Third callback"); });
19
20   XBT_INFO("Turning off: Three callbacks should be triggered");
21   other_host->turn_off();
22
23   XBT_INFO("Disconnect the second callback");
24   simgrid::s4u::Host::on_state_change.disconnect(second);
25
26   XBT_INFO("Turning on: Two callbacks should be triggered");
27   other_host->turn_on();
28
29   XBT_INFO("Disconnect the first callback");
30   simgrid::s4u::Host::on_state_change.disconnect(first);
31
32   XBT_INFO("Turning off: One callback should be triggered");
33   other_host->turn_off();
34
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();
39 }
40
41 int main(int argc, char* argv[])
42 {
43   simgrid::s4u::Engine e(&argc, argv);
44   e.load_platform(argv[1]);
45
46   simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker);
47
48   e.run();
49
50   return 0;
51 }