1 /* Copyright (c) 2019. 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_DISK_HPP_
7 #define INCLUDE_SIMGRID_S4U_DISK_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>
22 /** Disk represent the disk resources associated to a host
24 * By default, SimGrid does not keep track of the actual data being written but
25 * only computes the time taken by the corresponding data movement.
28 class XBT_PUBLIC Disk : public xbt::Extendable<Disk> {
31 friend kernel::resource::DiskImpl;
34 explicit Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name) {}
37 virtual ~Disk() = default;
40 /** @brief Callback signal fired when a new Storage is created */
41 static xbt::signal<void(Disk&)> on_creation;
42 /** @brief Callback signal fired when a Storage is destroyed */
43 static xbt::signal<void(Disk const&)> on_destruction;
44 /** @brief Callback signal fired when a Storage's state changes */
45 static xbt::signal<void(Disk const&)> on_state_change;
47 /** @brief Retrieves the name of that storage as a C++ string */
48 std::string const& get_name() const { return name_; }
49 /** @brief Retrieves the name of that storage as a C string */
50 const char* get_cname() const { return name_.c_str(); }
52 const std::unordered_map<std::string, std::string>* get_properties() const;
53 const char* get_property(const std::string& key) const;
54 void set_property(const std::string&, const std::string& value);
57 void set_data(void* data) { userdata_ = data; }
58 void* get_data() { return userdata_; }
60 IoPtr io_init(sg_size_t size, s4u::Io::OpType type);
62 IoPtr read_async(sg_size_t size);
63 sg_size_t read(sg_size_t size);
65 IoPtr write_async(sg_size_t size);
66 sg_size_t write(sg_size_t size);
67 kernel::resource::DiskImpl* get_impl() const { return pimpl_; }
70 kernel::resource::DiskImpl* const pimpl_;
72 void* userdata_ = nullptr;
76 } // namespace simgrid
78 #endif /* INCLUDE_SIMGRID_S4U_DISK_HPP_ */