Logo AND Algorithmique Numérique Distribuée

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