1 /* Copyright (c) 2006-2015. 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"
12 extern xbt_lib_t storage_lib;
17 boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
18 Storage::Storage(std::string name, smx_storage_t inferior) :
19 name_(name), pimpl_(inferior)
21 size_ = SIMIX_storage_get_size(pimpl_);
22 storages_->insert({name, this});
25 Storage::~Storage() = default;
27 smx_storage_t Storage::inferior() {
30 Storage &Storage::byName(const char*name) {
31 s4u::Storage *res = nullptr;
33 res = storages_->at(name);
34 } catch (std::out_of_range& e) {
35 smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
36 if (inferior == nullptr)
37 xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
39 res = new Storage(name,inferior);
44 const char* Storage::name()
49 sg_size_t Storage::sizeFree()
51 return simcall_storage_get_free_size(pimpl_);
54 sg_size_t Storage::sizeUsed()
56 return simcall_storage_get_used_size(pimpl_);
59 sg_size_t Storage::size() {
63 xbt_dict_t Storage::properties()
65 return simcall_storage_get_properties(pimpl_);
68 std::map<std::string, sg_size_t*>* Storage::content()
70 return simgrid::simix::kernelImmediate(
71 [this] { return static_cast<simgrid::surf::Storage*>(surf_storage_resource_priv(this->pimpl_))->getContent(); });
75 } /* namespace simgrid */