From: Martin Quinson Date: Sun, 20 Dec 2015 22:09:03 +0000 (+0100) Subject: make the host callbacks static to surf::Host instead of globals X-Git-Tag: v3_13~1422 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d68f666f1af96f557cd6fe7503703358439ca188 make the host callbacks static to surf::Host instead of globals --- diff --git a/src/surf/callbacks.cpp b/src/surf/callbacks.cpp index 22b2bc4144..78705cbfad 100644 --- a/src/surf/callbacks.cpp +++ b/src/surf/callbacks.cpp @@ -12,7 +12,7 @@ void surf_on_host_created(void (*callback)(sg_host_t)) { - simgrid::surf::hostCreatedCallbacks.connect([callback](simgrid::surf::Host* host) { + simgrid::surf::Host::creationCallbacks.connect([callback](simgrid::surf::Host* host) { const char* id = host->getName(); sg_host_t h = sg_host_by_name(id); xbt_assert(h != NULL, "Host not found for name %s", id); diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index 0dcf34b568..e7014c2ba0 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -33,11 +33,6 @@ namespace surf { simgrid::xbt::Extension Host::EXTENSION_ID; -simgrid::surf::signal hostCreatedCallbacks; -simgrid::surf::signal hostDestructedCallbacks; -simgrid::surf::signal hostStateChangedCallbacks; -simgrid::surf::signal hostActionStateChangedCallbacks; - /********* * Model * *********/ @@ -80,6 +75,9 @@ void HostModel::adjustWeightOfDummyCpuActions() /************ * Resource * ************/ +simgrid::surf::signal Host::creationCallbacks; +simgrid::surf::signal Host::destructionCallbacks; +simgrid::surf::signal Host::stateChangeCallbacks; void Host::init() { @@ -101,7 +99,7 @@ Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props, Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu) : Resource(model, name, constraint) -, PropertyHolder(props) + , PropertyHolder(props) , p_storage(storage), p_netElm(netElm), p_cpu(cpu) { p_params.ramsize = 0; @@ -109,7 +107,7 @@ Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props, lmm_ void Host::onDie() { - hostDestructedCallbacks(this); + destructionCallbacks(this); Resource::onDie(); } @@ -124,13 +122,13 @@ void Host::attach(simgrid::Host* host) xbt_die("Already attached to host %s", host->id().c_str()); host->extension_set(this); p_host = host; - hostCreatedCallbacks(this); + creationCallbacks(this); } void Host::setState(e_surf_resource_state_t state){ e_surf_resource_state_t old = Resource::getState(); Resource::setState(state); - hostStateChangedCallbacks(this, old, state); + stateChangeCallbacks(this, old, state); p_cpu->setState(state); } @@ -374,11 +372,12 @@ void Host::setParams(vm_params_t params) /********** * Action * **********/ +simgrid::surf::signal HostAction::stateChangeCallbacks; void HostAction::setState(e_surf_action_state_t state){ e_surf_action_state_t old = getState(); Action::setState(state); - hostActionStateChangedCallbacks(this, old, state); + stateChangeCallbacks(this, old, state); } } diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index 8fde63d95d..fa34643ec9 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -26,29 +26,6 @@ class XBT_PRIVATE HostModel; class XBT_PRIVATE Host; class XBT_PRIVATE HostAction; -/************* - * Callbacks * - *************/ - -/** @ingroup SURF_callbacks - * @brief Callbacks fired after Host creation. Signature: `void(Host*)` - */ -XBT_PUBLIC_DATA(simgrid::surf::signal) hostCreatedCallbacks; - -/** @ingroup SURF_callbacks - * @brief Callbacks fired Host destruction. Signature: `void(Host*)` - */ -XBT_PUBLIC_DATA(simgrid::surf::signal) hostDestructedCallbacks; - -/** @ingroup SURF_callbacks - * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)` - */ -XBT_PUBLIC_DATA(simgrid::surf::signal) hostStateChangedCallbacks; - -/** @ingroup SURF_callbacks - * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)` - */ -XBT_PUBLIC_DATA(simgrid::surf::signal) hostActionStateChangedCallbacks; } } @@ -70,7 +47,7 @@ namespace surf { * @brief SURF Host model interface class * @details A model is an object which handle the interactions between its Resources and its Actions */ -class HostModel : public Model { +class HostModel : public Model{ public: HostModel() : Model() {} ~HostModel() {} @@ -99,6 +76,13 @@ class Host : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder { public: static simgrid::xbt::Extension EXTENSION_ID; + + /* callbacks */ + static simgrid::surf::signal creationCallbacks; /** Called on each newly created object */ + static simgrid::surf::signal destructionCallbacks; /** Called just before destructing an object */ + static simgrid::surf::signal stateChangeCallbacks; + +public: static void init(); /** * @brief Host constructor @@ -292,6 +276,8 @@ private: */ class HostAction : public Action { public: + static simgrid::surf::signal stateChangeCallbacks; + /** * @brief HostAction constructor * diff --git a/src/surf/network_constant.cpp b/src/surf/network_constant.cpp index c6bd1b314e..9f045db18f 100644 --- a/src/surf/network_constant.cpp +++ b/src/surf/network_constant.cpp @@ -27,7 +27,7 @@ void surf_network_model_init_Constant() routing_model_create(NULL); - simgrid::surf::hostCreatedCallbacks.connect([](simgrid::surf::Host*) { + simgrid::surf::Host::creationCallbacks.connect([](simgrid::surf::Host*) { host_number_int++; }); sg_platf_link_add_cb(netcste_parse_nolink); diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 1ba7a30004..86db6aa05b 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -91,7 +91,6 @@ void surf_network_model_init_IB(void) { using simgrid::surf::networkActionStateChangedCallbacks; using simgrid::surf::networkCommunicateCallbacks; - using simgrid::surf::hostCreatedCallbacks; if (surf_network_model) return; @@ -100,7 +99,7 @@ void surf_network_model_init_IB(void) xbt_dynar_push(all_existing_models, &surf_network_model); networkActionStateChangedCallbacks.connect(IB_action_state_changed_callback); networkCommunicateCallbacks.connect(IB_action_init_callback); - hostCreatedCallbacks.connect(IB_create_host_callback); + simgrid::surf::Host::creationCallbacks.connect(IB_create_host_callback); xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", 8775); } diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index b8b19cd6b7..cbfde2c015 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -142,13 +142,13 @@ void sg_energy_plugin_init() { if (simgrid::energy::surf_energy == NULL) { simgrid::energy::surf_energy = new std::map(); - simgrid::surf::hostCreatedCallbacks.connect(energyHostCreatedCallback); simgrid::surf::VMCreatedCallbacks.connect(energyVMCreatedCallback); - simgrid::surf::hostDestructedCallbacks.connect(energyHostDestructedCallback); + simgrid::surf::Host::creationCallbacks.connect(energyHostCreatedCallback); + simgrid::surf::Host::destructionCallbacks.connect(energyHostDestructedCallback); simgrid::surf::cpuActionStateChangedCallbacks.connect( energyCpuActionStateChangedCallback); simgrid::surf::surfExitCallbacks.connect(sg_energy_plugin_exit); - simgrid::surf::hostStateChangedCallbacks.connect( + simgrid::surf::Host::stateChangeCallbacks.connect( energyStateChangedCallback); } } diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 1110ef12c3..3935c9606c 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -302,7 +302,7 @@ void surf_init(int *argc, char **argv) { XBT_DEBUG("Create all Libs"); host_list = xbt_dict_new_homogeneous([](void*p) { - delete (simgrid::Host*)p; + delete static_cast(p); }); as_router_lib = xbt_lib_new(); storage_lib = xbt_lib_new();