]> AND Public Git Repository - simgrid.git/blobdiff - src/surf/HostImpl.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplification
[simgrid.git] / src / surf / HostImpl.cpp
index 7b33f5dbfe91afbc5f7992ceeadfaded030070a4..e5c64670aeb4601772a5f6cfbde16c6aab702f40 100644 (file)
@@ -3,14 +3,14 @@
 /* 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. */
 
+#include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Host.hpp"
 #include "src/plugins/vm/VirtualMachineImpl.hpp"
 #include "src/simix/smx_private.hpp"
 
 #include <string>
 
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_host, surf, "Logging specific to the SURF host module");
-
-simgrid::surf::HostModel *surf_host_model = nullptr;
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_host, ker_resource, "Host resources agregate CPU, networking and I/O features");
 
 /*************
  * Callbacks *t
@@ -25,11 +25,16 @@ namespace surf {
 /************
  * Resource *
  ************/
-HostImpl::HostImpl(s4u::Host* host) : piface_(host)
+HostImpl::HostImpl(const std::string& name, s4u::Host* piface) : piface_(this), name_(name)
+{
+  xbt_assert(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname());
+  s4u::Engine::get_instance()->host_register(name_, piface);
+}
+
+HostImpl::HostImpl(const std::string& name) : piface_(this), name_(name)
 {
-  /* The VM wants to reinstall a new HostImpl, but we don't want to leak the previously existing one */
-  delete piface_->pimpl_;
-  piface_->pimpl_ = this;
+  xbt_assert(s4u::Host::by_name_or_null(name_) == nullptr, "Refusing to create a second host named '%s'.", get_cname());
+  s4u::Engine::get_instance()->host_register(name_, &piface_);
 }
 
 HostImpl::~HostImpl()
@@ -51,6 +56,17 @@ HostImpl::~HostImpl()
     d->destroy();
 }
 
+/** @brief Fire the required callbacks and destroy the object
+ *
+ * Don't delete directly a Host, call h->destroy() instead.
+ */
+void HostImpl::destroy()
+{
+  s4u::Host::on_destruction(*this->get_iface());
+  s4u::Engine::get_instance()->host_unregister(std::string(name_));
+  delete this;
+}
+
 /** Re-starts all the actors that are marked as restartable.
  *
  * Weird things will happen if you turn on a host that is already on. S4U is fool-proof, not this.
@@ -135,21 +151,9 @@ void HostImpl::remove_disk(const std::string& disk_name)
   }
 }
 
-std::vector<const char*> HostImpl::get_attached_storages()
+void HostImpl::seal()
 {
-  std::vector<const char*> storages;
-  for (auto const& s : storage_)
-    if (s.second->get_host() == piface_->get_cname())
-      storages.push_back(s.second->get_iface()->get_cname());
-  return storages;
-}
-std::unordered_map<std::string, s4u::Storage*>* HostImpl::get_mounted_storages()
-{
-  auto* mounts = new std::unordered_map<std::string, s4u::Storage*>();
-  for (auto const& m : storage_) {
-    mounts->insert({m.first, m.second->get_iface()});
-  }
-  return mounts;
+  sealed_ = true;
 }
 } // namespace surf
 } // namespace simgrid