XBT_PUBLIC_CLASS Host :
public simgrid::xbt::Extendable<Host> {
-private:
+public:
explicit Host(const char *name);
-public: // TODO, make me private
- ~Host();
- /** Do not use this function, it should be private */
- static Host* by_name_or_create(const char* name);
+ ~Host(); // TODO, make me private
/** Retrieves an host from its name, or return nullptr */
static Host* by_name_or_null(const char* name);
Host::Host(const char* name)
: name_(name)
{
+ xbt_assert(sg_host_by_name(name) == nullptr, "Refusing to create a second host named '%s'.", name);
xbt_dict_set(host_list, name, this, nullptr);
}
});
return (Host*) xbt_dict_get_or_null(host_list, name);
}
-Host* Host::by_name_or_create(const char* name)
-{
- Host* host = by_name_or_null(name);
- if (host == nullptr)
- host = new Host(name);
-
- return host;
-}
Host *Host::current(){
smx_actor_t smx_proc = SIMIX_process_self();
SIMIX_vm_shutdown(vm, simcall->issuer);
}
-/**
- * @brief Function to destroy a SIMIX VM host.
- *
- * @param vm the vm host to destroy (a sg_host_t)
- */
+extern xbt_dict_t host_list; // FIXME:killme don't dupplicate the content of s4u::Host this way
+ /**
+ * @brief Function to destroy a SIMIX VM host.
+ *
+ * @param vm the vm host to destroy (a sg_host_t)
+ */
void SIMIX_vm_destroy(sg_host_t vm)
{
/* this code basically performs a similar thing like SIMIX_host_destroy() */
/* Don't free these things twice: they are the ones of my physical host */
vm->pimpl_cpu = nullptr;
vm->pimpl_netcard = nullptr;
+
+ if (xbt_dict_get_or_null(host_list, vm->name().c_str()))
+ xbt_dict_remove(host_list, vm->name().c_str());
}
for (int i : *cluster->radicals) {
char* router_id = bprintf("router_%s%d%s", cluster->prefix, i, cluster->suffix);
- simgrid::s4u::Host* router = simgrid::s4u::Host::by_name_or_create(router_id);
+ simgrid::s4u::Host* router = new simgrid::s4u::Host(router_id);
ns3_add_host(*router);
// Create private link
/** @brief Add an "host" to the current AS */
void sg_platf_new_host(sg_platf_host_cbarg_t host)
{
- xbt_assert(sg_host_by_name(host->id) == nullptr, "Refusing to create a second host named '%s'.", host->id);
-
simgrid::kernel::routing::AsImpl* current_routing = routing_get_current();
if (current_routing->hierarchy_ == simgrid::kernel::routing::AsImpl::RoutingMode::unset)
current_routing->hierarchy_ = simgrid::kernel::routing::AsImpl::RoutingMode::base;
simgrid::kernel::routing::NetCard *netcard =
new simgrid::kernel::routing::NetCardImpl(host->id, simgrid::kernel::routing::NetCard::Type::Host, current_routing);
- sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
+ simgrid::s4u::Host* h = new simgrid::s4u::Host(host->id);
h->pimpl_netcard = netcard;
if(mount_list) {
{
/* Register this VM to the list of all VMs */
allVms_.push_back(this);
- piface_ = simgrid::s4u::Host::by_name_or_create(name);
+ piface_ = new simgrid::s4u::Host(name);
piface_->extension_set<simgrid::surf::HostImpl>(this);
/* Currently, we assume a VM has no storage. */
* from the VM name, we have to make sure that the system does not call the
* free callback for the network resource object. The network resource object
* is still used by the physical machine. */
- sg_host_t host_VM = simgrid::s4u::Host::by_name_or_create(name);
+ sg_host_t host_VM = piface_;
host_VM->pimpl_netcard = host_PM->pimpl_netcard;
vmState_ = SURF_VM_STATE_CREATED;
// Roughly, create a vcpu resource by using the values of the sub_cpu one.
CpuCas01 *sub_cpu = dynamic_cast<CpuCas01*>(host_PM->pimpl_cpu);
- cpu_ = surf_cpu_model_vm->createCpu(host_VM, // the machine hosting the VM
- sub_cpu->getSpeedPeakList(), 1 /*cores*/);
+ cpu_ = surf_cpu_model_vm->createCpu(host_VM, sub_cpu->getSpeedPeakList(), 1 /*cores*/);
if (sub_cpu->getPState() != 0)
cpu_->setPState(sub_cpu->getPState());