X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7981fe568ccfcc3c517bd73ac146d2b59fa85ea2..c139b4e36702f58bd8a75e87cf537959da82dbc9:/src/s4u/s4u_storage.cpp diff --git a/src/s4u/s4u_storage.cpp b/src/s4u/s4u_storage.cpp index 983b597ddc..1c3d02d8b6 100644 --- a/src/s4u/s4u_storage.cpp +++ b/src/s4u/s4u_storage.cpp @@ -1,15 +1,18 @@ -/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2006-2018. 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/msg.h" +#include "simgrid/kernel/resource/Resource.hpp" +#include "simgrid/plugins/file_system.h" +#include "simgrid/s4u/Engine.hpp" #include "simgrid/s4u/Host.hpp" #include "simgrid/s4u/Storage.hpp" #include "simgrid/simix.hpp" -#include "src/kernel/model/Resource.hpp" -#include "src/plugins/file_system/FileSystem.hpp" +#include "simgrid/storage.h" #include "src/surf/StorageImpl.hpp" + +#include #include namespace simgrid { @@ -19,28 +22,32 @@ template class Extendable; namespace s4u { -void getStorageList(std::map* whereTo) +void XBT_ATTRIB_DEPRECATED_v322( + "simgrid::s4u::getStorageList() is deprecated in favor of Engine::getAllStorages(). Please switch before v3.22") + getStorageList(std::map* whereTo) +{ + for (auto const& s : simgrid::s4u::Engine::getInstance()->getAllStorages()) + whereTo->insert({s->get_name(), s}); +} + +Storage::Storage(std::string name, surf::StorageImpl* pimpl) : pimpl_(pimpl), name_(name) { - for (auto const& s : *surf::StorageImpl::storagesMap()) - whereTo->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface + simgrid::s4u::Engine::getInstance()->addStorage(name, this); } Storage* Storage::byName(std::string name) { - surf::StorageImpl* res = surf::StorageImpl::byName(name); - if (res == nullptr) - return nullptr; - return &res->piface_; + return Engine::getInstance()->storageByNameOrNull(name); } -const std::string& Storage::getName() const +const std::string& Storage::get_name() const { - return pimpl_->getName(); + return name_; } -const char* Storage::getCname() const +const char* Storage::get_cname() const { - return pimpl_->getCname(); + return name_.c_str(); } const char* Storage::getType() @@ -88,7 +95,7 @@ simgrid::xbt::signal Storage::onDestruction; } /* namespace simgrid */ /* **************************** Public C interface *************************** */ -SG_BEGIN_DECL() + /** @addtogroup sg_storage_management * (#sg_storage_t) and the functions for managing it. */ @@ -102,13 +109,13 @@ SG_BEGIN_DECL() const char* sg_storage_get_name(sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->getCname(); + return storage->get_cname(); } const char* sg_storage_get_host(sg_storage_t storage) { xbt_assert((storage != nullptr), "Invalid parameters"); - return storage->getHost()->getCname(); + return storage->getHost()->get_cname(); } /** \ingroup sg_storage_management @@ -136,7 +143,7 @@ xbt_dict_t sg_storage_get_properties(sg_storage_t storage) * \param name a property name * \param value what to change the property to */ -void sg_storage_set_property_value(sg_storage_t storage, const char* name, char* value) +void sg_storage_set_property_value(sg_storage_t storage, const char* name, const char* value) { storage->setProperty(name, value); } @@ -168,12 +175,10 @@ sg_storage_t sg_storage_get_by_name(const char* name) */ xbt_dynar_t sg_storages_as_dynar() { - std::map* storage_list = new std::map; - simgrid::s4u::getStorageList(storage_list); + std::vector storage_list = simgrid::s4u::Engine::getInstance()->getAllStorages(); xbt_dynar_t res = xbt_dynar_new(sizeof(sg_storage_t), nullptr); - for (auto const& s : *storage_list) - xbt_dynar_push(res, &(s.second)); - delete storage_list; + for (auto const& s : storage_list) + xbt_dynar_push(res, &s); return res; } @@ -197,4 +202,3 @@ sg_size_t sg_storage_write(sg_storage_t storage, sg_size_t size) { return storage->write(size); } -SG_END_DECL()