Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fixing codacy warnings on multi-core VM tests + using a dedicated platform file for...
[simgrid.git] / src / s4u / s4u_storage.cpp
1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "../surf/StorageImpl.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "simgrid/simix.hpp"
9 #include "xbt/lib.h"
10 #include <unordered_map>
11
12 extern xbt_lib_t storage_lib;
13
14 namespace simgrid {
15 namespace s4u {
16
17 std::unordered_map<std::string, Storage*>* Storage::storages_ = new std::unordered_map<std::string, Storage*>();
18
19 Storage::Storage(std::string name, smx_storage_t inferior) :
20     name_(name), pimpl_(inferior)
21 {
22   hostname_ = surf_storage_get_host(pimpl_);
23   size_     = surf_storage_get_size(pimpl_);
24   storages_->insert({name, this});
25 }
26
27 Storage::~Storage() = default;
28
29 smx_storage_t Storage::inferior()
30 {
31   return pimpl_;
32 }
33
34 Storage& Storage::byName(const char* name)
35 {
36   s4u::Storage* res = nullptr;
37   try {
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);
43
44     res = new Storage(name,inferior);
45   }
46   return *res;
47 }
48
49 const char* Storage::name()
50 {
51   return name_.c_str();
52 }
53
54 const char* Storage::host()
55 {
56   return hostname_.c_str();
57 }
58
59 sg_size_t Storage::sizeFree()
60 {
61   return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getFreeSize(); });
62 }
63
64 sg_size_t Storage::sizeUsed()
65 {
66   return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(pimpl_)->getUsedSize(); });
67 }
68
69 sg_size_t Storage::size() {
70   return size_;
71 }
72
73 xbt_dict_t Storage::properties()
74 {
75   return simcall_storage_get_properties(pimpl_);
76 }
77
78 const char* Storage::property(const char* key)
79 {
80   return static_cast<const char*>(xbt_dict_get_or_null(this->properties(), key));
81 }
82
83 void Storage::setProperty(const char* key, char* value)
84 {
85   xbt_dict_set(this->properties(), key, value, nullptr);
86 }
87
88 std::map<std::string, sg_size_t*>* Storage::content()
89 {
90   return simgrid::simix::kernelImmediate([this] { return surf_storage_resource_priv(this->pimpl_)->getContent(); });
91 }
92
93 std::unordered_map<std::string, Storage*>* Storage::allStorages()
94 {
95   return storages_;
96 }
97
98 } /* namespace s4u */
99 } /* namespace simgrid */