Logo AND Algorithmique Numérique Distribuée

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