Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change cname() to getCname() and add getName() in surf::Resource.
[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 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 char* Storage::getName()
34 {
35   return pimpl_->getCname();
36 }
37
38 const char* Storage::getType()
39 {
40   return pimpl_->typeId_.c_str();
41 }
42
43 Host* Storage::getHost()
44 {
45   return attached_to_;
46 }
47
48 sg_size_t Storage::getSizeFree()
49 {
50   return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
51 }
52
53 sg_size_t Storage::getSizeUsed()
54 {
55   return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
56 }
57
58 sg_size_t Storage::getSize()
59 {
60   return pimpl_->getSize();
61 }
62
63 std::map<std::string, std::string>* Storage::getProperties()
64 {
65   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
66 }
67
68 const char* Storage::getProperty(const char* key)
69 {
70   return this->pimpl_->getProperty(key);
71 }
72
73 void Storage::setProperty(const char* key, const char* value)
74 {
75   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
76 }
77
78 std::map<std::string, sg_size_t>* Storage::getContent()
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 */