Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allStorages() -> getStorageList(whereTo)
[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/plugins/file_system/FileSystem.hpp"
10 #include "src/surf/StorageImpl.hpp"
11 #include <unordered_map>
12
13 namespace simgrid {
14 namespace xbt {
15 template class Extendable<simgrid::s4u::Storage>;
16 }
17
18 namespace s4u {
19
20 void getStorageList(std::map<std::string, Storage*>* whereTo)
21 {
22   for (auto const& s : *surf::StorageImpl::storagesMap())
23     whereTo->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
24 }
25
26 Storage* Storage::byName(std::string 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 std::string& Storage::getName() const
35 {
36   return pimpl_->getName();
37 }
38
39 const char* Storage::getCname() const
40 {
41   return pimpl_->getCname();
42 }
43
44 const char* Storage::getType()
45 {
46   return pimpl_->typeId_.c_str();
47 }
48
49 Host* Storage::getHost()
50 {
51   return attached_to_;
52 }
53
54
55 std::map<std::string, std::string>* Storage::getProperties()
56 {
57   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
58 }
59
60 const char* Storage::getProperty(std::string key)
61 {
62   return this->pimpl_->getProperty(key);
63 }
64
65 void Storage::setProperty(std::string key, std::string value)
66 {
67   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
68 }
69
70 sg_size_t Storage::read(sg_size_t size)
71 {
72   return simcall_storage_read(pimpl_, size);
73 }
74
75 sg_size_t Storage::write(sg_size_t size)
76 {
77   return simcall_storage_write(pimpl_, size);
78 }
79
80 /*************
81  * Callbacks *
82  *************/
83 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
84 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
85
86 } /* namespace s4u */
87 } /* namespace simgrid */