+xbt_dynar_t sg_hosts_as_dynar(void)
+{
+ xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL);
+
+ xbt_dict_cursor_t cursor = nullptr;
+ const char* name = nullptr;
+ simgrid::Host* host = nullptr;
+ xbt_dict_foreach(host_list, cursor, name, host)
+ if(routing_get_network_element_type(name) == SURF_NETWORK_ELEMENT_HOST)
+ xbt_dynar_push(res, &host);
+ return res;
+}
+
+// ========= Layering madness ==============
+
+int MSG_HOST_LEVEL;
+int SD_HOST_LEVEL;
+int SIMIX_HOST_LEVEL;
+int ROUTING_HOST_LEVEL;
+int USER_HOST_LEVEL;
+
+#include "src/msg/msg_private.h" // MSG_host_priv_free. FIXME: killme by initializing that level in msg when used
+#include "src/simdag/simdag_private.h" // __SD_workstation_destroy. FIXME: killme by initializing that level in simdag when used
+#include "src/simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme by initializing that level in simix when used
+#include "src/surf/cpu_interface.hpp"
+#include "src/surf/surf_routing.hpp"
+
+void sg_host_init()
+{
+ MSG_HOST_LEVEL = simgrid::Host::extension_create([](void *p) {
+ __MSG_host_priv_free((msg_host_priv_t) p);
+ });
+
+ ROUTING_HOST_LEVEL = simgrid::Host::extension_create([](void *p) {
+ delete static_cast<simgrid::surf::NetCard*>(p);
+ });
+
+ SD_HOST_LEVEL = simgrid::Host::extension_create(__SD_workstation_destroy);
+ SIMIX_HOST_LEVEL = simgrid::Host::extension_create(SIMIX_host_destroy);
+ USER_HOST_LEVEL = simgrid::Host::extension_create(NULL);
+}
+
+// ========== User data Layer ==========
+void *sg_host_user(sg_host_t host) {
+ return host->extension(USER_HOST_LEVEL);
+}
+void sg_host_user_set(sg_host_t host, void* userdata) {
+ host->extension_set(USER_HOST_LEVEL,userdata);
+}
+void sg_host_user_destroy(sg_host_t host) {
+ 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->extension(MSG_HOST_LEVEL);
+}
+void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) {
+ host->extension_set(MSG_HOST_LEVEL, smx_host);
+}
+// ========== SimDag Layer ==============
+SD_workstation_priv_t sg_host_sd(sg_host_t host) {
+ 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->extension_set(SD_HOST_LEVEL, smx_host);
+}
+void sg_host_sd_destroy(sg_host_t host) {
+ host->extension_set(SD_HOST_LEVEL, nullptr);
+}
+
+// ========== Simix layer =============