From: Martin Quinson Date: Sat, 26 Mar 2016 14:42:33 +0000 (+0100) Subject: Factorize some code into the netcard constructor X-Git-Tag: v3_13~273 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4eb138c5bdd15c411d68931cb43d93a75f0cc817?hp=28200591a8ba30e8b362400419b03bc94205198e Factorize some code into the netcard constructor --- diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 9dfdc53525..ea7814cd7a 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -82,10 +82,8 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host) simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing); - netcard->setId(current_routing->addComponent(netcard)); sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id); h->pimpl_netcard = netcard; - simgrid::surf::netcardCreatedCallbacks(netcard); if(mount_list){ xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list); @@ -142,10 +140,8 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router) simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing); - netcard->setId(current_routing->addComponent(netcard)); xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) netcard); XBT_DEBUG("Having set name '%s' id '%d'", router->id, netcard->id()); - simgrid::surf::netcardCreatedCallbacks(netcard); if (router->coord && strcmp(router->coord, "")) { unsigned int cursor; @@ -925,10 +921,8 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) /* make a new routing component */ simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->name(), SURF_NETWORK_ELEMENT_AS, current_routing); - if (current_routing == NULL && routing_platf->root_ == NULL) { - /* it is the first one */ + if (current_routing == NULL && routing_platf->root_ == NULL) { /* it is the first one */ routing_platf->root_ = new_as; - netcard->setId(-1); } else if (current_routing != NULL && routing_platf->root_ != NULL) { xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id), @@ -940,8 +934,6 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) current_routing->hierarchy_ = simgrid::surf::AsImpl::RoutingMode::recursive; /* add to the sons dictionary */ xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, NULL); - /* add to the father element list */ - netcard->setId(current_routing->addComponent(netcard)); } else { THROWF(arg_error, 0, "All defined components must belong to a AS"); } @@ -953,7 +945,6 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS) current_routing = new_as; current_routing->netcard_ = netcard; - simgrid::surf::netcardCreatedCallbacks(netcard); simgrid::surf::asCreatedCallbacks(new_as); if (TRACE_is_enabled()) sg_instr_AS_begin(AS); diff --git a/src/surf/surf_routing.hpp b/src/surf/surf_routing.hpp index 2e049100d2..ccbb7d63ae 100644 --- a/src/surf/surf_routing.hpp +++ b/src/surf/surf_routing.hpp @@ -27,6 +27,9 @@ SG_END_DECL() namespace simgrid { namespace surf { + XBT_PUBLIC_DATA(simgrid::xbt::signal) asCreatedCallbacks; + XBT_PUBLIC_DATA(simgrid::xbt::signal) netcardCreatedCallbacks; + /*********** * Classes * ***********/ @@ -43,7 +46,6 @@ class NetCard { public: virtual ~NetCard(){}; virtual int id()=0; // Our rank in the vertices_ array of our containing AS. - virtual void setId(int id)=0; virtual char *name()=0; virtual AsImpl *containingAS()=0; // This is the AS in which I am virtual bool isAS()=0; @@ -53,15 +55,18 @@ public: struct XBT_PRIVATE NetCardImpl : public NetCard { public: - NetCardImpl(const char *name, e_surf_network_element_type_t componentType, AsImpl *as) + NetCardImpl(const char *name, e_surf_network_element_type_t componentType, AsImpl *containingAS) : name_(xbt_strdup(name)), componentType_(componentType), - containingAS_(as) - {} + containingAS_(containingAS) + { + if (containingAS != nullptr) + id_ = containingAS->addComponent(this); + simgrid::surf::netcardCreatedCallbacks(this); + } ~NetCardImpl() { xbt_free(name_);}; int id() override {return id_;} - void setId(int id) override {id_ = id;} char *name() override {return name_;} AsImpl *containingAS() override {return containingAS_;} @@ -101,13 +106,6 @@ public: void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector * links, double *latency); }; -/************* - * Callbacks * - *************/ - -XBT_PUBLIC_DATA(simgrid::xbt::signal) netcardCreatedCallbacks; -XBT_PUBLIC_DATA(simgrid::xbt::signal) asCreatedCallbacks; - } }