/* 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"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_host, ker_resource, "Host resources agregate CPU, networking and I/O features");
-simgrid::surf::HostModel *surf_host_model = nullptr;
-
/*************
* Callbacks *t
*************/
/************
* 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()
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.
}
}
-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