X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7335dd97eb58110e47e7a1c9d6603093e1d01091..13fb4af932a02ea0bd4293d1e55ac071de326f80:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 53cfb30ce4..23c7e603f3 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -1,79 +1,60 @@ -/* Copyright (c) 2006-2015, 2017. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2006-2017. 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 "simgrid/s4u/storage.hpp" +#include "../surf/StorageImpl.hpp" +#include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "src/surf/storage_interface.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}); -} + std::unordered_map* map = surf::StorageImpl::storagesMap(); + std::map* res = new std::map; + for (auto s : *map) + res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface -Storage::~Storage() = default; - -smx_storage_t Storage::inferior() -{ - return pimpl_; + return res; } -Storage& Storage::byName(const char* name) +Storage* Storage::byName(const char* 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() { - return name_.c_str(); + return pimpl_->cname(); } const char* Storage::host() { - return hostname_.c_str(); + return pimpl_->attach_; } sg_size_t Storage::sizeFree() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); }); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); }); } sg_size_t Storage::sizeUsed() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); }); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); }); } sg_size_t Storage::size() { - return size_; + return pimpl_->size_; } xbt_dict_t Storage::properties() { - return simcall_storage_get_properties(pimpl_); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); } const char* Storage::property(const char* key) @@ -88,13 +69,14 @@ void Storage::setProperty(const char* key, char* value) std::map* Storage::content() { - return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); }); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); } -std::unordered_map* Storage::allStorages() -{ - return storages_; -} +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Storage::onCreation; +simgrid::xbt::signal Storage::onDestruction; } /* namespace s4u */ } /* namespace simgrid */