Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'upstream/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 <xbt/Extendable.hpp>
11 #include <xbt/base.h>
12
13 #include <map>
14 #include <string>
15 #include <unordered_map>
16
17 namespace simgrid {
18 namespace xbt {
19 extern template class XBT_PUBLIC Extendable<simgrid::s4u::Storage>;
20 }
21 namespace s4u {
22
23 XBT_ATTRIB_DEPRECATED_v322("Please use Engine::get_all_storages()") XBT_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
24
25 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
26   friend s4u::Engine;
27   friend simgrid::surf::StorageImpl;
28
29 public:
30   explicit Storage(std::string name, surf::StorageImpl * pimpl);
31
32 protected:
33   virtual ~Storage() = default;
34
35 public:
36   /** @brief Callback signal fired when a new Storage is created */
37   static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
38   /** @brief Callback signal fired when a Storage is destroyed */
39   static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
40   /** @brief Callback signal fired when a Storage's state changes */
41   static simgrid::xbt::signal<void(s4u::Storage&)> on_state_change;
42
43   /** Retrieve a Storage by its name. It must exist in the platform file */
44   static Storage* by_name(std::string name);
45   static Storage* by_name_or_null(std::string name);
46
47   /** @brief Retrieves the name of that storage as a C++ string */
48   std::string const& get_name() const { return name_; }
49   /** @brief Retrieves the name of that storage as a C string */
50   const char* get_cname() const { return name_.c_str(); }
51
52   const char* get_type();
53   Host* get_host() { return attached_to_; };
54   void set_host(Host* host) { attached_to_ = host; }
55
56   std::unordered_map<std::string, std::string>* get_properties();
57   const char* get_property(std::string key);
58   void set_property(std::string, std::string value);
59
60   void set_data(void* data) { userdata_ = data; }
61   void* get_data() { return userdata_; }
62
63   sg_size_t read(sg_size_t size);
64   sg_size_t write(sg_size_t size);
65   surf::StorageImpl* get_impl() { return pimpl_; }
66
67   // Deprecated functions
68   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name)
69   {
70     return by_name(name);
71   }
72   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); }
73   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); }
74   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_type()") const char* getType() { return get_type(); }
75   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); }
76   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_properties()") std::map<std::string, std::string>* getProperties()
77   {
78     std::map<std::string, std::string>* res             = new std::map<std::string, std::string>();
79     std::unordered_map<std::string, std::string>* props = get_properties();
80     for (auto const& kv : *props)
81       res->insert(kv);
82     return res;
83   }
84   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key)
85   {
86     return get_property(key);
87   }
88   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_property()") void setProperty(std::string key, std::string value)
89   {
90     set_property(key, value);
91   }
92   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); }
93   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); }
94
95 private:
96   Host* attached_to_              = nullptr;
97   surf::StorageImpl* const pimpl_ = nullptr;
98   std::string name_;
99   void* userdata_ = nullptr;
100 };
101
102 } /* namespace s4u */
103 } /* namespace simgrid */
104
105 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */