Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into master
[simgrid.git] / include / simgrid / s4u / Storage.hpp
1 /* Copyright (c) 2006-2018. 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 #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
7 #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Io.hpp>
11 #include <xbt/Extendable.hpp>
12 #include <xbt/base.h>
13 #include <xbt/signal.hpp>
14
15 #include <map>
16 #include <string>
17 #include <unordered_map>
18
19 namespace simgrid {
20 namespace s4u {
21
22 #ifndef DOXYGEN
23 /** @deprecated Engine::get_all_storages() */
24 XBT_ATTRIB_DEPRECATED_v322("Please use Engine::get_all_storages()") XBT_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
25 #endif
26
27 /** Storage represent the disk resources, usually associated to a given host
28  *
29  * By default, SimGrid does not keep track of the actual data being written but
30  * only computes the time taken by the corresponding data movement.
31  */
32
33 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
34   friend simgrid::s4u::Engine;
35   friend simgrid::s4u::Io;
36   friend simgrid::surf::StorageImpl;
37
38 public:
39   explicit Storage(std::string name, surf::StorageImpl * pimpl);
40
41 protected:
42   virtual ~Storage() = default;
43 public:
44   /** @brief Callback signal fired when a new Storage is created */
45   static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
46   /** @brief Callback signal fired when a Storage is destroyed */
47   static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
48   /** @brief Callback signal fired when a Storage's state changes */
49   static simgrid::xbt::signal<void(s4u::Storage&)> on_state_change;
50
51   /** Retrieve a Storage by its name. It must exist in the platform file */
52   static Storage* by_name(std::string name);
53   static Storage* by_name_or_null(std::string name);
54
55   /** @brief Retrieves the name of that storage as a C++ string */
56   std::string const& get_name() const { return name_; }
57   /** @brief Retrieves the name of that storage as a C string */
58   const char* get_cname() const { return name_.c_str(); }
59
60   const char* get_type();
61   Host* get_host() { return attached_to_; };
62   void set_host(Host* host) { attached_to_ = host; }
63
64   std::unordered_map<std::string, std::string>* get_properties();
65   const char* get_property(std::string key);
66   void set_property(std::string, std::string value);
67
68   void set_data(void* data) { userdata_ = data; }
69   void* get_data() { return userdata_; }
70
71   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
72
73   IoPtr read_async(sg_size_t size);
74   sg_size_t read(sg_size_t size);
75
76   IoPtr write_async(sg_size_t size);
77   sg_size_t write(sg_size_t size);
78   surf::StorageImpl* get_impl() { return pimpl_; }
79
80   // Deprecated functions
81   /** @deprecated Storage::by_name() */
82   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name)
83   {
84     return by_name(name);
85   }
86   /** @deprecated Storage::get_name() */
87   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); }
88   /** @deprecated Storage::get_cname() */
89   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); }
90   /** @deprecated Storage::get_type() */
91   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_type()") const char* getType() { return get_type(); }
92   /** @deprecated Storage::get_host() */
93   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); }
94   /** @deprecated Storage::get_properties() */
95   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_properties()") std::map<std::string, std::string>* getProperties()
96   {
97     std::map<std::string, std::string>* res             = new std::map<std::string, std::string>();
98     std::unordered_map<std::string, std::string>* props = get_properties();
99     for (auto const& kv : *props)
100       res->insert(kv);
101     return res;
102   }
103   /** @deprecated Storage::get_property() */
104   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key)
105   {
106     return get_property(key);
107   }
108   /** @deprecated Storage::set_property() */
109   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_property()") void setProperty(std::string key, std::string value)
110   {
111     set_property(key, value);
112   }
113   /** @deprecated Storage::set_data() */
114   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); }
115   /** @deprecated Storage::get_data() */
116   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); }
117
118 private:
119   Host* attached_to_              = nullptr;
120   surf::StorageImpl* const pimpl_ = nullptr;
121   std::string name_;
122   void* userdata_ = nullptr;
123 };
124
125 } /* namespace s4u */
126 } /* namespace simgrid */
127
128 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */