Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill the now useless type xbt::string
[simgrid.git] / src / s4u / s4u_Host.cpp
index d84f23e..4266d80 100644 (file)
@@ -84,7 +84,7 @@ Host* Host::current()
   return self->get_host();
 }
 
-xbt::string const& Host::get_name() const
+std::string const& Host::get_name() const
 {
   return this->pimpl_->get_name();
 }
@@ -111,11 +111,6 @@ void Host::turn_off()
   if (is_on()) {
     const kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
     kernel::actor::simcall_answered([this, self] {
-      for (VirtualMachine* const& vm : kernel::resource::VirtualMachineImpl::allVms_)
-        if (vm->get_pm() == this) {
-          vm->shutdown();
-          vm->turn_off();
-        }
       this->pimpl_cpu_->turn_off();
       this->pimpl_->turn_off(self);
 
@@ -368,12 +363,20 @@ void Host::remove_disk(const std::string& disk_name)
 
 VirtualMachine* Host::create_vm(const std::string& name, int core_amount)
 {
-  return new VirtualMachine(name, this, core_amount);
+  return kernel::actor::simcall_answered(
+      [this, &name, core_amount] { return this->pimpl_->create_vm(name, core_amount); });
 }
 
 VirtualMachine* Host::create_vm(const std::string& name, int core_amount, size_t ramsize)
 {
-  return new VirtualMachine(name, this, core_amount, ramsize);
+  return kernel::actor::simcall_answered(
+      [this, &name, core_amount, ramsize] { return this->pimpl_->create_vm(name, core_amount, ramsize); });
+}
+
+VirtualMachine* Host::vm_by_name_or_null(const std::string& name)
+{
+  simgrid::kernel::resource::VirtualMachineImpl* vm = this->pimpl_->get_vm_by_name_or_null(name);
+  return vm ? vm->get_iface() : nullptr;
 }
 
 ExecPtr Host::exec_init(double flops) const
@@ -445,6 +448,12 @@ sg_host_t sg_host_by_name(const char* name)
   return simgrid::s4u::Host::by_name_or_null(name);
 }
 
+/** @brief Retrieve a VM running on a given host from its name, or return NULL if no VM matches*/
+sg_vm_t sg_vm_by_name(sg_host_t host, const char* name)
+{
+  return host->vm_by_name_or_null(name);
+}
+
 // ========= Layering madness ==============*
 
 // ========== User data Layer ==========
@@ -573,8 +582,8 @@ xbt_dict_t sg_host_get_properties(const_sg_host_t host)
 
   if (props == nullptr)
     return nullptr;
-  for (auto const& elm : *props) {
-    xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()));
+  for (auto const& [key, value] : *props) {
+    xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str()));
   }
   return as_dict;
 }
@@ -658,8 +667,8 @@ void sg_host_dump(const_sg_host_t host) // XBT_ATTRIB_DEPRECATED_v335
 
   if (not props->empty()) {
     XBT_INFO("  - properties:");
-    for (auto const& elm : *props) {
-      XBT_INFO("    %s->%s", elm.first.c_str(), elm.second.c_str());
+    for (auto const& [key, value] : *props) {
+      XBT_INFO("    %s->%s", key.c_str(), value.c_str());
     }
   }
 }