X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/ba9a4cfeba4eb00e84cd17603fc9654e81445655..2f3bc1bedb87e982714241309c59180d10d87c94:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 6b99ef8bde..d10a19d886 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -1,59 +1,89 @@ -/* 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 "xbt/lib.h" -extern xbt_lib_t storage_lib; +#include "../surf/StorageImpl.hpp" +#include "simgrid/s4u/Host.hpp" +#include "simgrid/s4u/Storage.hpp" +#include "simgrid/simix.hpp" +#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; - inferior_ = inferior; +std::map* allStorages() +{ + 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 - storages_->insert({name, this}); + return res; } -Storage::~Storage() { - // TODO Auto-generated destructor stub +Storage* Storage::byName(const char* name) +{ + surf::StorageImpl* res = surf::StorageImpl::byName(name); + if (res == nullptr) + return nullptr; + return &res->piface_; } -smx_storage_t Storage::inferior() { - return inferior_; +const char* Storage::name() +{ + return pimpl_->cname(); } -Storage &Storage::byName(const char*name) { - s4u::Storage *res = NULL; - 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 == NULL) - 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::type() +{ + return pimpl_->typeId_.c_str(); } -const char*Storage::name() { - return name_.c_str(); +Host* Storage::host() +{ + return attached_to_; } -sg_size_t Storage::sizeFree() { - return simcall_storage_get_free_size(inferior_); +sg_size_t Storage::sizeFree() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); }); } -sg_size_t Storage::sizeUsed() { - return simcall_storage_get_used_size(inferior_); + +sg_size_t Storage::sizeUsed() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); }); } + sg_size_t Storage::size() { - return SIMIX_storage_get_size(inferior_); + return pimpl_->size_; +} + +xbt_dict_t Storage::properties() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); }); +} + +const char* Storage::property(const char* key) +{ + return static_cast(xbt_dict_get_or_null(this->properties(), key)); +} + +void Storage::setProperty(const char* key, char* value) +{ + xbt_dict_set(this->properties(), key, value, nullptr); } +std::map* Storage::content() +{ + return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); }); +} + +/************* + * Callbacks * + *************/ +simgrid::xbt::signal Storage::onCreation; +simgrid::xbt::signal Storage::onDestruction; + } /* namespace s4u */ } /* namespace simgrid */