From: Martin Quinson Date: Wed, 5 Jan 2022 00:28:52 +0000 (+0100) Subject: Introduce on_???_cb functions to shield the signals X-Git-Tag: v3.30~136 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c04075c49b6bc68df4f37240b4ac53e7a108abaa Introduce on_???_cb functions to shield the signals --- diff --git a/ChangeLog b/ChangeLog index 0106da1528..e4e795874f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,13 @@ S4U: - New function: Engine::track_vetoed_activities() to interrupt run() when an activity fails to start, and to keep track of such activities. Please see the corresponding example for more info. + - Introduce on_X_cb() functions for all signals, to attach a new + callback to the signal X. The signal variables are now hidden and + only these functions should be used. + Rational: this enables the usual deprecation schema where functions + remain for 4 releases when we need to modify the signals, while the + current code with the signal variables directly visible prevent any + smooth transition. SMPI: - Dynamic costs for MPI operations: New API to allow users to dynamically diff --git a/examples/cpp/actor-exiting/s4u-actor-exiting.cpp b/examples/cpp/actor-exiting/s4u-actor-exiting.cpp index 0b612962fb..ae5e60073d 100644 --- a/examples/cpp/actor-exiting/s4u-actor-exiting.cpp +++ b/examples/cpp/actor-exiting/s4u-actor-exiting.cpp @@ -77,10 +77,10 @@ int main(int argc, char* argv[]) e.load_platform(argv[1]); /* - Load the platform description */ /* Register a callback in the Actor::on_termination signal. It will be called for every terminated actors */ - sg4::Actor::on_termination.connect( + sg4::Actor::on_termination_cb( [](sg4::Actor const& actor) { XBT_INFO("Actor %s terminates now", actor.get_cname()); }); /* Register a callback in the Actor::on_destruction signal. It will be called for every destructed actors */ - sg4::Actor::on_destruction.connect( + sg4::Actor::on_destruction_cb( [](sg4::Actor const& actor) { XBT_INFO("Actor %s gets destroyed now", actor.get_cname()); }); /* Create some actors */ diff --git a/examples/cpp/dag-comm/s4u-dag-comm.cpp b/examples/cpp/dag-comm/s4u-dag-comm.cpp index 9401b8aa7b..525fb689ff 100644 --- a/examples/cpp/dag-comm/s4u-dag-comm.cpp +++ b/examples/cpp/dag-comm/s4u-dag-comm.cpp @@ -19,12 +19,12 @@ int main(int argc, char* argv[]) auto jupiter = e.host_by_name("Jupiter"); // Display the details on vetoed activities - simgrid::s4u::Activity::on_veto.connect([](const simgrid::s4u::Activity& a) { + simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) { XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(), (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned")); }); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec != nullptr) XBT_INFO("Activity '%s' is complete (start time: %f, finish time: %f)", exec->get_cname(), exec->get_start_time(), diff --git a/examples/cpp/dag-failure/s4u-dag-failure.cpp b/examples/cpp/dag-failure/s4u-dag-failure.cpp index 2c6bd2e832..8b04b9d331 100644 --- a/examples/cpp/dag-failure/s4u-dag-failure.cpp +++ b/examples/cpp/dag-failure/s4u-dag-failure.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) auto* faulty = e.host_by_name("Faulty Host"); auto* safe = e.host_by_name("Safe Host"); - sg4::Activity::on_completion.connect([](sg4::Activity& activity) { + sg4::Activity::on_completion_cb([](sg4::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; diff --git a/examples/cpp/dag-io/s4u-dag-io.cpp b/examples/cpp/dag-io/s4u-dag-io.cpp index 9f1bee80f2..81e2e91748 100644 --- a/examples/cpp/dag-io/s4u-dag-io.cpp +++ b/examples/cpp/dag-io/s4u-dag-io.cpp @@ -19,12 +19,12 @@ int main(int argc, char* argv[]) auto carl = e.host_by_name("carl"); // Display the details on vetoed activities - simgrid::s4u::Activity::on_veto.connect([](const simgrid::s4u::Activity& a) { + simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) { XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", a.get_cname(), (a.dependencies_solved() ? "solved" : "NOT solved"), (a.is_assigned() ? "assigned" : "NOT assigned")); }); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; diff --git a/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp b/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp index bdced0001c..df88874135 100644 --- a/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp +++ b/examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp @@ -153,7 +153,7 @@ int main(int argc, char** argv) std::set vetoed; e.track_vetoed_activities(&vetoed); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { // when an Exec completes, we need to set the potential start time of all its ouput comms const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here diff --git a/examples/cpp/dag-simple/s4u-dag-simple.cpp b/examples/cpp/dag-simple/s4u-dag-simple.cpp index f377550aa0..03445a4945 100644 --- a/examples/cpp/dag-simple/s4u-dag-simple.cpp +++ b/examples/cpp/dag-simple/s4u-dag-simple.cpp @@ -18,7 +18,7 @@ int main(int argc, char* argv[]) auto fafard = e.host_by_name("Fafard"); // Display the details on vetoed activities - simgrid::s4u::Activity::on_veto.connect([](const simgrid::s4u::Activity& a) { + simgrid::s4u::Activity::on_veto_cb([](const simgrid::s4u::Activity& a) { const auto& exec = static_cast(a); // all activities are execs in this example XBT_INFO("Activity '%s' vetoed. Dependencies: %s; Ressources: %s", exec.get_cname(), @@ -26,7 +26,7 @@ int main(int argc, char* argv[]) (exec.is_assigned() ? "assigned" : "NOT assigned")); }); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; diff --git a/examples/cpp/exec-dependent/s4u-exec-dependent.cpp b/examples/cpp/exec-dependent/s4u-exec-dependent.cpp index ada7e5e899..dcff84c373 100644 --- a/examples/cpp/exec-dependent/s4u-exec-dependent.cpp +++ b/examples/cpp/exec-dependent/s4u-exec-dependent.cpp @@ -54,7 +54,7 @@ int main(int argc, char* argv[]) simgrid::s4u::Actor::create("worker", e.host_by_name("Fafard"), worker); - simgrid::s4u::Activity::on_veto.connect([&e](simgrid::s4u::Activity& a) { + simgrid::s4u::Activity::on_veto_cb([&e](simgrid::s4u::Activity& a) { auto& exec = static_cast(a); // First display the situation diff --git a/examples/cpp/platform-failures/s4u-platform-failures.cpp b/examples/cpp/platform-failures/s4u-platform-failures.cpp index 675e2f177f..0417ef6aaf 100644 --- a/examples/cpp/platform-failures/s4u-platform-failures.cpp +++ b/examples/cpp/platform-failures/s4u-platform-failures.cpp @@ -104,7 +104,7 @@ int main(int argc, char* argv[]) // This is how to attach a profile to an host that is created from the XML file. // This should be done before calling load_platform(), as the on_creation() event is fired when loading the platform. // You can never set a new profile to a resource that already have one. - sg4::Host::on_creation.connect([](sg4::Host& h) { + sg4::Host::on_creation_cb([](sg4::Host& h) { if (h.get_name() == "Bourrassa") { h.set_state_profile(simgrid::kernel::profile::ProfileBuilder::from_string("bourassa_profile", "67 0\n70 1\n", 0)); } diff --git a/include/simgrid/s4u/Activity.hpp b/include/simgrid/s4u/Activity.hpp index e5aca02bf7..32357759ac 100644 --- a/include/simgrid/s4u/Activity.hpp +++ b/include/simgrid/s4u/Activity.hpp @@ -95,13 +95,17 @@ protected: static std::set* vetoed_activities_; -public: - /*! Signal fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no - * resource assigned) */ +private: static xbt::signal on_veto; - /*! Signal fired when theactivity completes (either normally, cancelled or failed) */ static xbt::signal on_completion; +public: + /*! Add a callback fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no + * resource assigned) */ + static void on_veto_cb(const std::function& cb) { on_veto.connect(cb); } + /*! Add a callback fired when theactivity completes (either normally, cancelled or failed) */ + static void on_completion_cb(const std::function cb) { on_completion.connect(cb); } + void vetoable_start() { state_ = State::STARTING; diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 935187e968..3e1b38c4ed 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -68,32 +68,47 @@ public: /** Retrieve a reference to myself */ static Actor* self(); - /** Fired when a new actor has been created **/ +#ifndef DOXYGEN static xbt::signal on_creation; - /** Signal to others that an actor has been suspended**/ static xbt::signal on_suspend; - /** Signal to others that an actor has been resumed **/ static xbt::signal on_resume; - /** Signal to others that an actor is sleeping **/ static xbt::signal on_sleep; - /** Signal to others that an actor wakes up for a sleep **/ static xbt::signal on_wake_up; - /** Signal to others that an actor is has been migrated to another host **/ static xbt::signal on_host_change; + static xbt::signal on_termination; + static xbt::signal on_destruction; +#endif + +public: + /** Add a callback fired when a new actor has been created **/ + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + /** Add a callback fired when an actor has been suspended**/ + static void on_suspend_cb(const std::function cb) { on_suspend.connect(cb); } + /** Add a callback fired when an actor has been resumed **/ + static void on_resume_cb(const std::function& cb) { on_resume.connect(cb); } + /** Add a callback fired when an actor starts sleeping **/ + static void on_sleep_cb(const std::function& cb) { on_sleep.connect(cb); } + /** Add a callback fired when an actor wakes up from a sleep **/ + static void on_wake_up_cb(const std::function& cb) { on_wake_up.connect(cb); } + /** Add a callback fired when an actor is has been migrated to another host **/ + static void on_host_change_cb(const std::function& cb) + { + on_host_change.connect(cb); + } - /** Signal indicating that an actor terminated its code. + /** Add a callback fired when an actor terminates its code. * @beginrst * The actor may continue to exist if it is still referenced in the simulation, but it's not active anymore. * If you want to free extra data when the actor's destructor is called, use :cpp:var:`Actor::on_destruction`. * If you want to register to the termination of a given actor, use :cpp:func:`this_actor::on_exit()` instead. * @endrst */ - static xbt::signal on_termination; - /** Signal indicating that an actor is about to disappear (its destructor was called). + static void on_termination_cb(const std::function& cb) { on_termination.connect(cb); } + /** Add a callback fired when an actor is about to disappear (its destructor was called). * This signal is fired for any destructed actor, which is mostly useful when designing plugins and extensions. * If you want to react to the end of the actor's code, use Actor::on_termination instead. * If you want to register to the termination of a given actor, use this_actor::on_exit() instead.*/ - static xbt::signal on_destruction; + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } /** Create an actor from a std::function. * If the actor is restarted, it gets a fresh copy of the function. */ diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index bee49b304a..68f5a8ad47 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -63,10 +63,17 @@ public: */ static void sendto(Host* from, Host* to, uint64_t simulated_size_in_bytes); + static void on_send_cb(const std::function& cb) { on_send.connect(cb); } + static void on_recv_cb(const std::function& cb) { on_recv.connect(cb); } + static void on_start_cb(const std::function& cb) { on_start.connect(cb); } + static void on_completion_cb(const std::function& cb) { on_completion.connect(cb); } +#ifndef DOXYGEN + /* FIXME signals should be private */ static xbt::signal on_send; static xbt::signal on_recv; static xbt::signal on_start; static xbt::signal on_completion; +#endif /*! take a vector s4u::CommPtr and return when one of them is finished. * The return value is the rank of the first finished CommPtr. */ diff --git a/include/simgrid/s4u/Disk.hpp b/include/simgrid/s4u/Disk.hpp index 736476367e..f6a7ea7e57 100644 --- a/include/simgrid/s4u/Disk.hpp +++ b/include/simgrid/s4u/Disk.hpp @@ -126,11 +126,16 @@ public: Disk* seal(); /* The signals */ - /** @brief Callback signal fired when a new Disk is created */ + /** @brief Add a callback fired when a new Disk is created */ + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + /** @brief Add a callback fired when a Disk is destroyed */ + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } + /** @brief Add a callback fired when a Disk's state changes */ + static void on_state_change_cb(const std::function& cb) { on_state_change.connect(cb); } + +private: static xbt::signal on_creation; - /** @brief Callback signal fired when a Disk is destroyed */ static xbt::signal on_destruction; - /** @brief Callback signal fired when a Disk's state changes */ static xbt::signal on_state_change; }; diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 7b298a4981..db838013cc 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -195,25 +195,32 @@ public: static void set_config(const std::string& name, const std::string& value); Engine* set_default_comm_data_copy_callback(void (*callback)(kernel::activity::CommImpl*, void*, size_t)); - /** Callback fired when the platform is created (ie, the xml file parsed), - * right before the actual simulation starts. */ - static xbt::signal on_platform_created; - /** Callback fired when the platform is about to be created + /** Add a callback fired when the platform is created (ie, the xml file parsed), + * right before the actual simulation starts. */ + static void on_platform_created_cb(const std::function& cb) { on_platform_created.connect(cb); } + /** Add a callback fired when the platform is about to be created * (ie, after any configuration change and just before the resource creation) */ - static xbt::signal on_platform_creation; + static void on_platform_creation_cb(const std::function& cb) { on_platform_creation.connect(cb); } + /** Add a callback fired when the main simulation loop ends, just before the end of Engine::run() */ + static void on_simulation_end_cb(const std::function& cb) { on_simulation_end.connect(cb); } - /** Callback fired when the main simulation loop ends, just before the end of Engine::run() */ - static xbt::signal on_simulation_end; - - /** Callback fired when the time jumps into the future */ - static xbt::signal on_time_advance; + /** Add a callback fired when the time jumps into the future */ + static void on_time_advance_cb(const std::function& cb) { on_time_advance.connect(cb); } - /** Callback fired when the time cannot advance because of inter-actors deadlock. Note that the on_exit of each actor - * is also executed on deadlock. */ - static xbt::signal on_deadlock; + /** Add a callback fired when the time cannot advance because of inter-actors deadlock. Note that the on_exit of each + * actor is also executed on deadlock. */ + static void on_deadlock_cb(const std::function& cb) { on_deadlock.connect(cb); } +#ifndef DOXYGEN + /* FIXME signals should be private */ + static xbt::signal on_platform_created; + static xbt::signal on_platform_creation; +#endif private: + static xbt::signal on_simulation_end; + static xbt::signal on_time_advance; + static xbt::signal on_deadlock; kernel::EngineImpl* const pimpl; static Engine* instance_; void initialize(int* argc, char** argv); diff --git a/include/simgrid/s4u/Exec.hpp b/include/simgrid/s4u/Exec.hpp index 14c173b6bf..1013fcffb5 100644 --- a/include/simgrid/s4u/Exec.hpp +++ b/include/simgrid/s4u/Exec.hpp @@ -42,13 +42,15 @@ protected: void reset() const; + static xbt::signal on_start; + public: #ifndef DOXYGEN Exec(Exec const&) = delete; Exec& operator=(Exec const&) = delete; #endif /*! Signal fired each time that an execution actually starts (no veto) */ - static xbt::signal on_start; + static void on_start_cb(const std::function& cb) { on_start.connect(cb); } static ExecPtr init(); Exec* start() override; diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index e745232277..b59ec85d10 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -54,18 +54,23 @@ public: protected: virtual ~Host(); // Call destroy() instead of manually deleting it. Host* set_netpoint(kernel::routing::NetPoint* netpoint); -#endif -public: - /** Called on each newly created host */ static xbt::signal on_creation; - /** Called when the machine is turned on or off (called AFTER the change) */ + static xbt::signal on_destruction; + +public: + static xbt::signal on_speed_change; static xbt::signal on_state_change; - /** Called when the speed of the machine is changed (called AFTER the change) +#endif + /** Add a callback fired on each newly created host */ + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + /** Add a callback fired when the machine is turned on or off (called AFTER the change) */ + static void on_state_change_cb(const std::function& cb) { on_state_change.connect(cb); } + /** Add a callback fired when the speed of the machine is changed (called AFTER the change) * (either because of a pstate switch or because of an external load event coming from the profile) */ - static xbt::signal on_speed_change; - /** Called just before destructing a host */ - static xbt::signal on_destruction; + static void on_speed_change_cb(const std::function& cb) { on_speed_change.connect(cb); } + /** Add a callback fired just before destructing a host */ + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } virtual void destroy(); #ifndef DOXYGEN diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index 5d89a0b3c5..c473b1063e 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -40,6 +40,9 @@ protected: virtual ~Link() = default; // The implementation that never changes kernel::resource::LinkImplIntf* const pimpl_; +#ifndef DOXYGEN + friend kernel::resource::NetworkAction; // signal comm_state_changed +#endif public: enum class SharingPolicy { NONLINEAR = 4, WIFI = 3, SPLITDUPLEX = 2, SHARED = 1, FATPIPE = 0 }; @@ -137,22 +140,32 @@ public: Link* seal(); - /* The signals */ - /** @brief Callback signal fired when a new Link is created */ +private: +#ifndef DOXYGEN static xbt::signal on_creation; - - /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */ static xbt::signal on_state_change; - - /** @brief Callback signal fired when the bandwidth of a Link changes */ static xbt::signal on_bandwidth_change; - - /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */ static xbt::signal on_communication_state_change; - - /** @brief Callback signal fired when a Link is destroyed */ static xbt::signal on_destruction; +#endif + +public: + /* The signals */ + /** @brief Add a callback fired when a new Link is created */ + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + /** @brief Add a callback fired when the state of a Link changes (when it is turned on or off) */ + static void on_state_change_cb(const std::function& cb) { on_state_change.connect(cb); } + /** @brief Add a callback fired when the bandwidth of a Link changes */ + static void on_bandwidth_change_cb(const std::function& cb) { on_bandwidth_change.connect(cb); } + /** @brief Add a callback fired when a communication changes it state (ready/done/cancel) */ + static void on_communication_state_change_cb( + const std::function& cb) + { + on_communication_state_change.connect(cb); + } + /** @brief Add a callback fired when a Link is destroyed */ + static void on_destruction_cb(std::function cb) { on_destruction.connect(cb); } }; /** diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 6c0f3e7306..4d37853bb7 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -116,10 +116,14 @@ public: std::vector const& link_list)> on_route_creation; // XBT_ATTRIB_DEPRECATED_v332 : should not be used by users, used by ns3.. if necessary, // signal shouldn't use LinkImpl* -#endif +private: static xbt::signal on_creation; static xbt::signal on_seal; +#endif +public: + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + static void on_seal_cb(const std::function& cb) { on_seal.connect(cb); } /** * @brief Create a host diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index d1c7a844f3..1292c46924 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -69,15 +69,34 @@ public: VirtualMachine* set_bound(double bound); State get_state() const; + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + static void on_start_cb(const std::function& cb) { on_start.connect(cb); } + static void on_started_cb(const std::function& cb) { on_started.connect(cb); } + static void on_shutdown_cb(const std::function& cb) { on_shutdown.connect(cb); } + static void on_suspend_cb(const std::function& cb) { on_suspend.connect(cb); } + static void on_resume_cb(const std::function& cb) { on_resume.connect(cb); } + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } + static void on_migration_start_cb(const std::function& cb) + { + on_migration_start.connect(cb); + } + static void on_migration_end_cb(const std::function& cb) + { + on_migration_end.connect(cb); + } +#ifndef DOXYGEN + /* FIXME the signals should be private */ + static xbt::signal on_migration_start; + static xbt::signal on_migration_end; + static xbt::signal on_destruction; +#endif +private: static xbt::signal on_creation; static xbt::signal on_start; static xbt::signal on_started; static xbt::signal on_shutdown; static xbt::signal on_suspend; static xbt::signal on_resume; - static xbt::signal on_migration_start; - static xbt::signal on_migration_end; - static xbt::signal on_destruction; }; } // namespace s4u } // namespace simgrid diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index 16f8b150bb..901622397b 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -384,13 +384,13 @@ static void on_simulation_start() XBT_DEBUG("Filename %s is open for writing", filename.c_str()); if (format == "Paje") { - Container::on_creation.connect(on_container_creation_paje); - Container::on_destruction.connect(on_container_destruction_paje); - EntityValue::on_creation.connect(on_entity_value_creation); - Type::on_creation.connect(on_type_creation); - LinkType::on_creation.connect(on_link_type_creation); - PajeEvent::on_creation.connect(on_event_creation); - PajeEvent::on_destruction.connect(on_event_destruction); + Container::on_creation_cb(on_container_creation_paje); + Container::on_destruction_cb(on_container_destruction_paje); + EntityValue::on_creation_cb(on_entity_value_creation); + Type::on_creation_cb(on_type_creation); + LinkType::on_creation_cb(on_link_type_creation); + PajeEvent::on_creation_cb(on_event_creation); + PajeEvent::on_destruction_cb(on_event_destruction); paje::dump_generator_version(); @@ -404,9 +404,9 @@ static void on_simulation_start() paje::dump_header(trace_basic, TRACE_display_sizes()); } else { trace_format = TraceFormat::Ti; - Container::on_creation.connect(on_container_creation_ti); - Container::on_destruction.connect(on_container_destruction_ti); - StateEvent::on_destruction.connect(on_state_event_destruction); + Container::on_creation_cb(on_container_creation_ti); + Container::on_destruction_cb(on_container_destruction_ti); + StateEvent::on_destruction_cb(on_state_event_destruction); } trace_active = true; @@ -464,10 +464,10 @@ void init() 6); /* Connect Engine callbacks */ - s4u::Engine::on_platform_creation.connect(on_simulation_start); - s4u::Engine::on_time_advance.connect([](double /*time_delta*/) { dump_buffer(false); }); - s4u::Engine::on_deadlock.connect(on_simulation_end); - s4u::Engine::on_simulation_end.connect(on_simulation_end); + s4u::Engine::on_platform_creation_cb(on_simulation_start); + s4u::Engine::on_time_advance_cb([](double /*time_delta*/) { dump_buffer(false); }); + s4u::Engine::on_deadlock_cb(on_simulation_end); + s4u::Engine::on_simulation_end_cb(on_simulation_end); } } // namespace instr } // namespace simgrid diff --git a/src/instr/instr_paje_containers.hpp b/src/instr/instr_paje_containers.hpp index 8ce3d7f3e9..c10ab2bd61 100644 --- a/src/instr/instr_paje_containers.hpp +++ b/src/instr/instr_paje_containers.hpp @@ -30,10 +30,14 @@ class Container { protected: static void set_root(Container* root) { root_container_ = root; } -public: +private: static xbt::signal on_creation; static xbt::signal on_destruction; +public: + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } + explicit Container(const std::string& name, const std::string& type_name, Container* parent); Container(const Container&) = delete; Container& operator=(const Container&) = delete; diff --git a/src/instr/instr_paje_events.hpp b/src/instr/instr_paje_events.hpp index 17aab29eaa..10c3b3b2f7 100644 --- a/src/instr/instr_paje_events.hpp +++ b/src/instr/instr_paje_events.hpp @@ -46,10 +46,13 @@ inline std::ostream& operator<<(std::ostream& os, PajeEventType event) class PajeEvent { Container* container_; Type* type_; -public: static xbt::signal on_creation; static xbt::signal on_destruction; +public: + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } + double timestamp_; PajeEventType eventType_; std::stringstream stream_; @@ -83,8 +86,10 @@ class StateEvent : public PajeEvent { #endif std::unique_ptr extra_; -public: static xbt::signal on_destruction; + +public: + static void on_destruction_cb(const std::function& cb) { on_destruction.connect(cb); } StateEvent(Container* container, Type* type, PajeEventType event_type, EntityValue* value, TIData* extra); ~StateEvent() override { on_destruction(*this); } bool has_extra() const { return extra_ != nullptr; } diff --git a/src/instr/instr_paje_types.hpp b/src/instr/instr_paje_types.hpp index b30eb760bc..d09cb2b040 100644 --- a/src/instr/instr_paje_types.hpp +++ b/src/instr/instr_paje_types.hpp @@ -26,11 +26,16 @@ class Type { std::map, std::less<>> children_; Container* issuer_ = nullptr; + static xbt::signal on_creation; + protected: Container* get_issuer() const { return issuer_; } public: - static xbt::signal on_creation; + static void on_creation_cb(const std::function& cb) + { + on_creation.connect(cb); + } Type(PajeEventType event_type, const std::string& name, const std::string& alias, const std::string& color, Type* parent); @@ -94,8 +99,13 @@ public: }; class LinkType : public ValueType { -public: static xbt::signal on_creation; + +public: + static void on_creation_cb(const std::function& cb) + { + on_creation.connect(cb); + } LinkType(const std::string& name, const Type* source, const Type* dest, const std::string& alias, Type* parent) : ValueType(PajeEventType::DefineLinkType, name, alias, parent) { diff --git a/src/instr/instr_paje_values.hpp b/src/instr/instr_paje_values.hpp index ee9d3f992f..c679fd5582 100644 --- a/src/instr/instr_paje_values.hpp +++ b/src/instr/instr_paje_values.hpp @@ -18,8 +18,10 @@ class EntityValue { std::string color_; Type* parent_; -public: static xbt::signal on_creation; + +public: + static void on_creation_cb(const std::function& cb) { on_creation.connect(cb); } explicit EntityValue(const std::string& name, const std::string& color, Type* parent); long long int get_id() const { return id_; } diff --git a/src/instr/instr_platform.cpp b/src/instr/instr_platform.cpp index 67cf07540d..c47e87966c 100644 --- a/src/instr/instr_platform.cpp +++ b/src/instr/instr_platform.cpp @@ -422,70 +422,70 @@ void define_callbacks() // always need the callbacks to zones (we need only the root zone), to create the rootContainer and the rootType // properly if (TRACE_needs_platform()) { - s4u::Engine::on_platform_created.connect(on_platform_created); - s4u::Host::on_creation.connect(on_host_creation); - s4u::Host::on_speed_change.connect([](s4u::Host const& host) { + s4u::Engine::on_platform_created_cb(on_platform_created); + s4u::Host::on_creation_cb(on_host_creation); + s4u::Host::on_speed_change_cb([](s4u::Host const& host) { Container::by_name(host.get_name()) ->get_variable("speed") ->set_event(simgrid_get_clock(), host.get_core_count() * host.get_available_speed()); }); - s4u::Link::on_creation.connect(on_link_creation); - s4u::Link::on_bandwidth_change.connect([](s4u::Link const& link) { + s4u::Link::on_creation_cb(on_link_creation); + s4u::Link::on_bandwidth_change_cb([](s4u::Link const& link) { Container::by_name(link.get_name()) ->get_variable("bandwidth") ->set_event(simgrid_get_clock(), sg_bandwidth_factor * link.get_bandwidth()); }); - s4u::NetZone::on_seal.connect([](s4u::NetZone const& /*netzone*/) { currentContainer.pop_back(); }); + s4u::NetZone::on_seal_cb([](s4u::NetZone const& /*netzone*/) { currentContainer.pop_back(); }); kernel::routing::NetPoint::on_creation.connect([](kernel::routing::NetPoint const& netpoint) { if (netpoint.is_router()) new RouterContainer(netpoint.get_name(), currentContainer.back()); }); } - s4u::NetZone::on_creation.connect(on_netzone_creation); + s4u::NetZone::on_creation_cb(on_netzone_creation); kernel::resource::CpuAction::on_state_change.connect(on_action_state_change); - s4u::Link::on_communication_state_change.connect(on_action_state_change); + s4u::Link::on_communication_state_change_cb(on_action_state_change); if (TRACE_actor_is_enabled()) { - s4u::Actor::on_creation.connect(on_actor_creation); - s4u::Actor::on_destruction.connect([](s4u::Actor const& actor) { + s4u::Actor::on_creation_cb(on_actor_creation); + s4u::Actor::on_destruction_cb([](s4u::Actor const& actor) { auto container = Container::by_name_or_null(instr_pid(actor)); if (container != nullptr) container->remove_from_parent(); }); - s4u::Actor::on_suspend.connect([](s4u::Actor const& actor) { + s4u::Actor::on_suspend_cb([](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("suspend"); }); - s4u::Actor::on_resume.connect( + s4u::Actor::on_resume_cb( [](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event(); }); - s4u::Actor::on_sleep.connect([](s4u::Actor const& actor) { + s4u::Actor::on_sleep_cb([](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->push_event("sleep"); }); - s4u::Actor::on_wake_up.connect( + s4u::Actor::on_wake_up_cb( [](s4u::Actor const& actor) { Container::by_name(instr_pid(actor))->get_state("ACTOR_STATE")->pop_event(); }); - s4u::Exec::on_start.connect([](s4u::Exec const&) { + s4u::Exec::on_start_cb([](s4u::Exec const&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("execute"); }); - s4u::Activity::on_completion.connect([](const s4u::Activity&) { + s4u::Activity::on_completion_cb([](const s4u::Activity&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->pop_event(); }); - s4u::Comm::on_send.connect([](s4u::Comm const&) { + s4u::Comm::on_send_cb([](s4u::Comm const&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("send"); }); - s4u::Comm::on_recv.connect([](s4u::Comm const&) { + s4u::Comm::on_recv_cb([](s4u::Comm const&) { Container::by_name(instr_pid(*s4u::Actor::self()))->get_state("ACTOR_STATE")->push_event("receive"); }); - s4u::Actor::on_host_change.connect(on_actor_host_change); + s4u::Actor::on_host_change_cb(on_actor_host_change); } if (TRACE_smpi_is_enabled() && TRACE_smpi_is_computing()) { - s4u::Exec::on_start.connect([](s4u::Exec const& exec) { + s4u::Exec::on_start_cb([](s4u::Exec const& exec) { Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid())) ->get_state("MPI_STATE") ->push_event("computing", new CpuTIData("compute", exec.get_cost())); }); - s4u::Activity::on_completion.connect([](const s4u::Activity&) { + s4u::Activity::on_completion_cb([](const s4u::Activity&) { Container::by_name(std::string("rank-") + std::to_string(s4u::Actor::self()->get_pid())) ->get_state("MPI_STATE") ->pop_event(); @@ -493,18 +493,18 @@ void define_callbacks() } if (TRACE_vm_is_enabled()) { - s4u::Host::on_creation.connect(on_vm_creation); - s4u::VirtualMachine::on_start.connect([](s4u::VirtualMachine const& vm) { + s4u::Host::on_creation_cb(on_vm_creation); + s4u::VirtualMachine::on_start_cb([](s4u::VirtualMachine const& vm) { Container::by_name(vm.get_name())->get_state("VM_STATE")->push_event("start"); }); - s4u::VirtualMachine::on_started.connect( + s4u::VirtualMachine::on_started_cb( [](s4u::VirtualMachine const& vm) { Container::by_name(vm.get_name())->get_state("VM_STATE")->pop_event(); }); - s4u::VirtualMachine::on_suspend.connect([](s4u::VirtualMachine const& vm) { + s4u::VirtualMachine::on_suspend_cb([](s4u::VirtualMachine const& vm) { Container::by_name(vm.get_name())->get_state("VM_STATE")->push_event("suspend"); }); - s4u::VirtualMachine::on_resume.connect( + s4u::VirtualMachine::on_resume_cb( [](s4u::VirtualMachine const& vm) { Container::by_name(vm.get_name())->get_state("VM_STATE")->pop_event(); }); - s4u::Host::on_destruction.connect( + s4u::Host::on_destruction_cb( [](s4u::Host const& host) { Container::by_name(host.get_name())->remove_from_parent(); }); } } diff --git a/src/kernel/EngineImpl.cpp b/src/kernel/EngineImpl.cpp index 4a38f962ef..c9f6f41678 100644 --- a/src/kernel/EngineImpl.cpp +++ b/src/kernel/EngineImpl.cpp @@ -238,7 +238,7 @@ void EngineImpl::initialize(int* argc, char** argv) /* register a function to be called by SURF after the environment creation */ sg_platf_init(); - s4u::Engine::on_platform_created.connect([this]() { this->presolve(); }); + s4u::Engine::on_platform_created_cb([this]() { this->presolve(); }); if (config::get_value("debug/clean-atexit")) atexit(shutdown); diff --git a/src/kernel/resource/VirtualMachineImpl.cpp b/src/kernel/resource/VirtualMachineImpl.cpp index a04e7abf2a..e1ab67e218 100644 --- a/src/kernel/resource/VirtualMachineImpl.cpp +++ b/src/kernel/resource/VirtualMachineImpl.cpp @@ -118,9 +118,9 @@ static void remove_active_activity(kernel::activity::ActivityImpl const& act) VMModel::VMModel(const std::string& name) : HostModel(name) { - s4u::Host::on_state_change.connect(host_state_change); - s4u::Exec::on_start.connect(add_active_exec); - s4u::Activity::on_completion.connect(remove_active_exec); + s4u::Host::on_state_change_cb(host_state_change); + s4u::Exec::on_start_cb(add_active_exec); + s4u::Activity::on_completion_cb(remove_active_exec); activity::ActivityImpl::on_resumed.connect(add_active_activity); activity::ActivityImpl::on_suspended.connect(remove_active_activity); } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 68768afea6..07cfb6e8f6 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -83,9 +83,9 @@ NetZoneImpl::NetZoneImpl(const std::string& name) : piface_(this), name_(name) simgrid::s4u::Engine::on_platform_creation(); /* Initialize the surf models. That must be done after we got all config, and before we need the models. - * That is, after the last tag, if any, and before the first of cluster|peer|zone|trace|trace_connect + * That is, after the last tag, if any, and before the first of cluster|peer|zone|trace|trace_cb * - * I'm not sure for and , there may be a bug here + * I'm not sure for and , there may be a bug here * (FIXME: check it out by creating a file beginning with one of these tags) * but cluster and peer come down to zone creations, so putting this verification here is correct. */ diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index 3e183363a4..1187d8b361 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -41,7 +41,7 @@ void MSG_init_nocheck(int* argc, char** argv) msg_global->sent_msg = 0; msg_global->task_copy_callback = nullptr; msg_global->process_data_cleanup = nullptr; - simgrid::s4u::Actor::on_termination.connect([](simgrid::s4u::Actor const& actor) { + simgrid::s4u::Actor::on_termination_cb([](simgrid::s4u::Actor const& actor) { // free the data if a function was provided void* userdata = sg_actor_get_data(&actor); if (userdata && msg_global->process_data_cleanup) diff --git a/src/plugins/file_system/s4u_FileSystem.cpp b/src/plugins/file_system/s4u_FileSystem.cpp index ad88b620a8..e22e8b052f 100644 --- a/src/plugins/file_system/s4u_FileSystem.cpp +++ b/src/plugins/file_system/s4u_FileSystem.cpp @@ -463,15 +463,15 @@ void sg_storage_file_system_init() if (not FileSystemDiskExt::EXTENSION_ID.valid()) { FileSystemDiskExt::EXTENSION_ID = simgrid::s4u::Disk::extension_create(); - simgrid::s4u::Disk::on_creation.connect(&on_disk_creation); + simgrid::s4u::Disk::on_creation_cb(&on_disk_creation); } if (not FileDescriptorHostExt::EXTENSION_ID.valid()) { FileDescriptorHostExt::EXTENSION_ID = simgrid::s4u::Host::extension_create(); - simgrid::s4u::Host::on_creation.connect(&on_host_creation); + simgrid::s4u::Host::on_creation_cb(&on_host_creation); } - simgrid::s4u::Engine::on_platform_created.connect(&on_platform_created); - simgrid::s4u::Engine::on_simulation_end.connect(&on_simulation_end); + simgrid::s4u::Engine::on_platform_created_cb(&on_platform_created); + simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end); } sg_file_t sg_file_open(const char* fullpath, void* data) diff --git a/src/plugins/host_dvfs.cpp b/src/plugins/host_dvfs.cpp index ef6f7d4788..b0677f6174 100644 --- a/src/plugins/host_dvfs.cpp +++ b/src/plugins/host_dvfs.cpp @@ -295,11 +295,11 @@ public: task_id = 0; } }); - simgrid::s4u::Exec::on_start.connect([this](simgrid::s4u::Exec const& activity) { + simgrid::s4u::Exec::on_start_cb([this](simgrid::s4u::Exec const& activity) { if (activity.get_host() == get_host()) pre_task(); }); - simgrid::s4u::Activity::on_completion.connect([this](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([this](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; @@ -444,5 +444,5 @@ void sg_host_dvfs_plugin_init() sg_host_load_plugin_init(); - simgrid::s4u::Host::on_creation.connect(&on_host_added); + simgrid::s4u::Host::on_creation_cb(&on_host_added); } diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 18ed351da1..3b2b4839ef 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -477,11 +477,11 @@ void sg_host_energy_plugin_init() HostEnergy::EXTENSION_ID = simgrid::s4u::Host::extension_create(); - simgrid::s4u::Host::on_creation.connect(&on_creation); - simgrid::s4u::Host::on_state_change.connect(&on_host_change); - simgrid::s4u::Host::on_speed_change.connect(&on_host_change); - simgrid::s4u::Host::on_destruction.connect(&on_host_destruction); - simgrid::s4u::Engine::on_simulation_end.connect(&on_simulation_end); + simgrid::s4u::Host::on_creation_cb(&on_creation); + simgrid::s4u::Host::on_state_change_cb(&on_host_change); + simgrid::s4u::Host::on_speed_change_cb(&on_host_change); + simgrid::s4u::Host::on_destruction_cb(&on_host_destruction); + simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end); simgrid::kernel::resource::CpuAction::on_state_change.connect(&on_action_state_change); // We may only have one actor on a node. If that actor executes something like // compute -> recv -> compute @@ -489,7 +489,7 @@ void sg_host_energy_plugin_init() // that the next trigger would be the 2nd compute, hence ignoring the idle time // during the recv call. By updating at the beginning of a compute, we can // fix that. (If the cpu is not idle, this is not required.) - simgrid::s4u::Exec::on_start.connect([](simgrid::s4u::Exec const& activity) { + simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) { if (activity.get_host_number() == 1) { // We only run on one host simgrid::s4u::Host* host = activity.get_host(); const simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); diff --git a/src/plugins/host_load.cpp b/src/plugins/host_load.cpp index 3f95fb40c9..f2b14574e1 100644 --- a/src/plugins/host_load.cpp +++ b/src/plugins/host_load.cpp @@ -227,13 +227,13 @@ void sg_host_load_plugin_init() } // Make sure that every future host also gets an extension (in case the platform is not loaded yet) - simgrid::s4u::Host::on_creation.connect([](simgrid::s4u::Host& host) { + simgrid::s4u::Host::on_creation_cb([](simgrid::s4u::Host& host) { if (dynamic_cast(&host)) // Ignore virtual machines return; host.extension_set(new HostLoad(&host)); }); - simgrid::s4u::Exec::on_start.connect([](simgrid::s4u::Exec const& activity) { + simgrid::s4u::Exec::on_start_cb([](simgrid::s4u::Exec const& activity) { if (activity.get_host_number() == 1) { // We only run on one host simgrid::s4u::Host* host = activity.get_host(); const simgrid::s4u::VirtualMachine* vm = dynamic_cast(host); @@ -249,7 +249,7 @@ void sg_host_load_plugin_init() XBT_WARN("HostLoad plugin currently does not support executions on several hosts"); } }); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return; @@ -264,8 +264,8 @@ void sg_host_load_plugin_init() XBT_WARN("HostLoad plugin currently does not support executions on several hosts"); } }); - simgrid::s4u::Host::on_state_change.connect(&on_host_change); - simgrid::s4u::Host::on_speed_change.connect(&on_host_change); + simgrid::s4u::Host::on_state_change_cb(&on_host_change); + simgrid::s4u::Host::on_speed_change_cb(&on_host_change); } /** @brief Returns the current load of that host, as a ratio = achieved_flops / (core_current_speed * core_amount) diff --git a/src/plugins/link_energy.cpp b/src/plugins/link_energy.cpp index 37366fe9c0..078fd850d2 100644 --- a/src/plugins/link_energy.cpp +++ b/src/plugins/link_energy.cpp @@ -191,7 +191,7 @@ void sg_link_energy_plugin_init() xbt_assert(sg_host_count() == 0, "Please call sg_link_energy_plugin_init() before initializing the platform."); - simgrid::s4u::Link::on_creation.connect([](simgrid::s4u::Link& link) { + simgrid::s4u::Link::on_creation_cb([](simgrid::s4u::Link& link) { if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { XBT_DEBUG("Wired Link created: %s", link.get_cname()); link.extension_set(new LinkEnergy(&link)); @@ -200,12 +200,12 @@ void sg_link_energy_plugin_init() } }); - simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link const& link) { + simgrid::s4u::Link::on_state_change_cb([](simgrid::s4u::Link const& link) { if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) link.extension()->update(); }); - simgrid::s4u::Link::on_destruction.connect([](simgrid::s4u::Link const& link) { + simgrid::s4u::Link::on_destruction_cb([](simgrid::s4u::Link const& link) { if (link.get_name() != "__loopback__" && link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) XBT_INFO("Energy consumption of link '%s': %f Joules", link.get_cname(), link.extension()->get_consumed_energy()); @@ -214,7 +214,7 @@ void sg_link_energy_plugin_init() simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication); simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication); - simgrid::s4u::Engine::on_simulation_end.connect(&on_simulation_end); + simgrid::s4u::Engine::on_simulation_end_cb(&on_simulation_end); } /** @ingroup plugin_link_energy diff --git a/src/plugins/link_energy_wifi.cpp b/src/plugins/link_energy_wifi.cpp index eee76c6eb4..bee75ade7b 100644 --- a/src/plugins/link_energy_wifi.cpp +++ b/src/plugins/link_energy_wifi.cpp @@ -291,7 +291,7 @@ void sg_wifi_energy_plugin_init() * - Link::on_communication_state_change: to account for the energy when communications are updated * - CommImpl::on_start and CommImpl::on_completion: to account for the energy during communications */ - simgrid::s4u::Link::on_creation.connect([](simgrid::s4u::Link& link) { + simgrid::s4u::Link::on_creation_cb([](simgrid::s4u::Link& link) { // verify the link is appropriate to WiFi energy computations if (link.get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) { XBT_DEBUG("Wifi Link: %s, initialization of wifi energy plugin", link.get_cname()); @@ -302,7 +302,7 @@ void sg_wifi_energy_plugin_init() } }); - simgrid::s4u::Link::on_destruction.connect([](simgrid::s4u::Link const& link) { + simgrid::s4u::Link::on_destruction_cb([](simgrid::s4u::Link const& link) { // output energy values if WiFi link if (link.get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) { link.extension()->update_destroy(); @@ -314,16 +314,15 @@ void sg_wifi_energy_plugin_init() } }); - simgrid::s4u::Link::on_communication_state_change.connect( - [](simgrid::kernel::resource::NetworkAction const& action, - simgrid::kernel::resource::Action::State /* previous */) { - // update WiFi links encountered during the communication - for (auto const* link : action.get_links()) { - if (link != nullptr && link->get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) { - link->get_iface()->extension()->update(); - } - } - }); + simgrid::s4u::Link::on_communication_state_change_cb([](simgrid::kernel::resource::NetworkAction const& action, + simgrid::kernel::resource::Action::State /* previous */) { + // update WiFi links encountered during the communication + for (auto const* link : action.get_links()) { + if (link != nullptr && link->get_sharing_policy() == simgrid::s4u::Link::SharingPolicy::WIFI) { + link->get_iface()->extension()->update(); + } + } + }); simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication); simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication); diff --git a/src/plugins/link_load.cpp b/src/plugins/link_load.cpp index 5f60b67b8d..69b4397d38 100644 --- a/src/plugins/link_load.cpp +++ b/src/plugins/link_load.cpp @@ -189,7 +189,7 @@ void sg_link_load_plugin_init() LinkLoad::EXTENSION_ID = simgrid::s4u::Link::extension_create(); // Attach new LinkLoad links created in the future. - simgrid::s4u::Link::on_creation.connect([](simgrid::s4u::Link& link) { + simgrid::s4u::Link::on_creation_cb([](simgrid::s4u::Link& link) { if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { XBT_DEBUG("Wired link '%s' created. Attaching a LinkLoad to it.", link.get_cname()); link.extension_set(new LinkLoad(&link)); @@ -202,24 +202,23 @@ void sg_link_load_plugin_init() simgrid::kernel::activity::CommImpl::on_start.connect(&on_communication); simgrid::kernel::activity::CommImpl::on_completion.connect(&on_communication); - simgrid::s4u::Link::on_state_change.connect([](simgrid::s4u::Link const& link) { + simgrid::s4u::Link::on_state_change_cb([](simgrid::s4u::Link const& link) { if (link.get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { auto link_load = link.extension(); if (link_load->is_tracked()) link_load->update(); } }); - simgrid::s4u::Link::on_communication_state_change.connect( - [](simgrid::kernel::resource::NetworkAction const& action, - simgrid::kernel::resource::Action::State /* previous */) { - for (auto const* link : action.get_links()) { - if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { - auto link_load = link->get_iface()->extension(); - if (link_load->is_tracked()) - link_load->update(); - } - } - }); + simgrid::s4u::Link::on_communication_state_change_cb([](simgrid::kernel::resource::NetworkAction const& action, + simgrid::kernel::resource::Action::State /* previous */) { + for (auto const* link : action.get_links()) { + if (link != nullptr && link->get_sharing_policy() != simgrid::s4u::Link::SharingPolicy::WIFI) { + auto link_load = link->get_iface()->extension(); + if (link_load->is_tracked()) + link_load->update(); + } + } + }); } /** diff --git a/src/plugins/vm/VmLiveMigration.cpp b/src/plugins/vm/VmLiveMigration.cpp index 3dce9fbb2f..f4dd67457c 100644 --- a/src/plugins/vm/VmLiveMigration.cpp +++ b/src/plugins/vm/VmLiveMigration.cpp @@ -290,7 +290,7 @@ void sg_vm_live_migration_plugin_init() { sg_vm_dirty_page_tracking_init(); VmMigrationExt::ensureVmMigrationExtInstalled(); - simgrid::s4u::VirtualMachine::on_shutdown.connect(&onVirtualMachineShutdown); + simgrid::s4u::VirtualMachine::on_shutdown_cb(&onVirtualMachineShutdown); } simgrid::s4u::VirtualMachine* sg_vm_create_migratable(simgrid::s4u::Host* pm, const char* name, int coreAmount, diff --git a/src/plugins/vm/dirty_page_tracking.cpp b/src/plugins/vm/dirty_page_tracking.cpp index ff1f087790..f4ba064da6 100644 --- a/src/plugins/vm/dirty_page_tracking.cpp +++ b/src/plugins/vm/dirty_page_tracking.cpp @@ -115,9 +115,9 @@ void sg_vm_dirty_page_tracking_init() if (not DirtyPageTrackingExt::EXTENSION_ID.valid()) { DirtyPageTrackingExt::EXTENSION_ID = simgrid::kernel::resource::VirtualMachineImpl::extension_create(); - simgrid::s4u::VirtualMachine::on_creation.connect(&on_virtual_machine_creation); - simgrid::s4u::Exec::on_start.connect(&on_exec_creation); - simgrid::s4u::Activity::on_completion.connect(&on_exec_completion); + simgrid::s4u::VirtualMachine::on_creation_cb(&on_virtual_machine_creation); + simgrid::s4u::Exec::on_start_cb(&on_exec_creation); + simgrid::s4u::Activity::on_completion_cb(&on_exec_completion); } } diff --git a/src/smpi/bindings/smpi_f77_comm.cpp b/src/smpi/bindings/smpi_f77_comm.cpp index 91c80bb81d..6cd4ef3628 100644 --- a/src/smpi/bindings/smpi_f77_comm.cpp +++ b/src/smpi/bindings/smpi_f77_comm.cpp @@ -192,9 +192,10 @@ void mpi_comm_call_errhandler_ (int* comm,int* errorcode, int* ierr){ *ierr = MPI_Comm_call_errhandler(simgrid::smpi::Comm::f2c(*comm), *errorcode); } -void mpi_comm_connect_ ( char *port_name, int* info, int* root, int* comm, int*newcomm, int* ierr){ +void mpi_comm_connect_(char* port_name, int* info, int* root, int* comm, int* newcomm, int* ierr) +{ MPI_Comm tmp; - *ierr = MPI_Comm_connect( port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); + *ierr = MPI_Comm_connect(port_name, simgrid::smpi::Info::f2c(*info), *root, simgrid::smpi::Comm::f2c(*comm), &tmp); if(*ierr == MPI_SUCCESS) { *newcomm = tmp->c2f(); } diff --git a/src/smpi/bindings/smpi_mpi.cpp b/src/smpi/bindings/smpi_mpi.cpp index c1072a9312..471da2e6ea 100644 --- a/src/smpi/bindings/smpi_mpi.cpp +++ b/src/smpi/bindings/smpi_mpi.cpp @@ -408,7 +408,9 @@ UNIMPLEMENTED_WRAPPED_PMPI_CALL_NOFAIL(int,MPI_Add_error_string,( int errorcode, UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Cart_map,(MPI_Comm comm_old, int ndims, const int* dims, const int* periods, int* newrank) ,(comm_old, ndims, dims, periods, newrank)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Close_port,(const char *port_name),( port_name)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Comm_accept,(const char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm),( port_name, info, root, comm, newcomm)) -UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Comm_connect,(const char *port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm *newcomm),( port_name, info, root, comm, newcomm)) +UNIMPLEMENTED_WRAPPED_PMPI_CALL(int, MPI_Comm_connect, + (const char* port_name, MPI_Info info, int root, MPI_Comm comm, MPI_Comm* newcomm), + (port_name, info, root, comm, newcomm)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Comm_get_parent,( MPI_Comm *parent),( parent)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Comm_idup,( MPI_Comm comm, MPI_Comm *newcomm, MPI_Request* request),( comm, newcomm, request)) UNIMPLEMENTED_WRAPPED_PMPI_CALL(int,MPI_Comm_join,( int fd, MPI_Comm *intercomm),( fd, intercomm)) diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 2a8d1889ae..84c80df0a4 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -596,11 +596,11 @@ int smpi_main(const char* executable, int argc, char* argv[]) // Called either directly from the user code, or from the code called by smpirun void SMPI_init(){ smpi_init_options_internal(false); - simgrid::s4u::Actor::on_creation.connect([](simgrid::s4u::Actor& actor) { + simgrid::s4u::Actor::on_creation_cb([](simgrid::s4u::Actor& actor) { if (not actor.is_daemon()) actor.extension_set(new simgrid::smpi::ActorExt(&actor)); }); - simgrid::s4u::Host::on_creation.connect( + simgrid::s4u::Host::on_creation_cb( [](simgrid::s4u::Host& host) { host.extension_set(new simgrid::smpi::Host(&host)); }); for (auto const& host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) host->extension_set(new simgrid::smpi::Host(host)); diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 1ab07edfc2..b50b769426 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -39,9 +39,9 @@ void surf_network_model_init_IB() engine->add_model(net_model); engine->get_netzone_root()->set_network_model(net_model); - simgrid::s4u::Link::on_communication_state_change.connect(NetworkIBModel::IB_action_state_changed_callback); + simgrid::s4u::Link::on_communication_state_change_cb(NetworkIBModel::IB_action_state_changed_callback); simgrid::kernel::activity::CommImpl::on_start.connect(NetworkIBModel::IB_comm_start_callback); - simgrid::s4u::Host::on_creation.connect(NetworkIBModel::IB_create_host_callback); + simgrid::s4u::Host::on_creation_cb(NetworkIBModel::IB_create_host_callback); simgrid::config::set_default("network/weight-S", 8775); } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 82e59a5aa3..29435110a8 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -333,14 +333,14 @@ NetworkNS3Model::NetworkNS3Model(const std::string& name) : NetworkModel(name) XBT_VERB("Declare SimGrid's %s within ns-3", pt.get_cname()); }); - s4u::Engine::on_platform_created.connect([]() { + s4u::Engine::on_platform_created_cb([]() { /* Create the ns3 topology based on routing strategy */ ns3::GlobalRouteManager::BuildGlobalRoutingDatabase(); ns3::GlobalRouteManager::InitializeRoutes(); }); routing::on_cluster_creation.connect(&clusterCreation_cb); routing::NetZoneImpl::on_route_creation.connect(&routeCreation_cb); - s4u::NetZone::on_seal.connect(&zoneCreation_cb); + s4u::NetZone::on_seal_cb(&zoneCreation_cb); } LinkImpl* NetworkNS3Model::create_link(const std::string& name, const std::vector& bandwidths) diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index dd91fbfc03..a5a06d0414 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -56,7 +56,7 @@ void sg_platf_init() void sg_platf_exit() { simgrid::kernel::routing::on_cluster_creation.disconnect_slots(); - simgrid::s4u::Engine::on_platform_created.disconnect_slots(); + // simgrid::s4u::Engine::on_platform_created.disconnect_slots(); surf_parse_lex_destroy(); } diff --git a/src/surf/xml/surfxml_parseplatf.cpp b/src/surf/xml/surfxml_parseplatf.cpp index eb876f0a85..a7b5c95b5f 100644 --- a/src/surf/xml/surfxml_parseplatf.cpp +++ b/src/surf/xml/surfxml_parseplatf.cpp @@ -34,7 +34,8 @@ XBT_PRIVATE std::unordered_map trace_connect_list_link void sg_platf_trace_connect(simgrid::kernel::routing::TraceConnectCreationArgs* trace_connect) { surf_parse_assert(traces_set_list.find(trace_connect->trace) != traces_set_list.end(), - std::string("Cannot connect trace ")+ trace_connect->trace+ " to "+trace_connect->element+": trace unknown"); + std::string("Cannot connect trace ") + trace_connect->trace + " to " + trace_connect->element + + ": trace unknown"); switch (trace_connect->kind) { case simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL: @@ -106,7 +107,8 @@ void parse_platform_file(const std::string& file) /* connect all profiles relative to hosts */ for (auto const& elm : trace_connect_list_host_avail) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), + std::string(": Trace ") + elm.first + " undefined."); auto profile = traces_set_list.at(elm.first); auto host = engine->host_by_name_or_null(elm.second); @@ -115,7 +117,8 @@ void parse_platform_file(const std::string& file) } for (auto const& elm : trace_connect_list_host_speed) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), + std::string(": Trace ") + elm.first + " undefined."); auto profile = traces_set_list.at(elm.first); auto host = engine->host_by_name_or_null(elm.second); @@ -124,7 +127,8 @@ void parse_platform_file(const std::string& file) } for (auto const& elm : trace_connect_list_link_avail) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), + std::string(": Trace ") + elm.first + " undefined."); auto profile = traces_set_list.at(elm.first); auto link = engine->link_by_name_or_null(elm.second); @@ -133,7 +137,8 @@ void parse_platform_file(const std::string& file) } for (auto const& elm : trace_connect_list_link_bw) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), + std::string(": Trace ") + elm.first + " undefined."); auto profile = traces_set_list.at(elm.first); auto link = engine->link_by_name_or_null(elm.second); @@ -142,7 +147,8 @@ void parse_platform_file(const std::string& file) } for (auto const& elm : trace_connect_list_link_lat) { - surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), std::string(": Trace ")+elm.first+" undefined."); + surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(), + std::string(": Trace ") + elm.first + " undefined."); auto profile = traces_set_list.at(elm.first); auto link = engine->link_by_name_or_null(elm.second); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 05cff44352..aabf032dc0 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -193,17 +193,19 @@ void STag_surfxml_platform() { "Use simgrid_update_xml to update your file automatically. " "This program is installed automatically with SimGrid, or " "available in the tools/ directory of the source archive."); - surf_parse_assert((version >= 4.0), - std::string("******* THIS FILE IS TOO OLD (v:")+std::to_string(version)+") *********\n " - "Changes introduced in SimGrid 3.13:\n" - " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n" - " - In , attribute kind=\"POWER\" is now kind=\"SPEED\".\n" - " - DOCTYPE now point to the rignt URL.\n" - " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)" - "\n\n" - "Use simgrid_update_xml to update your file automatically. " - "This program is installed automatically with SimGrid, or " - "available in the tools/ directory of the source archive."); + surf_parse_assert( + (version >= 4.0), + std::string("******* THIS FILE IS TOO OLD (v:") + std::to_string(version) + + ") *********\n " + "Changes introduced in SimGrid 3.13:\n" + " - 'power' attribute of hosts (and others) got renamed to 'speed'.\n" + " - In , attribute kind=\"POWER\" is now kind=\"SPEED\".\n" + " - DOCTYPE now point to the rignt URL.\n" + " - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)" + "\n\n" + "Use simgrid_update_xml to update your file automatically. " + "This program is installed automatically with SimGrid, or " + "available in the tools/ directory of the source archive."); if (version < 4.1) { XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 " "That's fine, the new version is backward compatible. \n\n" @@ -659,27 +661,27 @@ void STag_surfxml_trace___connect() simgrid::kernel::routing::TraceConnectCreationArgs trace_connect; trace_connect.element = A_surfxml_trace___connect_element; - trace_connect.trace = A_surfxml_trace___connect_trace; + trace_connect.trace = A_surfxml_trace___connect_trace; switch (A_surfxml_trace___connect_kind) { - case AU_surfxml_trace___connect_kind: - case A_surfxml_trace___connect_kind_SPEED: - trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED; - break; - case A_surfxml_trace___connect_kind_BANDWIDTH: - trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH; - break; - case A_surfxml_trace___connect_kind_HOST___AVAIL: - trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL; - break; - case A_surfxml_trace___connect_kind_LATENCY: - trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY; - break; - case A_surfxml_trace___connect_kind_LINK___AVAIL: - trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL; - break; - default: - surf_parse_error("Invalid trace kind"); + case AU_surfxml_trace___connect_kind: + case A_surfxml_trace___connect_kind_SPEED: + trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::SPEED; + break; + case A_surfxml_trace___connect_kind_BANDWIDTH: + trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::BANDWIDTH; + break; + case A_surfxml_trace___connect_kind_HOST___AVAIL: + trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::HOST_AVAIL; + break; + case A_surfxml_trace___connect_kind_LATENCY: + trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LATENCY; + break; + case A_surfxml_trace___connect_kind_LINK___AVAIL: + trace_connect.kind = simgrid::kernel::routing::TraceConnectKind::LINK_AVAIL; + break; + default: + surf_parse_error("Invalid trace kind"); } sg_platf_trace_connect(&trace_connect); } @@ -808,7 +810,9 @@ void STag_surfxml_model___prop(){ void ETag_surfxml_prop(){/* Nothing to do */} void STag_surfxml_random(){/* Nothing to do */} void ETag_surfxml_random(){/* Nothing to do */} -void ETag_surfxml_trace___connect(){/* Nothing to do */} +void ETag_surfxml_trace___connect() +{ /* Nothing to do */ +} void STag_surfxml_trace() { /* Nothing to do */ } diff --git a/teshsuite/s4u/dependencies/dependencies.cpp b/teshsuite/s4u/dependencies/dependencies.cpp index e846943021..f0f2ba658f 100644 --- a/teshsuite/s4u/dependencies/dependencies.cpp +++ b/teshsuite/s4u/dependencies/dependencies.cpp @@ -13,7 +13,7 @@ int main(int argc, char** argv) xbt_assert(argc > 1, "Usage: %s platform_file\n\nExample: %s two_clusters.xml", argv[0], argv[0]); e.load_platform(argv[1]); - simgrid::s4u::Activity::on_completion.connect([](simgrid::s4u::Activity& activity) { + simgrid::s4u::Activity::on_completion_cb([](simgrid::s4u::Activity& activity) { const auto* exec = dynamic_cast(&activity); if (exec == nullptr) // Only Execs are concerned here return;