1 /* Copyright (c) 2017-2022. 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");
13 simgrid::s4u::this_actor::sleep_for(200);
17 static void dummy_daemon()
19 while (simgrid::s4u::this_actor::get_host()->is_on()) {
20 XBT_INFO("Hello from the infinite loop");
21 simgrid::s4u::this_actor::sleep_for(80.0);
25 static void autostart()
27 simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Fafard");
29 XBT_INFO("starting a dummy process on %s", host->get_cname());
30 simgrid::s4u::ActorPtr dummy_actor = simgrid::s4u::Actor::create("Dummy", host, dummy);
31 dummy_actor->on_exit([](bool failed) { XBT_INFO("Dummy actor %s.", failed ? "failed" : "terminating"); });
32 dummy_actor->set_auto_restart(true);
33 dummy_actor->on_exit([](bool) { XBT_INFO("On_exit callback set after autorestart"); });
35 XBT_INFO("starting a daemon process on %s", host->get_cname());
36 simgrid::s4u::ActorPtr daemon_actor = simgrid::s4u::Actor::create("Daemon", host, dummy_daemon);
37 daemon_actor->on_exit([](bool failed) { XBT_INFO("Daemon actor %s.", failed ? "failed" : "terminating"); });
38 daemon_actor->daemonize()->set_auto_restart(true);
39 daemon_actor->on_exit([](bool) { XBT_INFO("On_exit callback set after autorestart"); });
41 simgrid::s4u::this_actor::sleep_for(50);
43 XBT_INFO("powering off %s", host->get_cname());
46 simgrid::s4u::this_actor::sleep_for(10);
48 XBT_INFO("powering on %s", host->get_cname());
50 simgrid::s4u::this_actor::sleep_for(200);
53 int main(int argc, char* argv[])
55 simgrid::s4u::Engine e(&argc, argv);
56 e.load_platform(argv[1]);
58 simgrid::s4u::Actor::create("Autostart", e.host_by_name("Tremblay"), autostart);
61 XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());