Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify how we find platf files from teshsuite
[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/File.hpp"
7 #include "simgrid/s4u/Host.hpp"
8 #include "simgrid/s4u/Storage.hpp"
9 #include "simgrid/simix.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 std::map<std::string, Storage*>* allStorages()
21 {
22   std::unordered_map<std::string, surf::StorageImpl*>* map = surf::StorageImpl::storagesMap();
23   std::map<std::string, Storage*>* res                     = new std::map<std::string, Storage*>;
24   for (auto const& s : *map)
25     res->insert({s.first, &(s.second->piface_)}); // Convert each entry into its interface
26
27   return res;
28 }
29
30 Storage* Storage::byName(std::string name)
31 {
32   surf::StorageImpl* res = surf::StorageImpl::byName(name);
33   if (res == nullptr)
34     return nullptr;
35   return &res->piface_;
36 }
37
38 const std::string& Storage::getName() const
39 {
40   return pimpl_->getName();
41 }
42
43 const char* Storage::getCname() const
44 {
45   return pimpl_->getCname();
46 }
47
48 const char* Storage::getType()
49 {
50   return pimpl_->typeId_.c_str();
51 }
52
53 Host* Storage::getHost()
54 {
55   return attached_to_;
56 }
57
58
59 std::map<std::string, std::string>* Storage::getProperties()
60 {
61   return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
62 }
63
64 const char* Storage::getProperty(std::string key)
65 {
66   return this->pimpl_->getProperty(key);
67 }
68
69 void Storage::setProperty(std::string key, std::string value)
70 {
71   simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
72 }
73
74 std::map<std::string, sg_size_t>* Storage::getContent()
75 {
76   FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
77   return file_system->getContent();
78 }
79
80 sg_size_t Storage::read(sg_size_t size)
81 {
82   return simcall_storage_read(pimpl_, size);
83 }
84
85 sg_size_t Storage::write(sg_size_t size)
86 {
87   return simcall_storage_write(pimpl_, size);
88 }
89
90 /*************
91  * Callbacks *
92  *************/
93 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onCreation;
94 simgrid::xbt::signal<void(s4u::Storage&)> Storage::onDestruction;
95
96 } /* namespace s4u */
97 } /* namespace simgrid */