1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u/Storage.hpp"
7 #include "simgrid/simix.hpp"
8 #include "src/surf/storage_interface.hpp"
10 #include <unordered_map>
12 extern xbt_lib_t storage_lib;
17 std::unordered_map<std::string, Storage*>* Storage::storages_ = new std::unordered_map<std::string, Storage*>();
19 Storage::Storage(std::string name, smx_storage_t inferior) :
20 name_(name), pimpl_(inferior)
22 hostname_ = surf_storage_get_host(pimpl_);
23 size_ = surf_storage_get_size(pimpl_);
24 storages_->insert({name, this});
27 Storage::~Storage() = default;
29 smx_storage_t Storage::inferior()
34 Storage& Storage::byName(const char* name)
36 s4u::Storage* res = nullptr;
38 res = storages_->at(name);
39 } catch (std::out_of_range& e) {
40 smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
41 if (inferior == nullptr)
42 xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
44 res = new Storage(name,inferior);
49 const char* Storage::name()
54 const char* Storage::host()
56 return hostname_.c_str();
59 sg_size_t Storage::sizeFree()
61 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); });
64 sg_size_t Storage::sizeUsed()
66 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); });
69 sg_size_t Storage::size() {
73 xbt_dict_t Storage::properties()
75 return simcall_storage_get_properties(pimpl_);
78 const char* Storage::property(const char* key)
80 return static_cast<const char*>(xbt_dict_get_or_null(this->properties(), key));
83 void Storage::setProperty(const char* key, char* value)
85 xbt_dict_set(this->properties(), key, value, nullptr);
88 std::map<std::string, sg_size_t*>* Storage::content()
90 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); });
93 std::unordered_map<std::string, Storage*>* Storage::allStorages()
99 } /* namespace simgrid */