Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3247dff7f3edc0e786767668395e3e7ad6ea4963
[simgrid.git] / include / simgrid / s4u / Storage.hpp
1 /* Copyright (c) 2006-2020. 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
21 extern template class XBT_PUBLIC xbt::Extendable<s4u::Storage>;
22
23 namespace s4u {
24
25 /** Storage represent the disk resources, usually associated to a given host
26  *
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.
29  */
30
31 class XBT_PUBLIC Storage : public xbt::Extendable<Storage> {
32   friend Engine;
33   friend Io;
34   friend kernel::resource::StorageImpl;
35
36 public:
37   explicit Storage(const std::string& name, kernel::resource::StorageImpl* pimpl);
38
39 protected:
40   virtual ~Storage() = default;
41 public:
42   /** @brief Callback signal fired when a new Storage is created */
43   static xbt::signal<void(Storage&)> on_creation;
44   /** @brief Callback signal fired when a Storage is destroyed */
45   static xbt::signal<void(Storage const&)> on_destruction;
46   /** @brief Callback signal fired when a Storage's state changes */
47   static xbt::signal<void(Storage const&)> on_state_change;
48
49   /** Retrieve a Storage by its name. It must exist in the platform file */
50   static Storage* by_name(const std::string& name);
51   static Storage* by_name_or_null(const std::string& name);
52
53   /** @brief Retrieves the name of that storage as a C++ string */
54   std::string const& get_name() const { return name_; }
55   /** @brief Retrieves the name of that storage as a C string */
56   const char* get_cname() const { return name_.c_str(); }
57
58   const char* get_type() const;
59   Host* get_host() const { return attached_to_; };
60   void set_host(Host* host) { attached_to_ = host; }
61
62   const std::unordered_map<std::string, std::string>* get_properties() const;
63   const char* get_property(const std::string& key) const;
64   void set_property(const std::string&, const std::string& value);
65
66   IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
67
68   IoPtr read_async(sg_size_t size);
69   sg_size_t read(sg_size_t size);
70
71   IoPtr write_async(sg_size_t size);
72   sg_size_t write(sg_size_t size);
73   kernel::resource::StorageImpl* get_impl() const { return pimpl_; }
74
75 private:
76   Host* attached_to_ = nullptr;
77   kernel::resource::StorageImpl* const pimpl_;
78   std::string name_;
79 };
80
81 } // namespace s4u
82 } // namespace simgrid
83
84 #endif /* INCLUDE_SIMGRID_S4U_STORAGE_HPP_ */