1 /* Copyright (c) 2006-2015, 2017. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/s4u/storage.hpp"
8 #include "simgrid/simix.hpp"
9 #include "src/surf/storage_interface.hpp"
11 #include <unordered_map>
13 extern xbt_lib_t storage_lib;
18 std::unordered_map<std::string, Storage*>* Storage::storages_ = new std::unordered_map<std::string, Storage*>();
20 Storage::Storage(std::string name, smx_storage_t inferior) :
21 name_(name), pimpl_(inferior)
23 hostname_ = surf_storage_get_host(pimpl_);
24 size_ = surf_storage_get_size(pimpl_);
25 storages_->insert({name, this});
28 Storage::~Storage() = default;
30 smx_storage_t Storage::inferior()
35 Storage& Storage::byName(const char* name)
37 s4u::Storage* res = nullptr;
39 res = storages_->at(name);
40 } catch (std::out_of_range& e) {
41 smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
42 if (inferior == nullptr)
43 xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
45 res = new Storage(name,inferior);
50 const char* Storage::name()
55 const char* Storage::host()
57 return hostname_.c_str();
60 sg_size_t Storage::sizeFree()
62 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); });
65 sg_size_t Storage::sizeUsed()
67 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); });
70 sg_size_t Storage::size() {
74 xbt_dict_t Storage::properties()
76 return simcall_storage_get_properties(pimpl_);
79 const char* Storage::property(const char* key)
81 return static_cast<const char*>(xbt_dict_get_or_null(this->properties(), key));
84 void Storage::setProperty(const char* key, char* value)
86 xbt_dict_set(this->properties(), key, value, nullptr);
89 std::map<std::string, sg_size_t*>* Storage::content()
91 return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); });
94 std::unordered_map<std::string, Storage*>* Storage::allStorages()
100 } /* namespace simgrid */