1 /* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
7 #define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Io.hpp>
11 #include <xbt/Extendable.hpp>
13 #include <xbt/signal.hpp>
17 #include <unordered_map>
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);
27 /** Storage represent the disk resources, usually associated to a given host */
29 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
30 friend simgrid::s4u::Engine;
31 friend simgrid::s4u::Io;
32 friend simgrid::surf::StorageImpl;
35 explicit Storage(std::string name, surf::StorageImpl * pimpl);
38 virtual ~Storage() = default;
40 /** @brief Callback signal fired when a new Storage is created */
41 static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
42 /** @brief Callback signal fired when a Storage is destroyed */
43 static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
44 /** @brief Callback signal fired when a Storage's state changes */
45 static simgrid::xbt::signal<void(s4u::Storage&)> on_state_change;
47 /** Retrieve a Storage by its name. It must exist in the platform file */
48 static Storage* by_name(std::string name);
49 static Storage* by_name_or_null(std::string name);
51 /** @brief Retrieves the name of that storage as a C++ string */
52 std::string const& get_name() const { return name_; }
53 /** @brief Retrieves the name of that storage as a C string */
54 const char* get_cname() const { return name_.c_str(); }
56 const char* get_type();
57 Host* get_host() { return attached_to_; };
58 void set_host(Host* host) { attached_to_ = host; }
60 std::unordered_map<std::string, std::string>* get_properties();
61 const char* get_property(std::string key);
62 void set_property(std::string, std::string value);
64 void set_data(void* data) { userdata_ = data; }
65 void* get_data() { return userdata_; }
67 IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
69 IoPtr read_async(sg_size_t size);
70 sg_size_t read(sg_size_t size);
72 IoPtr write_async(sg_size_t size);
73 sg_size_t write(sg_size_t size);
74 surf::StorageImpl* get_impl() { return pimpl_; }
76 // Deprecated functions
77 /** @deprecated Storage::by_name() */
78 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name)
82 /** @deprecated Storage::get_name() */
83 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); }
84 /** @deprecated Storage::get_cname() */
85 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); }
86 /** @deprecated Storage::get_type() */
87 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_type()") const char* getType() { return get_type(); }
88 /** @deprecated Storage::get_host() */
89 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); }
90 /** @deprecated Storage::get_properties() */
91 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_properties()") std::map<std::string, std::string>* getProperties()
93 std::map<std::string, std::string>* res = new std::map<std::string, std::string>();
94 std::unordered_map<std::string, std::string>* props = get_properties();
95 for (auto const& kv : *props)
99 /** @deprecated Storage::get_property() */
100 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key)
102 return get_property(key);
104 /** @deprecated Storage::set_property() */
105 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_property()") void setProperty(std::string key, std::string value)
107 set_property(key, value);
109 /** @deprecated Storage::set_data() */
110 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); }
111 /** @deprecated Storage::get_data() */
112 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); }
115 Host* attached_to_ = nullptr;
116 surf::StorageImpl* const pimpl_ = nullptr;
118 void* userdata_ = nullptr;
121 } /* namespace s4u */
122 } /* namespace simgrid */
124 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */