1 /* Copyright (c) 2006-2020. 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>
21 extern template class XBT_PUBLIC xbt::Extendable<s4u::Storage>;
25 /** Storage represent the disk resources, usually associated to a given host
27 * By default, SimGrid does not keep track of the actual data being written but
28 * only computes the time taken by the corresponding data movement.
31 class XBT_PUBLIC Storage : public xbt::Extendable<Storage> {
34 friend kernel::resource::StorageImpl;
37 explicit Storage(const std::string& name, kernel::resource::StorageImpl* pimpl);
40 virtual ~Storage() = default;
43 /** @brief Callback signal fired when a new Storage is created */
44 static xbt::signal<void(Storage&)> on_creation;
45 /** @brief Callback signal fired when a Storage is destroyed */
46 static xbt::signal<void(Storage const&)> on_destruction;
47 /** @brief Callback signal fired when a Storage's state changes */
48 static xbt::signal<void(Storage const&)> on_state_change;
50 /** Retrieve a Storage by its name. It must exist in the platform file */
51 static Storage* by_name(const std::string& name);
52 static Storage* by_name_or_null(const std::string& name);
54 /** @brief Retrieves the name of that storage as a C++ string */
55 std::string const& get_name() const { return name_; }
56 /** @brief Retrieves the name of that storage as a C string */
57 const char* get_cname() const { return name_.c_str(); }
59 const char* get_type() const;
60 Host* get_host() const { return attached_to_; };
61 void set_host(Host* host) { attached_to_ = host; }
63 const std::unordered_map<std::string, std::string>* get_properties() const;
64 const char* get_property(const std::string& key) const;
65 void set_property(const std::string&, const std::string& value);
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 kernel::resource::StorageImpl* get_impl() const { return pimpl_; }
77 Host* attached_to_ = nullptr;
78 kernel::resource::StorageImpl* const pimpl_;
83 } // namespace simgrid
85 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */