Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d10a19d886235558905db535d5243942a323adc9
[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/Host.hpp"
8 #include "simgrid/s4u/Storage.hpp"
9 #include "simgrid/simix.hpp"
10 #include <unordered_map>
11
12 namespace simgrid {
13 namespace s4u {
14
15 std::map<std::string, Storage*>* allStorages()
16 {
17   std::unordered_map<std::string, surf::StorageImpl*>* map = surf::StorageImpl::storagesMap();
18   std::map<std::string, Storage*>* res                     = new std::map<std::string, Storage*>;
19   for (auto s : *map)
20     res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
21
22   return res;
23 }
24
25 Storage* Storage::byName(const char* name)
26 {
27   surf::StorageImpl* res = surf::StorageImpl::byName(name);
28   if (res == nullptr)
29     return nullptr;
30   return &res->piface_;
31 }
32
33 const char* Storage::name()
34 {
35   return pimpl_->cname();
36 }
37
38 const char* Storage::type()
39 {
40   return pimpl_->typeId_.c_str();
41 }
42
43 Host* Storage::host()
44 {
45   return attached_to_;
46 }
47
48 sg_size_t Storage::sizeFree()
49 {
50   return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
51 }
52
53 sg_size_t Storage::sizeUsed()
54 {
55   return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
56 }
57
58 sg_size_t Storage::size() {
59   return pimpl_->size_;
60 }
61
62 xbt_dict_t Storage::properties()
63 {
64   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
65 }
66
67 const char* Storage::property(const char* key)
68 {
69   return static_cast<const char*>(xbt_dict_get_or_null(this->properties(), key));
70 }
71
72 void Storage::setProperty(const char* key, char* value)
73 {
74   xbt_dict_set(this->properties(), key, value, nullptr);
75 }
76
77 std::map<std::string, sg_size_t>* Storage::content()
78 {
79   return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
80 }
81
82 /*************
83  * Callbacks *
84  *************/
85 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
86 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
87
88 } /* namespace s4u */
89 } /* namespace simgrid */