X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/4a69abcc786d029bd2962537f767d12a0f808d11..1847d1441271d076b3de449c8853031ea208ce8f:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 48c58d71da..092afea5ef 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -1,75 +1,90 @@ -/* Copyright (c) 2006-2015. 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/Host.hpp" +#include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "src/surf/storage_interface.hpp" - -#include "xbt/lib.h" -extern xbt_lib_t storage_lib; +#include namespace simgrid { namespace s4u { -boost::unordered_map *Storage::storages_ = new boost::unordered_map (); -Storage::Storage(std::string name, smx_storage_t inferior) : - name_(name), pimpl_(inferior) +std::map* allStorages() { - size_ = SIMIX_storage_get_size(pimpl_); - storages_->insert({name, this}); + 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 + + return res; } -Storage::~Storage() = default; +Storage* Storage::byName(std::string name) +{ + surf::StorageImpl* res = surf::StorageImpl::byName(name); + if (res == nullptr) + return nullptr; + return &res->piface_; +} -smx_storage_t Storage::inferior() { - return pimpl_; +const char* Storage::getName() +{ + return pimpl_->cname(); } -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; + +const char* Storage::getType() +{ + return pimpl_->typeId_.c_str(); } -const char* Storage::name() +Host* Storage::getHost() { - return name_.c_str(); + return attached_to_; } -sg_size_t Storage::sizeFree() +sg_size_t Storage::getSizeFree() { - return simcall_storage_get_free_size(pimpl_); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); }); } -sg_size_t Storage::sizeUsed() +sg_size_t Storage::getSizeUsed() { - return simcall_storage_get_used_size(pimpl_); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); }); } -sg_size_t Storage::size() { - return size_; +sg_size_t Storage::getSize() +{ + return pimpl_->getSize(); } -xbt_dict_t Storage::properties() +std::map* Storage::getProperties() { - return simcall_storage_get_properties(pimpl_); + return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); } -std::map* Storage::content() +const char* Storage::getProperty(const char* key) { - return simgrid::simix::kernelImmediate( - [this] { return static_cast(surf_storage_resource_priv(this->pimpl_))->getContent(); }); + return this->pimpl_->getProperty(key); } +void Storage::setProperty(const char* key, const char* value) +{ + simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); }); +} + +std::map* Storage::getContent() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); +} + +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Storage::onCreation; +simgrid::xbt::signal Storage::onDestruction; + } /* namespace s4u */ } /* namespace simgrid */