Logo AND Algorithmique Numérique Distribuée

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