From 05e7b862d160f556d0430f55a3af784bcd44bd72 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 13 Feb 2017 23:01:28 +0100 Subject: [PATCH] move the Link signals to s4u --- include/simgrid/s4u/Link.hpp | 23 +++++++++++++++++++++-- src/s4u/s4u_link.cpp | 9 +++++++++ src/surf/instr_routing.cpp | 2 +- src/surf/network_cm02.cpp | 6 ++---- src/surf/network_constant.cpp | 2 +- src/surf/network_ib.cpp | 12 ++++-------- src/surf/network_interface.cpp | 20 ++++---------------- src/surf/network_interface.hpp | 15 --------------- src/surf/ptask_L07.cpp | 2 +- 9 files changed, 43 insertions(+), 48 deletions(-) diff --git a/include/simgrid/s4u/Link.hpp b/include/simgrid/s4u/Link.hpp index 05a3636368..af44cb4dcf 100644 --- a/include/simgrid/s4u/Link.hpp +++ b/include/simgrid/s4u/Link.hpp @@ -10,8 +10,7 @@ #include -#include "xbt/dict.h" -#include "xbt/fifo.h" +#include "xbt/signal.hpp" #include "simgrid/link.h" @@ -20,6 +19,10 @@ ***********/ namespace simgrid { +namespace surf { +class NetworkAction; +class Action; +}; namespace s4u { /** @brief A Link represents the network facilities between [hosts](\ref simgrid::s4u::Host) */ class Link { @@ -64,6 +67,22 @@ public: external load). Trace must contain percentages (value between 0 and 1). */ void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to external load). Trace must contain absolute values */ + + /* The signals */ + /** @brief Callback signal fired when a new Link is created */ + static simgrid::xbt::signal onCreation; + + /** @brief Callback signal fired when a Link is destroyed */ + static simgrid::xbt::signal onDestruction; + + /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */ + static simgrid::xbt::signal onStateChange; + + /** @brief Callback signal fired when a communication starts */ + static simgrid::xbt::signal onCommunicate; + + /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */ + static simgrid::xbt::signal onCommunicationStateChange; }; } } diff --git a/src/s4u/s4u_link.cpp b/src/s4u/s4u_link.cpp index f4b2d93cf1..3f719e5df7 100644 --- a/src/s4u/s4u_link.cpp +++ b/src/s4u/s4u_link.cpp @@ -148,5 +148,14 @@ void Link::setLatencyTrace(tmgr_trace_t trace) this->pimpl_->setLatencyTrace(trace); }); } + +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Link::onCreation; +simgrid::xbt::signal Link::onDestruction; +simgrid::xbt::signal Link::onStateChange; +simgrid::xbt::signal Link::onCommunicate; +simgrid::xbt::signal Link::onCommunicationStateChange; } } diff --git a/src/surf/instr_routing.cpp b/src/surf/instr_routing.cpp index 89e978735f..00b25553d1 100644 --- a/src/surf/instr_routing.cpp +++ b/src/surf/instr_routing.cpp @@ -324,7 +324,7 @@ void instr_routing_define_callbacks () //always need the call backs to ASes (we need only the root AS), //to create the rootContainer and the rootType properly if (!TRACE_needs_platform()) return; - simgrid::surf::LinkImpl::onCreation.connect(instr_routing_parse_start_link); + simgrid::s4u::Link::onCreation.connect(instr_routing_parse_start_link); simgrid::s4u::onPlatformCreated.connect(instr_routing_parse_end_platform); } diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 7f4e90010e..51b26dac50 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -377,7 +377,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz delete back_route; XBT_OUT(); - LinkImpl::onCommunicate(action, src, dst); + simgrid::s4u::Link::onCommunicate(action, src, dst); return action; } @@ -401,11 +401,9 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const char* name, doub if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(constraint()); - LinkImpl::onCreation(this); + simgrid::s4u::Link::onCreation(this); } - - void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value) { diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index 7dc5c255f7..e2675fcb5e 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -78,7 +78,7 @@ namespace simgrid { { NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor); - LinkImpl::onCommunicate(action, src, dst); + simgrid::s4u::Link::onCommunicate(action, src, dst); return action; } diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 64e9649b78..41fa93c82c 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -29,14 +29,12 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){ xbt_dict_set(((NetworkIBModel*)surf_network_model)->active_nodes, host.cname(), act, nullptr); } -static void IB_action_state_changed_callback( - simgrid::surf::NetworkAction *action, - simgrid::surf::Action::State statein, simgrid::surf::Action::State stateout) +static void IB_action_state_changed_callback(simgrid::surf::NetworkAction* action) { using simgrid::surf::NetworkIBModel; using simgrid::surf::IBNode; - if(statein!=simgrid::surf::Action::State::running || stateout!=simgrid::surf::Action::State::done) + if (action->getState() != simgrid::surf::Action::State::done) return; std::pair pair = ((NetworkIBModel*)surf_network_model)->active_comms[action]; XBT_DEBUG("IB callback - action %p finished", action); @@ -79,15 +77,13 @@ static void IB_action_init_callback(simgrid::surf::NetworkAction* action, simgri /* } */ void surf_network_model_init_IB() { - using simgrid::surf::networkActionStateChangedCallbacks; - if (surf_network_model) return; surf_network_model = new simgrid::surf::NetworkIBModel(); all_existing_models->push_back(surf_network_model); - networkActionStateChangedCallbacks.connect(IB_action_state_changed_callback); - simgrid::surf::LinkImpl::onCommunicate.connect(IB_action_init_callback); + simgrid::s4u::Link::onCommunicationStateChange.connect(IB_action_state_changed_callback); + simgrid::s4u::Link::onCommunicate.connect(IB_action_init_callback); simgrid::s4u::Host::onCreation.connect(IB_create_host_callback); xbt_cfg_setdefault_double("network/weight-S", 8775); diff --git a/src/surf/network_interface.cpp b/src/surf/network_interface.cpp index f88f52b66e..7f1e590ef7 100644 --- a/src/surf/network_interface.cpp +++ b/src/surf/network_interface.cpp @@ -48,17 +48,6 @@ namespace simgrid { (kv.second)->destroy(); delete links; } - - /************* - * Callbacks * - *************/ - - simgrid::xbt::signal LinkImpl::onCreation; - simgrid::xbt::signal LinkImpl::onDestruction; - simgrid::xbt::signal LinkImpl::onStateChange; - - simgrid::xbt::signal networkActionStateChangedCallbacks; - simgrid::xbt::signal LinkImpl::onCommunicate; } } @@ -137,7 +126,7 @@ namespace simgrid { { if (!currentlyDestroying_) { currentlyDestroying_ = true; - onDestruction(this); + s4u::Link::onDestruction(this); delete this; } } @@ -166,14 +155,14 @@ namespace simgrid { { if (isOff()) { Resource::turnOn(); - onStateChange(this); + s4u::Link::onStateChange(this); } } void LinkImpl::turnOff() { if (isOn()) { Resource::turnOff(); - onStateChange(this); + s4u::Link::onStateChange(this); } } void LinkImpl::setStateTrace(tmgr_trace_t trace) @@ -198,9 +187,8 @@ namespace simgrid { **********/ void NetworkAction::setState(Action::State state){ - Action::State old = getState(); Action::setState(state); - networkActionStateChangedCallbacks(this, old, state); + s4u::Link::onCommunicationStateChange(this); } } diff --git a/src/surf/network_interface.hpp b/src/surf/network_interface.hpp index 25c3d61e82..6c1d47d7fa 100644 --- a/src/surf/network_interface.hpp +++ b/src/surf/network_interface.hpp @@ -28,10 +28,6 @@ namespace simgrid { class NetworkAction; - /** @brief Callback signal fired when the state of a NetworkAction changes - * Signature: `void(NetworkAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */ - XBT_PUBLIC_DATA(simgrid::xbt::signal) networkActionStateChangedCallbacks; - /********* * Model * *********/ @@ -137,17 +133,6 @@ namespace simgrid { public: /** @brief Public interface */ s4u::Link piface_; - /** @brief Callback signal fired when a new Link is created */ - static simgrid::xbt::signal onCreation; - - /** @brief Callback signal fired when a Link is destroyed */ - static simgrid::xbt::signal onDestruction; - - /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */ - static simgrid::xbt::signal onStateChange; - - /** @brief Callback signal fired when a communication starts */ - static simgrid::xbt::signal onCommunicate; /** @brief Get the bandwidth in bytes per second of current Link */ virtual double bandwidth(); diff --git a/src/surf/ptask_L07.cpp b/src/surf/ptask_L07.cpp index 2f0ccdcaa4..8e90e0618d 100644 --- a/src/surf/ptask_L07.cpp +++ b/src/surf/ptask_L07.cpp @@ -273,7 +273,7 @@ LinkL07::LinkL07(NetworkL07Model* model, const char* name, double bandwidth, dou if (policy == SURF_LINK_FATPIPE) lmm_constraint_shared(constraint()); - LinkImpl::onCreation(this); + s4u::Link::onCreation(this); } Action *CpuL07::execution_start(double size) -- 2.20.1