Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #237 from oar-team/upstream
[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 "simgrid/s4u/Host.hpp"
7 #include "simgrid/s4u/Storage.hpp"
8 #include "simgrid/simix.hpp"
9 #include "src/surf/StorageImpl.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 const& 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(std::string 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 std::string& Storage::getName() const
34 {
35   return pimpl_->getName();
36 }
37
38 const char* Storage::getCname() const
39 {
40   return pimpl_->getCname();
41 }
42
43 const char* Storage::getType()
44 {
45   return pimpl_->typeId_.c_str();
46 }
47
48 Host* Storage::getHost()
49 {
50   return attached_to_;
51 }
52
53 sg_size_t Storage::getSizeFree()
54 {
55   return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
56 }
57
58 sg_size_t Storage::getSizeUsed()
59 {
60   return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
61 }
62
63 void Storage::decrUsedSize(sg_size_t size)
64 {
65   simgrid::simix::kernelImmediate([this, size] { pimpl_->usedSize_ -= size; });
66 }
67
68 sg_size_t Storage::getSize()
69 {
70   return pimpl_->getSize();
71 }
72
73 std::map<std::string, std::string>* Storage::getProperties()
74 {
75   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
76 }
77
78 const char* Storage::getProperty(std::string key)
79 {
80   return this->pimpl_->getProperty(key);
81 }
82
83 void Storage::setProperty(std::string key, std::string value)
84 {
85   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
86 }
87
88 std::map<std::string, sg_size_t>* Storage::getContent()
89 {
90   return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
91 }
92
93 sg_size_t Storage::read(sg_size_t size)
94 {
95   return simcall_storage_read(pimpl_, size);
96 }
97
98 sg_size_t Storage::write(sg_size_t size)
99 {
100   return simcall_storage_write(pimpl_, size);
101 }
102
103 /*************
104  * Callbacks *
105  *************/
106 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
107 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
108
109 } /* namespace s4u */
110 } /* namespace simgrid */