Logo AND Algorithmique Numérique Distribuée

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