From: Martin Quinson Date: Fri, 18 Dec 2015 23:39:49 +0000 (+0100) Subject: rename facets to extensions for clarity sake X-Git-Tag: v3_13~1424 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/9ba3bfdef0f13d77474c16059ca813b75ade43ab rename facets to extensions for clarity sake --- diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp index e1d2999faa..c887ee7431 100644 --- a/include/simgrid/Host.hpp +++ b/include/simgrid/Host.hpp @@ -13,12 +13,12 @@ #include #include -#include #include +#include namespace simgrid { -XBT_PUBLIC_CLASS Host : public simgrid::xbt::Facetable { +XBT_PUBLIC_CLASS Host : public simgrid::xbt::Extendable { private: simgrid::xbt::string id_; public: diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 83bba0b707..166915901c 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -21,10 +21,10 @@ SG_BEGIN_DECL() XBT_PUBLIC(size_t) sg_host_count(); -XBT_PUBLIC(size_t) sg_host_add_level(void(*deleter)(void*)); +XBT_PUBLIC(size_t) sg_host_extension_create(void(*deleter)(void*)); +XBT_PUBLIC(void*) sg_host_extension_get(sg_host_t host, size_t rank); XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name); XBT_PUBLIC(sg_host_t) sg_host_by_name_or_create(const char *name); -XBT_PUBLIC(void*) sg_host_get_facet(sg_host_t host, size_t facet); XBT_PUBLIC(const char*) sg_host_get_name(sg_host_t host); XBT_PUBLIC(xbt_dynar_t) sg_hosts_as_dynar(void); diff --git a/include/xbt/Extendable.hpp b/include/xbt/Extendable.hpp new file mode 100644 index 0000000000..81e7150625 --- /dev/null +++ b/include/xbt/Extendable.hpp @@ -0,0 +1,125 @@ +/* Copyright (c) 2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef SIMGRID_XBT_LIB_HPP +#define SIMGRID_XBT_LIB_HPP + +#include +#include +#include + +namespace simgrid { +namespace xbt { + +template class Extension; +template class Extendable; + +template +class Extension { + static const std::size_t INVALID_ID = std::numeric_limits::max(); + std::size_t id_; + friend class Extendable; + constexpr Extension(std::size_t id) : id_(id) {} +public: + constexpr Extension() : id_(INVALID_ID) {} + std::size_t id() const { return id_; } + bool valid() { return id_ != INVALID_ID; } +}; + +/** An Extendable is an object that you can extend with external elements. + * + * An Extension is one dimension of such extension. They are similar to the concept of mixins, that is, a set of behavior that is injected into a class without derivation. + * + * Imagine that you want to write a plugin dealing with the energy in SimGrid. + * You will have to store some information about each and every host. + * + * You could modify the Host class directly (but your code will soon become messy). + * You could create a class EnergyHost deriving Host, but it is not easily combinable + * with a notion of Host extended with another concept (such as mobility). + * You could completely externalize these data with an associative map Host->EnergyHost. + * It would work, provided that you implement this classical feature correctly (and it would induce a little performance penalty). + * Instead, you should add a new facet to the Host class, that happens to be Facetable. + * + */ +template +class Extendable { +private: + static std::vector deleters_; +protected: + std::vector extensions_; +public: + static size_t extension_create(void (*deleter)(void*)) + { + std::size_t res = deleters_.size(); + deleters_.push_back(deleter); + return res; + } + template + static Extension extension_create(void (*deleter)(void*)) + { + return Extension(extension_create(deleter)); + } + template static + Extension extension_create() + { + return extension_create([](void* p){ delete static_cast(p); }); + } + Extendable() : extensions_(deleters_.size(), nullptr) {} + ~Extendable() + { + /* Call destructors in reverse order of their registrations + * + * The rationale for this, is that if an extension B as been added after + * an extension A, the subsystem of B might depend on the subsystem on A and + * an extension of B might need to have the extension of A around when executing + * its cleanup function/destructor. */ + for (std::size_t i = extensions_.size(); i > 0; --i) + if (extensions_[i - 1] != nullptr) + deleters_[i - 1](extensions_[i - 1]); + } + + // Type-unsafe versions of the facet access methods: + void* extension(std::size_t rank) + { + if (rank >= extensions_.size()) + return nullptr; + else + return extensions_.at(rank); + } + void extension_set(std::size_t rank, void* value, bool use_dtor = true) + { + if (rank >= extensions_.size()) + extensions_.resize(rank + 1, nullptr); + void* old_value = this->extension(rank); + extensions_.at(rank) = value; + if (use_dtor && old_value != nullptr && deleters_[rank]) + deleters_[rank](old_value); + } + + // Type safe versions of the facet access methods: + template + U* extension(Extension rank) + { + return static_cast(extension(rank.id())); + } + template + void extension_set(Extension rank, U* value, bool use_dtor = true) + { + extension_set(rank.id(), value, use_dtor); + } + + // Convenience extension access when the type has a associated EXTENSION ID: + template U* extension() { return extension(U::EXTENSION_ID); } + template void extension_set(U* p) { extension_set(U::EXTENSION_ID, p); } +}; + +template +std::vector Extendable::deleters_ = {}; + +} +} + +#endif diff --git a/include/xbt/Facetable.hpp b/include/xbt/Facetable.hpp deleted file mode 100644 index 34bd0725e7..0000000000 --- a/include/xbt/Facetable.hpp +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (c) 2015. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef SIMGRID_XBT_LIB_HPP -#define SIMGRID_XBT_LIB_HPP - -#include -#include -#include - -namespace simgrid { -namespace xbt { - -template class FacetLevel; -template class Facetable; - -template -class FacetLevel { - static const std::size_t INVALID_ID = std::numeric_limits::max(); - std::size_t id_; - friend class Facetable; - constexpr FacetLevel(std::size_t id) : id_(id) {} -public: - constexpr FacetLevel() : id_(INVALID_ID) {} - std::size_t id() const { return id_; } - bool valid() { return id_ != INVALID_ID; } -}; - -/** A Facetable is an object that you can extend with external facets. - * - * Facets are similar to the concept of mixins, that is, a set of behavior that is injected into a class without derivation. - * - * Imagine that you want to write a plugin dealing with the energy in SimGrid. - * You will have to store some information about each and every host. - * - * You could modify the Host class directly (but your code will soon become messy). - * You could create a class EnergyHost deriving Host, but it is not easily combinable - * with a notion of Host extended with another concept (such as mobility). - * You could completely externalize these data with an associative map Host->EnergyHost. - * It would work, provided that you implement this classical feature correctly (and it would induce a little performance penalty). - * Instead, you should add a new facet to the Host class, that happens to be Facetable. - * - */ -template -class Facetable { -private: - static std::vector deleters_; -protected: - std::vector facets_; -public: - static size_t add_level(void (*deleter)(void*)) - { - std::size_t res = deleters_.size(); - deleters_.push_back(deleter); - return res; - } - template - static FacetLevel add_level(void (*deleter)(void*)) - { - return FacetLevel(add_level(deleter)); - } - template static - FacetLevel add_level() - { - return add_level([](void* p){ delete static_cast(p); }); - } - Facetable() : facets_(deleters_.size(), nullptr) {} - ~Facetable() - { - /* Call destructors in reverse order of their registrations - * - * The rationale for this, is that if a level B as been added after a - * facet A, the subsystem of B might depend on the subsystem on A and a - * facet of B might need to have the facet of A around when executing - * its cleanup function/destructor. */ - for (std::size_t i = facets_.size(); i > 0; --i) - if (facets_[i - 1] != nullptr) - deleters_[i - 1](facets_[i - 1]); - } - - // Type-unsafe versions of the facet access methods: - void* facet(std::size_t level) - { - if (level >= facets_.size()) - return nullptr; - else - return facets_.at(level); - } - void set_facet(std::size_t level, void* value, bool use_dtor = true) - { - if (level >= facets_.size()) - facets_.resize(level + 1, nullptr); - void* old_value = this->facet(level); - facets_.at(level) = value; - if (use_dtor && old_value != nullptr && deleters_[level]) - deleters_[level](old_value); - } - - // Type safe versions of the facet access methods: - template - U* facet(FacetLevel level) - { - return static_cast(facet(level.id())); - } - template - void set_facet(FacetLevel level, U* value, bool use_dtor = true) - { - set_facet(level.id(), value, use_dtor); - } - - // Convnience facet access when the type has a associated LEVEL: - template U* facet() { return facet(U::LEVEL); } - template void set_facet(U* p) { set_facet(U::LEVEL, p); } -}; - -template -std::vector Facetable::deleters_ = {}; - -} -} - -#endif diff --git a/src/bindings/java/jmsg.cpp b/src/bindings/java/jmsg.cpp index 90461fb968..1b700b7a52 100644 --- a/src/bindings/java/jmsg.cpp +++ b/src/bindings/java/jmsg.cpp @@ -134,7 +134,7 @@ Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) MSG_init(&argc, argv); - JAVA_HOST_LEVEL = simgrid::Host::add_level(__JAVA_host_priv_free); + JAVA_HOST_LEVEL = simgrid::Host::extension_create(__JAVA_host_priv_free); JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, __JAVA_storage_priv_free); for (index = 0; index < argc; index++) @@ -158,7 +158,7 @@ JNIEXPORT void JNICALL xbt_dynar_t hosts = MSG_hosts_as_dynar(); for (unsigned long index = 0; index < xbt_dynar_length(hosts) - 1; index++) { msg_host_t msg_host = xbt_dynar_get_as(hosts,index,msg_host_t); - jobject jhost = (jobject) msg_host->facet(JAVA_HOST_LEVEL); + jobject jhost = (jobject) msg_host->extension(JAVA_HOST_LEVEL); if (jhost) jhost_unref(env, jhost); diff --git a/src/bindings/java/jmsg_as.cpp b/src/bindings/java/jmsg_as.cpp index b7d9cd8679..474bccde01 100644 --- a/src/bindings/java/jmsg_as.cpp +++ b/src/bindings/java/jmsg_as.cpp @@ -161,7 +161,7 @@ Java_org_simgrid_msg_As_getHosts(JNIEnv * env, jobject jas) host = xbt_dynar_get_as(table,index,msg_host_t); - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); diff --git a/src/bindings/java/jmsg_host.cpp b/src/bindings/java/jmsg_host.cpp index 9eb83121fc..accb02e600 100644 --- a/src/bindings/java/jmsg_host.cpp +++ b/src/bindings/java/jmsg_host.cpp @@ -86,7 +86,7 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, } env->ReleaseStringUTFChars(jname, name); - if (!host->facet(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ + if (!host->extension(JAVA_HOST_LEVEL)) { /* native host not associated yet with java host */ /* Instantiate a new java host */ jhost = jhost_new_instance(env); @@ -111,11 +111,11 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls, /* the native host data field is set with the global reference to the * java host returned by this function */ - host->set_facet(JAVA_HOST_LEVEL, (void *)jhost); + host->extension_set(JAVA_HOST_LEVEL, (void *)jhost); } /* return the global reference to the java host instance */ - return (jobject) host->facet(JAVA_HOST_LEVEL); + return (jobject) host->extension(JAVA_HOST_LEVEL); } JNIEXPORT jobject JNICALL @@ -124,7 +124,7 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { msg_host_t host = MSG_host_self(); - if (!host->facet(JAVA_HOST_LEVEL)) { + if (!host->extension(JAVA_HOST_LEVEL)) { /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ @@ -148,9 +148,9 @@ Java_org_simgrid_msg_Host_currentHost(JNIEnv * env, jclass cls) { env->SetObjectField(jhost, jhost_field_Host_name, jname); /* Bind & store it */ jhost_bind(jhost, host, env); - host->set_facet(JAVA_HOST_LEVEL, (void *) jhost); + host->extension_set(JAVA_HOST_LEVEL, (void *) jhost); } else { - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); } return jhost; @@ -357,7 +357,7 @@ Java_org_simgrid_msg_Host_all(JNIEnv * env, jclass cls_arg) for (index = 0; index < count; index++) { host = xbt_dynar_get_as(table,index,msg_host_t); - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); if (!jhost) { jname = env->NewStringUTF(MSG_host_get_name(host)); diff --git a/src/bindings/java/jmsg_task.cpp b/src/bindings/java/jmsg_task.cpp index cd22641e7f..fb1a948181 100644 --- a/src/bindings/java/jmsg_task.cpp +++ b/src/bindings/java/jmsg_task.cpp @@ -282,12 +282,12 @@ Java_org_simgrid_msg_Task_getSource(JNIEnv * env, if (host == NULL) { return NULL; } - if (!host->facet(JAVA_HOST_LEVEL)) { + if (!host->extension(JAVA_HOST_LEVEL)) { jxbt_throw_jni(env, "MSG_task_get_source() failed"); return NULL; } - return (jobject) host->facet(JAVA_HOST_LEVEL); + return (jobject) host->extension(JAVA_HOST_LEVEL); } JNIEXPORT jdouble JNICALL diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index 0258585ae1..84e805877e 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -167,7 +167,7 @@ Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm) { msg_vm_t vm = jvm_get_native(env,jvm); msg_host_t host = MSG_vm_get_pm(vm); - if (!host->facet(JAVA_HOST_LEVEL)) { + if (!host->extension(JAVA_HOST_LEVEL)) { /* the native host not yet associated with the java host instance */ /* instanciate a new java host instance */ @@ -193,9 +193,9 @@ Java_org_simgrid_msg_VM_get_pm(JNIEnv *env, jobject jvm) { jname); /* Bind & store it */ jhost_bind(jhost, host, env); - host->set_facet(JAVA_HOST_LEVEL, (void *) jhost); + host->extension_set(JAVA_HOST_LEVEL, (void *) jhost); } else { - jhost = (jobject) host->facet(JAVA_HOST_LEVEL); + jhost = (jobject) host->extension(JAVA_HOST_LEVEL); } return jhost; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 5e01fde734..784d1aa151 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -200,7 +200,7 @@ XBT_PUBLIC_DATA(routing_platf_t) routing_platf; static inline surf_host_t surf_host_resource_priv(sg_host_t host) { - return (surf_host_t) sg_host_get_facet(host, SURF_HOST_LEVEL); + return (surf_host_t) sg_host_extension_get(host, SURF_HOST_LEVEL); } static inline void *surf_storage_resource_priv(const void *storage){ return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL); diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index c4c9f2042b..9b00223782 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -14,19 +14,19 @@ size_t sg_host_count() return xbt_dict_length(host_list); } -void* sg_host_get_facet(sg_host_t host, size_t facet) +const char *sg_host_get_name(sg_host_t host) { - return host->facet(facet); + return host->id().c_str(); } -const char *sg_host_get_name(sg_host_t host) +void* sg_host_extension_get(sg_host_t host, size_t ext) { - return host->id().c_str(); + return host->extension(ext); } -size_t sg_host_add_level(void(*deleter)(void*)) +size_t sg_host_extension_create(void(*deleter)(void*)) { - return simgrid::Host::add_level(deleter); + return simgrid::Host::extension_create(deleter); } sg_host_t sg_host_by_name(const char *name) @@ -75,78 +75,78 @@ static XBT_INLINE void routing_asr_host_free(void *p) { void sg_host_init() { - MSG_HOST_LEVEL = simgrid::Host::add_level([](void *p) { + MSG_HOST_LEVEL = simgrid::Host::extension_create([](void *p) { __MSG_host_priv_free((msg_host_priv_t) p); }); - SD_HOST_LEVEL = simgrid::Host::add_level(__SD_workstation_destroy); - SIMIX_HOST_LEVEL = simgrid::Host::add_level(SIMIX_host_destroy); + SD_HOST_LEVEL = simgrid::Host::extension_create(__SD_workstation_destroy); + SIMIX_HOST_LEVEL = simgrid::Host::extension_create(SIMIX_host_destroy); simgrid::surf::Cpu::init(); - ROUTING_HOST_LEVEL = simgrid::Host::add_level(routing_asr_host_free); - USER_HOST_LEVEL = simgrid::Host::add_level(NULL); + ROUTING_HOST_LEVEL = simgrid::Host::extension_create(routing_asr_host_free); + USER_HOST_LEVEL = simgrid::Host::extension_create(NULL); } // ========== User data Layer ========== void *sg_host_user(sg_host_t host) { - return host->facet(USER_HOST_LEVEL); + return host->extension(USER_HOST_LEVEL); } void sg_host_user_set(sg_host_t host, void* userdata) { - host->set_facet(USER_HOST_LEVEL,userdata); + host->extension_set(USER_HOST_LEVEL,userdata); } void sg_host_user_destroy(sg_host_t host) { - host->set_facet(USER_HOST_LEVEL, nullptr); + host->extension_set(USER_HOST_LEVEL, nullptr); } // ========== MSG Layer ============== msg_host_priv_t sg_host_msg(sg_host_t host) { - return (msg_host_priv_t) host->facet(MSG_HOST_LEVEL); + return (msg_host_priv_t) host->extension(MSG_HOST_LEVEL); } void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) { - host->set_facet(MSG_HOST_LEVEL, smx_host); + host->extension_set(MSG_HOST_LEVEL, smx_host); } void sg_host_msg_destroy(sg_host_t host) { - host->set_facet(MSG_HOST_LEVEL, nullptr); + host->extension_set(MSG_HOST_LEVEL, nullptr); } // ========== SimDag Layer ============== SD_workstation_priv_t sg_host_sd(sg_host_t host) { - return (SD_workstation_priv_t) host->facet(SD_HOST_LEVEL); + return (SD_workstation_priv_t) host->extension(SD_HOST_LEVEL); } void sg_host_sd_set(sg_host_t host, SD_workstation_priv_t smx_host) { - host->set_facet(SD_HOST_LEVEL, smx_host); + host->extension_set(SD_HOST_LEVEL, smx_host); } void sg_host_sd_destroy(sg_host_t host) { - host->set_facet(SD_HOST_LEVEL, nullptr); + host->extension_set(SD_HOST_LEVEL, nullptr); } // ========== Simix layer ============= smx_host_priv_t sg_host_simix(sg_host_t host){ - return (smx_host_priv_t) host->facet(SIMIX_HOST_LEVEL); + return (smx_host_priv_t) host->extension(SIMIX_HOST_LEVEL); } void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) { - host->set_facet(SIMIX_HOST_LEVEL, smx_host); + host->extension_set(SIMIX_HOST_LEVEL, smx_host); } void sg_host_simix_destroy(sg_host_t host) { - host->set_facet(SIMIX_HOST_LEVEL, nullptr); + host->extension_set(SIMIX_HOST_LEVEL, nullptr); } // ========== SURF CPU ============ surf_cpu_t sg_host_surfcpu(sg_host_t host) { - return host->facet(); + return host->extension(); } void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { - host->set_facet(simgrid::surf::Cpu::LEVEL, cpu); + host->extension_set(simgrid::surf::Cpu::EXTENSION_ID, cpu); // FIXME: use the typesafe version } void sg_host_surfcpu_destroy(sg_host_t host) { - host->set_facet(nullptr); + host->extension_set(nullptr); } // ========== RoutingEdge ============ surf_RoutingEdge *sg_host_edge(sg_host_t host) { - return (surf_RoutingEdge*) host->facet(ROUTING_HOST_LEVEL); + return (surf_RoutingEdge*) host->extension(ROUTING_HOST_LEVEL); } void sg_host_edge_set(sg_host_t host, surf_RoutingEdge *edge) { - host->set_facet(ROUTING_HOST_LEVEL, edge); + host->extension_set(ROUTING_HOST_LEVEL, edge); } void sg_host_edge_destroy(sg_host_t host, int do_callback) { - host->set_facet(ROUTING_HOST_LEVEL, nullptr, do_callback); + host->extension_set(ROUTING_HOST_LEVEL, nullptr, do_callback); } // =========== user-level functions =============== diff --git a/src/simgrid/sg_config.c b/src/simgrid/sg_config.c index c20342408f..7836066197 100644 --- a/src/simgrid/sg_config.c +++ b/src/simgrid/sg_config.c @@ -456,7 +456,7 @@ static void _sg_cfg_cb__surf_network_coordinates(const char *name, int val = xbt_cfg_get_boolean(_sg_cfg_set, name); if (val) { if (!already_set) { - COORD_HOST_LEVEL = sg_host_add_level(xbt_dynar_free_voidp); + COORD_HOST_LEVEL = sg_host_extension_create(xbt_dynar_free_voidp); COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp); } already_set = 1; diff --git a/src/surf/cpu_interface.cpp b/src/surf/cpu_interface.cpp index feca4113d0..2f1f7df542 100644 --- a/src/surf/cpu_interface.cpp +++ b/src/surf/cpu_interface.cpp @@ -20,12 +20,12 @@ simgrid::surf::CpuModel *surf_cpu_model_vm; namespace simgrid { namespace surf { -simgrid::xbt::FacetLevel Cpu::LEVEL; +simgrid::xbt::Extension Cpu::EXTENSION_ID; void Cpu::init() { - if (!LEVEL.valid()) - LEVEL = simgrid::Host::add_level(); + if (!EXTENSION_ID.valid()) + EXTENSION_ID = simgrid::Host::extension_create(); } /************* @@ -241,8 +241,8 @@ void Cpu::setState(e_surf_resource_state_t state) void Cpu::plug(simgrid::Host* host) { if (this->m_host != nullptr) - xbt_die("Aleady plugged into host %s", host->id().c_str()); - host->set_facet(this); + xbt_die("Already plugged into host %s", host->id().c_str()); + host->extension_set(this); this->m_host = host; simgrid::surf::cpuCreatedCallbacks(this); simgrid::surf::cpuStateChangedCallbacks(this, diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index 80564a2ff8..5e4aece37b 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -98,7 +98,7 @@ public: */ XBT_PUBLIC_CLASS Cpu : public simgrid::surf::Resource { public: - static simgrid::xbt::FacetLevel LEVEL; + static simgrid::xbt::Extension EXTENSION_ID; static void init(); Cpu(); diff --git a/src/surf/host_interface.cpp b/src/surf/host_interface.cpp index 54d562fe0e..0dcf34b568 100644 --- a/src/surf/host_interface.cpp +++ b/src/surf/host_interface.cpp @@ -31,7 +31,7 @@ void host_add_traces(){ namespace simgrid { namespace surf { -simgrid::xbt::FacetLevel Host::LEVEL; +simgrid::xbt::Extension Host::EXTENSION_ID; simgrid::surf::signal hostCreatedCallbacks; simgrid::surf::signal hostDestructedCallbacks; @@ -83,9 +83,9 @@ void HostModel::adjustWeightOfDummyCpuActions() void Host::init() { - if (!LEVEL.valid()) { - LEVEL = simgrid::Host::add_level(); - SURF_HOST_LEVEL = LEVEL.id(); + if (!EXTENSION_ID.valid()) { + EXTENSION_ID = simgrid::Host::extension_create(); + SURF_HOST_LEVEL = EXTENSION_ID.id(); // FIXME: KILLME } } @@ -122,7 +122,7 @@ void Host::attach(simgrid::Host* host) { if (p_host != nullptr) xbt_die("Already attached to host %s", host->id().c_str()); - host->set_facet(this); + host->extension_set(this); p_host = host; hostCreatedCallbacks(this); } diff --git a/src/surf/host_interface.hpp b/src/surf/host_interface.hpp index a7c6b51d9a..2aa6669d92 100644 --- a/src/surf/host_interface.hpp +++ b/src/surf/host_interface.hpp @@ -97,7 +97,7 @@ public: */ class Host : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder { public: - static simgrid::xbt::FacetLevel LEVEL; + static simgrid::xbt::Extension EXTENSION_ID; static void init(); /** * @brief Host constructor diff --git a/src/surf/ns3/ns3_interface.h b/src/surf/ns3/ns3_interface.h index 8043743bf2..36c8aa7c78 100644 --- a/src/surf/ns3/ns3_interface.h +++ b/src/surf/ns3/ns3_interface.h @@ -56,7 +56,7 @@ ns3_nodes_t ns3_find_host(const char* id) if (host == nullptr) return nullptr; else - return (ns3_nodes_t) sg_host_get_facet(host, NS3_HOST_LEVEL); + return (ns3_nodes_t) sg_host_get_extension(host, NS3_HOST_LEVEL); } SG_END_DECL() diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index bc658f3a80..c709ccac8c 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -171,7 +171,7 @@ void routing_get_route_and_latency(sg_routing_edge_t src, sg_routing_edge_t dst, surf_host_model_t surf_host_get_model(sg_host_t host) { simgrid::surf::Host* surf_host = - (simgrid::surf::Host*) host->facet(); + (simgrid::surf::Host*) host->extension(); return (surf_host_model_t) surf_host->getModel(); } @@ -393,10 +393,10 @@ void surf_vm_destroy(sg_host_t resource){ */ sg_host_surfcpu_destroy(resource); sg_host_edge_destroy(resource,1); - resource->set_facet(nullptr); + resource->extension_set(nullptr); /* TODO: comment out when VM storage is implemented. */ - // host->set_facet(SURF_STORAGE_LEVEL, nullptr); + // host->extension_set(SURF_STORAGE_LEVEL, nullptr); } void surf_vm_suspend(sg_host_t vm){ diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 0d3e36c351..dbc30ef44d 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -197,7 +197,7 @@ simgrid::surf::RoutingEdge *routing_add_host( } xbt_dynar_shrink(ctn, 0); xbt_dynar_free(&ctn_str); - h->set_facet(COORD_HOST_LEVEL, (void *) ctn); + h->extension_set(COORD_HOST_LEVEL, (void *) ctn); XBT_DEBUG("Having set host coordinates for '%s'",host->id); } diff --git a/src/surf/surf_routing_vivaldi.cpp b/src/surf/surf_routing_vivaldi.cpp index 3281f1edb4..d47f4ed1d4 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::by_name_or_create(tmp_src_name)->facet(COORD_HOST_LEVEL); + src_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(tmp_src_name)->extension(COORD_HOST_LEVEL); if (src_ctn == nullptr) - src_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(src->getName())->facet(COORD_HOST_LEVEL); + src_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(src->getName())->extension(COORD_HOST_LEVEL); } else if(src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_AS){ tmp_src_name = ROUTER_PEER(src->getName()); @@ -81,10 +81,10 @@ void AsVivaldi::getRouteAndLatency(RoutingEdge *src, RoutingEdge *dst, sg_platf_ } } dst_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(tmp_dst_name) - ->facet(COORD_HOST_LEVEL); + ->extension(COORD_HOST_LEVEL); if (dst_ctn == nullptr) dst_ctn = (xbt_dynar_t) simgrid::Host::by_name_or_create(dst->getName()) - ->facet(COORD_HOST_LEVEL); + ->extension(COORD_HOST_LEVEL); } else if(dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || dst->getRcType() == SURF_NETWORK_ELEMENT_AS){ tmp_dst_name = ROUTER_PEER(dst->getName()); diff --git a/src/surf/virtual_machine.cpp b/src/surf/virtual_machine.cpp index 9eab02c12e..37b24e7400 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::by_name_or_create(name)->set_facet(this); + simgrid::Host::by_name_or_create(name)->extension_set(this); } /* diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 0bc0ae4670..5533efe81a 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -755,7 +755,7 @@ set(headers_to_install include/xbt/hash.h include/xbt/heap.h include/xbt/lib.h - include/xbt/Facetable.hpp + include/xbt/Extendable.hpp include/xbt/log.h include/xbt/mallocator.h include/xbt/matrix.h