class Resource;
class Cpu;
class Link;
+ class HostImpl;
}
namespace trace_mgr {
class trace;
public:
// TODO, this could be a unique_ptr
+ surf::HostImpl* pimpl_ = nullptr;
/** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
surf::Cpu *pimpl_cpu = nullptr;
/** DO NOT USE DIRECTLY (@todo: these should be protected, once our code is clean) */
{
xbt_assert(currentlyDestroying_, "Please call h->destroy() instead of manually deleting it.");
+ delete pimpl_;
delete pimpl_cpu;
delete pimpl_netcard;
delete mounts;
*
* Don't delete directly an Host, call h->destroy() instead.
*
- * This is cumbersome but there is the simplest solution to ensure that the
+ * This is cumbersome but this is the simplest solution to ensure that the
* onDestruction() callback receives a valid object (because of the destructor
* order in a class hierarchy).
*/
if (isOff()) {
simgrid::simix::kernelImmediate([&]{
this->extension<simgrid::simix::Host>()->turnOn();
- this->extension<simgrid::surf::HostImpl>()->turnOn();
+ this->pimpl_->turnOn();
});
}
}
/** Get the properties assigned to a host */
xbt_dict_t Host::properties() {
return simgrid::simix::kernelImmediate([&] {
- simgrid::surf::HostImpl* surf_host = this->extension<simgrid::surf::HostImpl>();
- return surf_host->getProperties();
+ return this->pimpl_->getProperties();
});
}
/** Retrieve the property value (or nullptr if not set) */
const char*Host::property(const char*key) {
- simgrid::surf::HostImpl* surf_host = this->extension<simgrid::surf::HostImpl>();
- return surf_host->getProperty(key);
+ return this->pimpl_->getProperty(key);
}
void Host::setProperty(const char*key, const char *value){
simgrid::simix::kernelImmediate([&] {
- simgrid::surf::HostImpl* surf_host = this->extension<simgrid::surf::HostImpl>();
- surf_host->setProperty(key,value);
+ this->pimpl_->setProperty(key,value);
});
}
void Host::parameters(vm_params_t params)
{
simgrid::simix::kernelImmediate([&]() {
- this->extension<simgrid::surf::HostImpl>()->getParams(params);
+ this->pimpl_->getParams(params);
});
}
void Host::setParameters(vm_params_t params)
{
simgrid::simix::kernelImmediate([&]() {
- this->extension<simgrid::surf::HostImpl>()->setParams(params);
+ this->pimpl_->setParams(params);
});
}
xbt_dict_t Host::mountedStoragesAsDict()
{
return simgrid::simix::kernelImmediate([&] {
- return this->extension<simgrid::surf::HostImpl>()->getMountedStorageList();
+ return this->pimpl_->getMountedStorageList();
});
}
xbt_dynar_t Host::attachedStorages()
{
return simgrid::simix::kernelImmediate([&] {
- return this->extension<simgrid::surf::HostImpl>()->getAttachedStorageList();
+ return this->pimpl_->getAttachedStorageList();
});
}
// ========= storage related functions ============
xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){
- return host->extension<simgrid::surf::HostImpl>()->getMountedStorageList();
+ return host->pimpl_->getMountedStorageList();
}
xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){
- return host->extension<simgrid::surf::HostImpl>()->getAttachedStorageList();
+ return host->pimpl_->getAttachedStorageList();
}
xbt_assert((host != nullptr), "Invalid parameters");
if (h->isOn()) {
- simgrid::surf::HostImpl* surf_host = h->extension<simgrid::surf::HostImpl>();
- surf_host->turnOff();
+ h->pimpl_->turnOff();
/* Clean Simulator data */
if (xbt_swag_size(host->process_list) != 0) {
host_list_cpy[i] = host_list[i];
/* Check that we are not mixing VMs and PMs in the parallel task */
- simgrid::surf::HostImpl *host = host_list[0]->extension<simgrid::surf::HostImpl>();
- bool is_a_vm = (nullptr != dynamic_cast<simgrid::surf::VirtualMachine*>(host));
+ bool is_a_vm = (nullptr != dynamic_cast<simgrid::surf::VirtualMachine*>(host_list[0]->pimpl_));
for (int i = 1; i < host_nb; i++) {
- bool tmp_is_a_vm = (nullptr != dynamic_cast<simgrid::surf::VirtualMachine*>(host_list[i]->extension<simgrid::surf::HostImpl>()));
+ bool tmp_is_a_vm = (nullptr != dynamic_cast<simgrid::surf::VirtualMachine*>(host_list[i]->pimpl_));
xbt_assert(is_a_vm == tmp_is_a_vm, "parallel_execute: mixing VMs and PMs is not supported (yet).");
}
static long host_get_ramsize(sg_host_t vm, int *overcommit)
{
s_vm_params_t params;
- vm->extension<simgrid::surf::HostImpl>()->getParams(¶ms);
+ vm->pimpl_->getParams(¶ms);
if (overcommit)
*overcommit = params.overcommit;
}
long total_ramsize_of_vms = 0;
- xbt_dynar_t dyn_vms = pm->extension<simgrid::surf::HostImpl>()->getVms();
+ xbt_dynar_t dyn_vms = pm->pimpl_->getVms();
{
unsigned int cursor = 0;
sg_host_t another_vm;
{
if (__can_be_started(vm))
static_cast<simgrid::surf::VirtualMachine*>(
- vm->extension<simgrid::surf::HostImpl>()
+ vm->pimpl_
)->setState(SURF_VM_STATE_RUNNING);
else
THROWF(vm_error, 0, "The VM %s cannot be started", vm->name().c_str());
e_surf_vm_state_t SIMIX_vm_get_state(sg_host_t vm)
{
return static_cast<simgrid::surf::VirtualMachine*>(
- vm->extension<simgrid::surf::HostImpl>()
+ vm->pimpl_
)->getState();
}
/* FIXME: we may have to do something at the surf layer, e.g., vcpu action */
static_cast<simgrid::surf::VirtualMachine*>(
- vm->extension<simgrid::surf::HostImpl>()
+ vm->pimpl_
)->setState(SURF_VM_STATE_CREATED);
}
namespace simgrid {
namespace surf {
-simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> HostImpl::EXTENSION_ID;
-
/*********
* Model *
*********/
, PropertyHolder(nullptr)
, storage_(storage), cpu_(cpu)
{
- if (!EXTENSION_ID.valid())
- EXTENSION_ID = simgrid::s4u::Host::extension_create<simgrid::surf::HostImpl>();
params_.ramsize = 0;
}
}
/** @brief use destroy() instead of this destructor */
-HostImpl::~HostImpl()
-{
-}
+HostImpl::~HostImpl() = default;
void HostImpl::attach(simgrid::s4u::Host* host)
{
if (piface_ != nullptr)
xbt_die("Already attached to host %s", host->name().c_str());
- host->extension_set(this);
+ host->pimpl_ = this;
piface_ = host;
}
xbt_dynar_t dyn = xbt_dynar_new(sizeof(simgrid::surf::VirtualMachine*), nullptr);
for (VirtualMachine *ws_vm : VirtualMachine::allVms_) {
- if (this == ws_vm->getPm()->extension<simgrid::surf::HostImpl>())
+ if (this == ws_vm->getPm()->pimpl_)
xbt_dynar_push(dyn, &ws_vm);
}
class HostImpl
: public simgrid::surf::Resource,
public simgrid::surf::PropertyHolder {
-public:
- static simgrid::xbt::Extension<simgrid::s4u::Host, HostImpl> EXTENSION_ID;
public:
/**
/* Computes the consumption so far. Called lazily on need. */
void HostEnergy::update()
{
- simgrid::surf::HostImpl* surf_host = host->extension<simgrid::surf::HostImpl>();
+ simgrid::surf::HostImpl* surf_host = host->pimpl_;
double start_time = this->last_updated;
double finish_time = surf_get_clock();
double cpu_load;
/* **************************** events callback *************************** */
static void onCreation(simgrid::s4u::Host& host) {
- simgrid::surf::HostImpl* surf_host = host.extension<simgrid::surf::HostImpl>();
- if (dynamic_cast<simgrid::surf::VirtualMachine*>(surf_host)) // Ignore virtual machines
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host.pimpl_)) // Ignore virtual machines
return;
host.extension_set(new HostEnergy(&host));
}
sg_host_t sghost = sg_host_by_name(name);
if(sghost == nullptr)
continue;
- simgrid::surf::HostImpl *host = sghost->extension<simgrid::surf::HostImpl>();
+ simgrid::surf::HostImpl *host = sghost->pimpl_;
simgrid::surf::VirtualMachine *vm = dynamic_cast<simgrid::surf::VirtualMachine*>(host);
if (vm) // If it's a VM, take the corresponding PM
- host = vm->getPm()->extension<simgrid::surf::HostImpl>();
+ host = vm->getPm()->pimpl_;
HostEnergy *host_energy = host->piface_->extension<HostEnergy>();
}
static void onHostStateChange(simgrid::s4u::Host &host) {
- simgrid::surf::HostImpl* surf_host = host.extension<simgrid::surf::HostImpl>();
- if (dynamic_cast<simgrid::surf::VirtualMachine*>(surf_host)) // Ignore virtual machines
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host.pimpl_)) // Ignore virtual machines
return;
HostEnergy *host_energy = host.extension<HostEnergy>();
static void onHostDestruction(simgrid::s4u::Host& host) {
// Ignore virtual machines
- simgrid::surf::HostImpl* surf_host = host.extension<simgrid::surf::HostImpl>();
- if (dynamic_cast<simgrid::surf::VirtualMachine*>(surf_host))
+ if (dynamic_cast<simgrid::surf::VirtualMachine*>(host.pimpl_))
return;
HostEnergy *host_energy = host.extension<HostEnergy>();
host_energy->update();
*********/
static simgrid::surf::HostImpl *get_casted_host(sg_host_t host){ //FIXME: killme
- return host->extension<simgrid::surf::HostImpl>();
+ return host->pimpl_;
}
static simgrid::surf::VirtualMachine *get_casted_vm(sg_host_t host){
- return static_cast<simgrid::surf::VirtualMachine*>(host->extension<simgrid::surf::HostImpl>());
+ return static_cast<simgrid::surf::VirtualMachine*>(host->pimpl_);
}
extern double NOW;
{
/* Register this VM to the list of all VMs */
allVms_.push_back(this);
+
piface_ = new simgrid::s4u::Host(name);
- piface_->extension_set<simgrid::surf::HostImpl>(this);
+ piface_->pimpl_ = this;
/* Currently, a VM uses the network resource of its physical host. In
* host_lib, this network resource object is referred from two different keys.
/* Update the physical host of the given VM */
void VirtualMachine::migrate(sg_host_t host_dest)
{
- HostImpl *surfHost_dst = host_dest->extension<HostImpl>();
+ HostImpl *surfHost_dst = host_dest->pimpl_;
const char *vm_name = getName();
const char *pm_name_src = hostPM_->name().c_str();
const char *pm_name_dst = surfHost_dst->getName();