From: Martin Quinson Date: Tue, 15 Dec 2015 21:07:51 +0000 (+0100) Subject: give informative names to Host methods X-Git-Tag: v3_13~1442 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/eff13e323664f224576a26b017543955b3044b05?hp=4606a1dce740efe467e6b9033b804294d376de8f give informative names to Host methods --- diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp index a4e8ec5ed0..e914303e8b 100644 --- a/include/simgrid/Host.hpp +++ b/include/simgrid/Host.hpp @@ -23,8 +23,8 @@ public: Host(std::string id); ~Host(); std::string const& id() const { return id_; } - static Host* find_host(const char* name); - static Host* get_host(const char* name); + static Host* by_name_or_null(const char* name); + static Host* by_name_or_create(const char* name); }; } diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index 209e29620a..552ae8be6c 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -73,7 +73,7 @@ msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our paramete */ msg_host_t MSG_host_by_name(const char *name) { - return simgrid::Host::find_host(name); + return simgrid::Host::by_name_or_null(name); } /** \ingroup m_host_management diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 376392a9c9..1c3cb95a81 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -31,12 +31,12 @@ size_t sg_host_add_level(void(*deleter)(void*)) sg_host_t sg_host_by_name(const char *name) { - return simgrid::Host::find_host(name); + return simgrid::Host::by_name_or_null(name); } sg_host_t sg_host_by_name_or_create(const char *name) { - return simgrid::Host::get_host(name); + return simgrid::Host::by_name_or_create(name); } xbt_dynar_t sg_hosts_as_dynar(void) @@ -211,14 +211,14 @@ Host::~Host() { } -Host* Host::find_host(const char* name) +Host* Host::by_name_or_null(const char* name) { return (Host*) xbt_dict_get_or_null(host_list, name); } -Host* Host::get_host(const char* name) +Host* Host::by_name_or_create(const char* name) { - Host* host = find_host(name); + Host* host = by_name_or_null(name); if (host == nullptr) { host = new Host(name); xbt_dict_set(host_list, name, host, NULL); diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 955331aa57..a54d7337c9 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -53,7 +53,7 @@ Host *HostCLM03Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) netElm, cpu); surf_callback_emit(hostCreatedCallbacks, host); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); - simgrid::Host::find_host(name)->set_facet(SURF_HOST_LEVEL, host); + simgrid::Host::by_name_or_null(name)->set_facet(SURF_HOST_LEVEL, host); return host; } diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 20b4d50ede..82a0951719 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -275,7 +275,7 @@ Host *HostL07Model::createHost(const char *name,RoutingEdge *netElm, Cpu *cpu) HostL07 *host = new HostL07(this, name, NULL, netElm, cpu); surf_callback_emit(hostCreatedCallbacks, host); - simgrid::Host::get_host(name)->set_facet(SURF_HOST_LEVEL, host); + simgrid::Host::by_name_or_create(name)->set_facet(SURF_HOST_LEVEL, host); return host; } diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 40fbd0bef6..84996b1571 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -41,7 +41,7 @@ static void simgrid_ns3_add_host(simgrid::surf::Host* host) { const char* id = host->getName(); XBT_DEBUG("NS3_ADD_HOST '%s'", id); - simgrid::Host::get_host(id)->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); + simgrid::Host::by_name_or_create(id)->set_facet(NS3_HOST_LEVEL, ns3_add_host(id)); } static void parse_ns3_add_link(sg_platf_link_cbarg_t link) @@ -108,7 +108,7 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *)); xbt_dynar_push_as(tab_elements_num, int, start); router_id = bprintf("ns3_%s%d%s", cluster_prefix, start, cluster_suffix); - simgrid::Host::get_host(router_id) + simgrid::Host::by_name_or_create(router_id) ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); @@ -120,7 +120,7 @@ static void parse_ns3_add_cluster(sg_platf_cluster_cbarg_t cluster) for (i = start; i <= end; i++){ xbt_dynar_push_as(tab_elements_num, int, i); router_id = bprintf("ns3_%s%d%s", cluster_prefix, i, cluster_suffix); - simgrid::Host::get_host(router_id) + simgrid::Host::by_name_or_create(router_id) ->set_facet(NS3_HOST_LEVEL, ns3_add_host_cluster(router_id)); XBT_DEBUG("NS3_ADD_ROUTER '%s'",router_id); free(router_id); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 433de56176..b267423760 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -196,7 +196,7 @@ simgrid::surf::RoutingEdge *routing_add_host( } xbt_dynar_shrink(ctn, 0); xbt_dynar_free(&ctn_str); - simgrid::Host::get_host(host->id)->set_facet(COORD_HOST_LEVEL, (void *) ctn); + simgrid::Host::by_name_or_create(host->id)->set_facet(COORD_HOST_LEVEL, (void *) ctn); XBT_DEBUG("Having set host coordinates for '%s'",host->id); } @@ -1339,7 +1339,7 @@ xbt_dynar_t surf_AS_get_hosts(simgrid::surf::As *as) for (int index = 0; index < count; index++) { sg_routing_edge_t relm = xbt_dynar_get_as(elms, index, simgrid::surf::RoutingEdge*); - sg_host_t delm = simgrid::Host::find_host(relm->getName()); + sg_host_t delm = simgrid::Host::by_name_or_null(relm->getName()); if (delm!=NULL) { xbt_dynar_push(res, &delm); } diff --git a/src/surf/surf_routing_vivaldi.cpp b/src/surf/surf_routing_vivaldi.cpp index 315369c432..3281f1edb4 100644 --- a/src/surf/surf_routing_vivaldi.cpp +++ b/src/surf/surf_routing_vivaldi.cpp @@ -57,9 +57,9 @@ void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_ *lat += static_cast(info.link_up)->getLatency(); } } - src_ctn = (xbt_dynar_t) simgrid::Host::get_host(tmp_src_name)->facet(COORD_HOST_LEVEL); + src_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(tmp_src_name)->facet(COORD_HOST_LEVEL); if (src_ctn == nullptr) - src_ctn = (xbt_dynar_t) simgrid::Host::get_host(src->getName())->facet(COORD_HOST_LEVEL); + src_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(src->getName())->facet(COORD_HOST_LEVEL); } else if(src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_AS){ tmp_src_name = ROUTER_PEER(src->getName()); @@ -80,10 +80,10 @@ void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_ *lat += static_cast(info.link_down)->getLatency(); } } - dst_ctn = (xbt_dynar_t) simgrid::Host::get_host(tmp_dst_name) + dst_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(tmp_dst_name) ->facet(COORD_HOST_LEVEL); if (dst_ctn == nullptr) - dst_ctn = (xbt_dynar_t) simgrid::Host::get_host(dst->getName()) + dst_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(dst->getName()) ->facet(COORD_HOST_LEVEL); } else if(dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || dst->getRcType() == SURF_NETWORK_ELEMENT_AS){ diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index eaac5bb22c..9be8a78fa9 100644 --- a/src/surf/virtual_machine.cpp +++ b/src/surf/virtual_machine.cpp @@ -38,7 +38,7 @@ VirtualMachine::VirtualMachine(Model *model, const char *name, xbt_dict_t props, : Host(model, name, props, NULL, netElm, cpu) { VMModel::ws_vms.push_back(*this); - simgrid::Host::get_host(name)->set_facet(SURF_HOST_LEVEL, this); + simgrid::Host::by_name_or_create(name)->set_facet(SURF_HOST_LEVEL, this); } /* @@ -62,7 +62,7 @@ void VirtualMachine::setState(e_surf_resource_state_t state){ **/ sg_host_t VirtualMachine::getPm() { - return simgrid::Host::find_host(p_subWs->getName()); + return simgrid::Host::by_name_or_null(p_subWs->getName()); } /********** diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index c2ff00aac2..c0f76ca122 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -338,7 +338,7 @@ void VMHL13::setAffinity(Cpu *cpu, unsigned long mask){ sg_host_t VMHL13::getPm() { // TODO, store pointer to the PM? - return simgrid::Host::find_host(p_subWs->getName()); + return simgrid::Host::by_name_or_null(p_subWs->getName()); } /* Adding a task to a VM updates the VCPU task on its physical machine. */