X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/a92d7b716f51a53dea7f59db8524d4add713b910..5bc3597e1513c7b94497ae0ea819e5fa2e28058a:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index d010801b6c..092afea5ef 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -4,96 +4,87 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "../surf/StorageImpl.hpp" +#include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "xbt/lib.h" #include -extern xbt_lib_t storage_lib; - namespace simgrid { namespace s4u { -std::unordered_map* Storage::storages_ = new std::unordered_map(); - -Storage::Storage(std::string name, smx_storage_t inferior) : - name_(name), pimpl_(inferior) +std::map* allStorages() { - hostname_ = surf_storage_get_host(pimpl_); - size_ = surf_storage_get_size(pimpl_); - storages_->insert({name, this}); -} - -Storage::~Storage() = default; + std::unordered_map* map = surf::StorageImpl::storagesMap(); + std::map* res = new std::map; + for (auto const& s : *map) + res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface -smx_storage_t Storage::inferior() -{ - return pimpl_; + return res; } -Storage& Storage::byName(const char* name) +Storage* Storage::byName(std::string name) { - s4u::Storage* res = nullptr; - try { - res = storages_->at(name); - } catch (std::out_of_range& e) { - smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name); - if (inferior == nullptr) - xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name); - - res = new Storage(name,inferior); - } - return *res; + surf::StorageImpl* res = surf::StorageImpl::byName(name); + if (res == nullptr) + return nullptr; + return &res->piface_; } -const char* Storage::name() +const char* Storage::getName() { - return name_.c_str(); + return pimpl_->cname(); } -const char* Storage::host() +const char* Storage::getType() { - return hostname_.c_str(); + return pimpl_->typeId_.c_str(); } -sg_size_t Storage::sizeFree() +Host* Storage::getHost() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); }); + return attached_to_; } -sg_size_t Storage::sizeUsed() +sg_size_t Storage::getSizeFree() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); }); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); }); } -sg_size_t Storage::size() { - return size_; +sg_size_t Storage::getSizeUsed() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); }); } -xbt_dict_t Storage::properties() +sg_size_t Storage::getSize() { - return simcall_storage_get_properties(pimpl_); + return pimpl_->getSize(); } -const char* Storage::property(const char* key) +std::map* Storage::getProperties() { - return static_cast(xbt_dict_get_or_null(this->properties(), key)); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); } -void Storage::setProperty(const char* key, char* value) +const char* Storage::getProperty(const char* key) { - xbt_dict_set(this->properties(), key, value, nullptr); + return this->pimpl_->getProperty(key); } -std::map* Storage::content() +void Storage::setProperty(const char* key, const char* value) { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); }); + simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); } -std::unordered_map* Storage::allStorages() +std::map* Storage::getContent() { - return storages_; + return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); } +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Storage::onCreation; +simgrid::xbt::signal Storage::onDestruction; + } /* namespace s4u */ } /* namespace simgrid */