+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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 "workstation_interface.hpp"
#include "vm_workstation_interface.hpp"
#include "cpu_cas01.hpp"
#include "simgrid/sg_config.h"
-extern "C" {
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
"Logging specific to the SURF workstation module");
-}
WorkstationModelPtr surf_workstation_model = NULL;
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
+surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
+surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
+surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
+
/*********
* Model *
*********/
-WorkstationModel::WorkstationModel(string name)
+WorkstationModel::WorkstationModel(const char *name)
: Model(name)
{
p_cpuModel = surf_cpu_model_pm;
WorkstationModel::~WorkstationModel() {
}
-
-
/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
* constraint (capacity) of the VM in the PM layer. If the VM does not have any
* active task, the dummy CPU action must be deactivated, so that the VM does
void **ind_host;
xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- WorkstationPtr ws = dynamic_cast<WorkstationPtr>(
- static_cast<ResourcePtr>(ind_host[SURF_WKS_LEVEL]));
- CpuCas01LmmPtr cpu_cas01 = dynamic_cast<CpuCas01LmmPtr>(
- static_cast<ResourcePtr>(ind_host[SURF_CPU_LEVEL]));
+ WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
+ CpuCas01Ptr cpu_cas01 = static_cast<CpuCas01Ptr>(ind_host[SURF_CPU_LEVEL]);
if (!ws)
continue;
/* skip if it is not a virtual machine */
- if (ws->p_model != static_cast<ModelPtr>(surf_vm_workstation_model))
+ if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
continue;
xbt_assert(cpu_cas01, "cpu-less workstation");
/* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- WorkstationVMLmmPtr ws_vm = dynamic_cast<WorkstationVMLmmPtr>(ws);
+ WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
- int is_active = lmm_constraint_used(cpu_cas01->p_model->p_maxminSystem, cpu_cas01->p_constraint);
+ int is_active = lmm_constraint_used(cpu_cas01->getModel()->getMaxminSystem(), cpu_cas01->getConstraint());
// int is_active_old = constraint_is_active(cpu_cas01);
// {
/************
* Resource *
************/
-Workstation::Workstation(xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
- : p_storage(storage), p_netElm(netElm), p_cpu(cpu)
-{}
+Workstation::Workstation()
+{
+ surf_callback_emit(workstationCreatedCallbacks, this);
+}
+
+Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props,
+ xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
+ : Resource(model, name, props)
+ , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
+{
+ p_params.ramsize = 0;
+ surf_callback_emit(workstationCreatedCallbacks, this);
+}
+
+Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
+ xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
+ : Resource(model, name, props, constraint)
+ , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
+{
+ p_params.ramsize = 0;
+ surf_callback_emit(workstationCreatedCallbacks, this);
+}
+
+Workstation::~Workstation(){
+ surf_callback_emit(workstationDestructedCallbacks, this);
+}
+
+void Workstation::setState(e_surf_resource_state_t state){
+ Resource::setState(state);
+ surf_callback_emit(workstationStateChangedCallbacks, this);
+}
int Workstation::getCore(){
return p_cpu->getCore();
p_cpu->setPowerPeakAt(pstate_index);
}
-double Workstation::getConsumedEnergy()
-{
- return p_cpu->getConsumedEnergy();
-}
-
xbt_dict_t Workstation::getProperties()
{
- return p_cpu->m_properties;
+ return p_cpu->getProperties();
}
-
StoragePtr Workstation::findStorageOnMountList(const char* mount)
{
StoragePtr st = NULL;
s_mount_t mnt;
unsigned int cursor;
- XBT_DEBUG("Search for storage name '%s' on '%s'", mount, m_name);
+ XBT_DEBUG("Search for storage name '%s' on '%s'", mount, getName());
xbt_dynar_foreach(p_storage,cursor,mnt)
{
XBT_DEBUG("See '%s'",mnt.name);
if(!strcmp(mount,mnt.name)){
- st = dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage));
+ st = static_cast<StoragePtr>(mnt.storage);
break;
}
}
- if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, m_name);
+ if(!st) xbt_die("Can't find mount '%s' for '%s'", mount, getName());
return st;
}
char *storage_name = NULL;
xbt_dynar_foreach(p_storage,i,mnt){
- storage_name = (char *)dynamic_cast<StoragePtr>(static_cast<ResourcePtr>(mnt.storage))->m_name;
+ storage_name = (char *)static_cast<StoragePtr>(mnt.storage)->getName();
xbt_dict_set(storage_list,mnt.name,storage_name,NULL);
}
return storage_list;
ActionPtr Workstation::open(const char* mount, const char* path) {
StoragePtr st = findStorageOnMountList(mount);
- XBT_DEBUG("OPEN on disk '%s'", st->m_name);
+ XBT_DEBUG("OPEN on disk '%s'", st->getName());
return st->open(mount, path);
}
ActionPtr Workstation::close(surf_file_t fd) {
StoragePtr st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("CLOSE on disk '%s'",st->m_name);
+ XBT_DEBUG("CLOSE on disk '%s'",st->getName());
return st->close(fd);
}
ActionPtr Workstation::read(surf_file_t fd, sg_size_t size) {
StoragePtr st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("READ on disk '%s'",st->m_name);
+ XBT_DEBUG("READ on disk '%s'",st->getName());
return st->read(fd, size);
}
ActionPtr Workstation::write(surf_file_t fd, sg_size_t size) {
StoragePtr st = findStorageOnMountList(fd->mount);
- XBT_DEBUG("WRITE on disk '%s'",st->m_name);
+ XBT_DEBUG("WRITE on disk '%s'",st->getName());
return st->write(fd, size);
}
/* Check if the file is on this storage */
if (!xbt_dict_get_or_null(st->p_content, fd->name)){
XBT_WARN("File %s is not on disk %s. Impossible to unlink", fd->name,
- st->m_name);
+ st->getName());
return 0;
} else {
- XBT_DEBUG("UNLINK on disk '%s'",st->m_name);
+ XBT_DEBUG("UNLINK on disk '%s'",st->getName());
st->m_usedSize -= fd->size;
// Remove the file from storage
xbt_dynar_t info = xbt_dynar_new(sizeof(void*), NULL);
xbt_dynar_push_as(info, sg_size_t *, psize);
xbt_dynar_push_as(info, void *, fd->mount);
- xbt_dynar_push_as(info, void *, (void *)st->m_name);
+ xbt_dynar_push_as(info, void *, (void *)st->getName());
xbt_dynar_push_as(info, void *, st->p_typeId);
xbt_dynar_push_as(info, void *, st->p_contentType);
char *key;
void **ind_host;
xbt_lib_foreach(host_lib, cursor, key, ind_host) {
- WorkstationPtr ws = dynamic_cast<WorkstationPtr>(static_cast<ResourcePtr>(ind_host[SURF_WKS_LEVEL]));
+ WorkstationPtr ws = static_cast<WorkstationPtr>(ind_host[SURF_WKS_LEVEL]);
if (!ws)
continue;
/* skip if it is not a virtual machine */
- if (ws->p_model != static_cast<ModelPtr>(surf_vm_workstation_model))
+ if (ws->getModel() != static_cast<ModelPtr>(surf_vm_workstation_model))
continue;
/* It is a virtual machine, so we can cast it to workstation_VM2013_t */
- WorkstationVMPtr ws_vm = dynamic_cast<WorkstationVMPtr>(ws);
+ WorkstationVMPtr ws_vm = static_cast<WorkstationVMPtr>(ws);
if (this == ws_vm-> p_subWs)
xbt_dynar_push(dyn, &ws_vm->p_subWs);
}
void Workstation::getParams(ws_params_t params)
{
- memcpy(params, &p_params, sizeof(s_ws_params_t));
+ *params = p_params;
}
void Workstation::setParams(ws_params_t params)
{
/* may check something here. */
- memcpy(&p_params, params, sizeof(s_ws_params_t));
+ p_params = *params;
}
/**********
* Action *
**********/
+
+void WorkstationAction::setState(e_surf_action_state_t state){
+ Action::setState(state);
+ surf_callback_emit(workstationActionStateChangedCallbacks, this);
+}