X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/66f8d6364c9d16e5ba469db4c93d98da40ae007a..12ad1e7c01058fada33cecf2d4c4cb8bf9874f9e:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index d010801b6c..d8f004ac63 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -3,97 +3,85 @@ /* 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 "../surf/StorageImpl.hpp" +#include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "xbt/lib.h" +#include "src/plugins/file_system/FileSystem.hpp" +#include "src/surf/StorageImpl.hpp" #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) -{ - hostname_ = surf_storage_get_host(pimpl_); - size_ = surf_storage_get_size(pimpl_); - storages_->insert({name, this}); +namespace xbt { +template class Extendable; } -Storage::~Storage() = default; +namespace s4u { -smx_storage_t Storage::inferior() +void getStorageList(std::map* whereTo) { - return pimpl_; + for (auto const& s : *surf::StorageImpl::storagesMap()) + whereTo->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface } -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 std::string& Storage::getName() const { - return name_.c_str(); + return pimpl_->getName(); } -const char* Storage::host() +const char* Storage::getCname() const { - return hostname_.c_str(); + return pimpl_->getCname(); } -sg_size_t Storage::sizeFree() +const char* Storage::getType() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); }); + return pimpl_->typeId_.c_str(); } -sg_size_t Storage::sizeUsed() +Host* Storage::getHost() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); }); + return attached_to_; } -sg_size_t Storage::size() { - return size_; -} -xbt_dict_t Storage::properties() +std::map* Storage::getProperties() { - return simcall_storage_get_properties(pimpl_); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); } -const char* Storage::property(const char* key) +const char* Storage::getProperty(std::string key) { - return static_cast(xbt_dict_get_or_null(this->properties(), key)); + return this->pimpl_->getProperty(key); } -void Storage::setProperty(const char* key, char* value) +void Storage::setProperty(std::string key, std::string value) { - xbt_dict_set(this->properties(), key, value, nullptr); + simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); } -std::map* Storage::content() +sg_size_t Storage::read(sg_size_t size) { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); }); + return simcall_storage_read(pimpl_, size); } -std::unordered_map* Storage::allStorages() +sg_size_t Storage::write(sg_size_t size) { - return storages_; + return simcall_storage_write(pimpl_, size); } +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Storage::onCreation; +simgrid::xbt::signal Storage::onDestruction; + } /* namespace s4u */ } /* namespace simgrid */