Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
allStorages() -> getStorageList(whereTo)
[simgrid.git] / include / simgrid / s4u / Storage.hpp
1 /* Copyright (c) 2006-2015, 2017. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
8 #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
9
10 #include "xbt/Extendable.hpp"
11 #include <map>
12 #include <simgrid/s4u/forward.hpp>
13 #include <simgrid/simix.h>
14 #include <string>
15 #include <unordered_map>
16 #include <xbt/base.h>
17
18 namespace simgrid {
19 namespace xbt {
20 extern template class XBT_PUBLIC() Extendable<simgrid::s4u::Storage>;
21 }
22 namespace s4u {
23
24 XBT_ATTRIB_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
25
26 XBT_PUBLIC_CLASS Storage : public simgrid::xbt::Extendable<Storage>
27 {
28   friend s4u::Engine;
29   friend simgrid::surf::StorageImpl;
30
31 public:
32   explicit Storage(surf::StorageImpl * pimpl) : pimpl_(pimpl) {}
33   virtual ~Storage() = default;
34   /** Retrieve a Storage by its name. It must exist in the platform file */
35   static Storage* byName(std::string name);
36   /** @brief Retrieves the name of that storage as a C++ string */
37   std::string const& getName() const;
38   /** @brief Retrieves the name of that storage as a C string */
39   const char* getCname() const;
40   const char* getType();
41   Host* getHost();
42
43   std::map<std::string, std::string>* getProperties();
44   const char* getProperty(std::string key);
45   void setProperty(std::string, std::string value);
46
47   void setUserdata(void* data) { userdata_ = data; }
48   void* getUserdata() { return userdata_; }
49
50   sg_size_t read(sg_size_t size);
51   sg_size_t write(sg_size_t size);
52   surf::StorageImpl* getImpl() { return pimpl_; }
53
54   /* The signals */
55   /** @brief Callback signal fired when a new Link is created */
56   static simgrid::xbt::signal<void(s4u::Storage&)> onCreation;
57
58   /** @brief Callback signal fired when a Link is destroyed */
59   static simgrid::xbt::signal<void(s4u::Storage&)> onDestruction;
60
61   Host* attached_to_              = nullptr;
62
63 private:
64   surf::StorageImpl* const pimpl_ = nullptr;
65   std::string name_;
66   void* userdata_ = nullptr;
67 };
68
69 } /* namespace s4u */
70 } /* namespace simgrid */
71
72 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */