Logo AND Algorithmique Numérique Distribuée

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