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 <xbt/Extendable.hpp>
18 extern template class XBT_PUBLIC Extendable<simgrid::s4u::Storage>;
22 XBT_ATTRIB_DEPRECATED_v322(
23 "simgrid::s4u::getStorageList() is deprecated in favor of Engine::get_all_storages(). Please switch before v3.22")
24 XBT_PUBLIC void getStorageList(std::map<std::string, Storage*>* whereTo);
26 class XBT_PUBLIC Storage : public simgrid::xbt::Extendable<Storage> {
28 friend simgrid::surf::StorageImpl;
31 explicit Storage(std::string name, surf::StorageImpl * pimpl);
34 virtual ~Storage() = default;
37 /** @brief Callback signal fired when a new Storage is created */
38 static simgrid::xbt::signal<void(s4u::Storage&)> on_creation;
39 /** @brief Callback signal fired when a Storage is destroyed */
40 static simgrid::xbt::signal<void(s4u::Storage&)> on_destruction;
41 /** @brief Callback signal fired when a Storage's state changes */
42 static simgrid::xbt::signal<void(s4u::Storage&)> on_state_change;
44 /** Retrieve a Storage by its name. It must exist in the platform file */
45 static Storage* by_name(std::string name);
46 static Storage* by_name_or_null(std::string name);
48 /** @brief Retrieves the name of that storage as a C++ string */
49 std::string const& get_name() const { return name_; }
50 /** @brief Retrieves the name of that storage as a C string */
51 const char* get_cname() const { return name_.c_str(); }
53 const char* get_type();
54 Host* get_host() { return attached_to_; };
55 void set_host(Host* host) { attached_to_ = host; }
57 std::map<std::string, std::string>* get_properties();
58 const char* get_property(std::string key);
59 void set_property(std::string, std::string value);
61 void set_data(void* data) { userdata_ = data; }
62 void* get_data() { return userdata_; }
64 sg_size_t read(sg_size_t size);
65 sg_size_t write(sg_size_t size);
66 surf::StorageImpl* get_impl() { return pimpl_; }
68 // Deprecated functions
69 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name)
73 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_name()") std::string const& getName() const { return get_name(); }
74 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_cname()") const char* getCname() const { return get_cname(); }
75 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_type()") const char* getType() { return get_type(); }
76 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_host()") Host* getHost() { return get_host(); }
77 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_properties()") std::map<std::string, std::string>* getProperties()
79 return get_properties();
81 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_property()") const char* getProperty(const char* key)
83 return get_property(key);
85 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_property()") void setProperty(std::string key, std::string value)
87 set_property(key, value);
89 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); }
90 XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); }
93 Host* attached_to_ = nullptr;
94 surf::StorageImpl* const pimpl_ = nullptr;
96 void* userdata_ = nullptr;
100 } /* namespace simgrid */
102 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */