-#include "surf/surf.h" // routing_get_network_element_type FIXME:killme
-
-sg_host_t sg_host_by_name(const char *name){
- return xbt_lib_get_elm_or_null(host_lib, name);
-}
-
-sg_host_t sg_host_by_name_or_create(const char *name) {
- sg_host_t res = xbt_lib_get_elm_or_null(host_lib, name);
- if (!res) {
- xbt_lib_set(host_lib,name,0,NULL); // Should only create the bucklet with no data added
- res = xbt_lib_get_elm_or_null(host_lib, name);
- }
- return res;
-}
-xbt_dynar_t sg_hosts_as_dynar(void) {
- xbt_lib_cursor_t cursor;
- char *key;
- void **data;
- xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL);
-
- xbt_lib_foreach(host_lib, cursor, key, data) {
- if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) {
- xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor);
- xbt_dynar_push(res, &elm);
- }
- }
- return res;
-}
-
-// ========= Layering madness ==============
-
-int MSG_HOST_LEVEL;
-int SD_HOST_LEVEL;
-int SIMIX_HOST_LEVEL;
-int ROUTING_HOST_LEVEL;
-int SURF_CPU_LEVEL;
-int USER_HOST_LEVEL;
-
-#include "src/msg/msg_private.h" // MSG_host_priv_free. FIXME: killme
-#include "src/simdag/private.h" // __SD_workstation_destroy. FIXME: killme
-#include "src/simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme
-#include "src/surf/cpu_interface.hpp"
-#include "src/surf/surf_routing.hpp"
+#include <xbt/Extendable.hpp>
+#include <simgrid/s4u/host.hpp>
+
+#include "src/kernel/routing/NetCard.hpp"
+#include "src/surf/HostImpl.hpp"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts");
+
+extern std::unordered_map<std::string, simgrid::s4u::Host*>
+ host_list; // FIXME: don't duplicate the content of s4u::Host this way
+
+void sg_host_exit()
+{
+ /* copy all names to not modify the map while iterating over it.
+ *
+ * Plus, the hosts are destroyed in the lexicographic order to ensure
+ * that the output is reproducible: we don't want to kill them in the
+ * pointer order as it could be platform-dependent, which would break
+ * the tests.
+ */
+ std::vector<std::string> names = std::vector<std::string>();
+ for (auto kv : host_list)
+ names.push_back(kv.second->name());
+
+ std::sort(names.begin(), names.end());
+
+ for (auto name : names)
+ host_list.at(name)->destroy();
+
+ // host_list.clear(); This would be sufficient if the dict would contain smart_ptr. It's now useless
+}
+
+size_t sg_host_count()
+{
+ return host_list.size();
+}
+/** @brief Returns the host list
+ *
+ * Uses sg_host_count() to know the array size.
+ *
+ * \return an array of \ref sg_host_t containing all the hosts in the platform.
+ * \remark The host order in this array is generally different from the
+ * creation/declaration order in the XML platform (we use a hash table
+ * internally).
+ * \see sg_host_count()
+ */
+sg_host_t *sg_host_list() {
+ xbt_assert(sg_host_count() > 0, "There is no host!");
+ return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar());
+}