Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
do not store name in s4u::Disk
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019-2021. 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 #include "simgrid/s4u/Disk.hpp"
7 #include "simgrid/s4u/Engine.hpp"
8 #include "simgrid/s4u/Host.hpp"
9 #include "simgrid/s4u/Io.hpp"
10 #include "simgrid/simix.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12
13 namespace simgrid {
14
15 template class xbt::Extendable<s4u::Disk>;
16
17 namespace s4u {
18
19 xbt::signal<void(Disk&)> Disk::on_creation;
20 xbt::signal<void(Disk const&)> Disk::on_destruction;
21 xbt::signal<void(Disk const&)> Disk::on_state_change;
22
23 const std::string& Disk::get_name() const
24 {
25   return pimpl_->get_name();
26 }
27
28 const char* Disk::get_cname() const
29 {
30   return pimpl_->get_cname();
31 }
32
33 Disk* Disk::set_read_bandwidth(double read_bw)
34 {
35   kernel::actor::simcall([this, read_bw] { pimpl_->set_read_bandwidth(read_bw); });
36   return this;
37 }
38
39 Disk* Disk::set_write_bandwidth(double write_bw)
40 {
41   kernel::actor::simcall([this, write_bw] { pimpl_->set_write_bandwidth(write_bw); });
42   return this;
43 }
44
45 double Disk::get_read_bandwidth() const
46 {
47   return pimpl_->get_read_bandwidth();
48 }
49
50 double Disk::get_write_bandwidth() const
51 {
52   return pimpl_->get_write_bandwidth();
53 }
54
55 Disk* Disk::set_host(Host* host)
56 {
57   pimpl_->set_host(host);
58   return this;
59 }
60
61 Host* Disk::get_host() const
62 {
63   return pimpl_->get_host();
64 }
65
66 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
67 {
68   return pimpl_->get_properties();
69 }
70
71 const char* Disk::get_property(const std::string& key) const
72 {
73   return pimpl_->get_property(key);
74 }
75
76 Disk* Disk::set_property(const std::string& key, const std::string& value)
77 {
78   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
79   return this;
80 }
81
82 Disk* Disk::set_properties(const std::unordered_map<std::string, std::string>& properties)
83 {
84   kernel::actor::simcall([this, properties] { this->pimpl_->set_properties(properties); });
85   return this;
86 }
87
88 IoPtr Disk::io_init(sg_size_t size, Io::OpType type) const
89 {
90   return Io::init()->set_disk(this)->set_size(size)->set_op_type(type);
91 }
92
93 IoPtr Disk::read_async(sg_size_t size) const
94 {
95   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start();
96 }
97
98 sg_size_t Disk::read(sg_size_t size) const
99 {
100   return IoPtr(io_init(size, Io::OpType::READ))->vetoable_start()->wait()->get_performed_ioops();
101 }
102
103 IoPtr Disk::write_async(sg_size_t size) const
104 {
105   return IoPtr(io_init(size, Io::OpType::WRITE)->vetoable_start());
106 }
107
108 sg_size_t Disk::write(sg_size_t size) const
109 {
110   return IoPtr(io_init(size, Io::OpType::WRITE))->vetoable_start()->wait()->get_performed_ioops();
111 }
112
113 Disk* Disk::seal()
114 {
115   kernel::actor::simcall([this]{ pimpl_->seal(); });
116   Disk::on_creation(*this);
117   return this;
118 }
119 } // namespace s4u
120 } // namespace simgrid
121
122 /* **************************** Public C interface *************************** */
123
124 const char* sg_disk_get_name(const_sg_disk_t disk)
125 {
126   return disk->get_cname();
127 }
128
129 sg_host_t sg_disk_get_host(const_sg_disk_t disk)
130 {
131   return disk->get_host();
132 }
133
134 double sg_disk_read_bandwidth(const_sg_disk_t disk)
135 {
136   return disk->get_read_bandwidth();
137 }
138
139 double sg_disk_write_bandwidth(const_sg_disk_t disk)
140 {
141   return disk->get_write_bandwidth();
142 }
143
144 sg_size_t sg_disk_read(const_sg_disk_t disk, sg_size_t size)
145 {
146   return disk->read(size);
147 }
148 sg_size_t sg_disk_write(const_sg_disk_t disk, sg_size_t size)
149 {
150   return disk->write(size);
151 }
152
153 void* sg_disk_get_data(const_sg_disk_t disk)
154 {
155   return disk->get_data();
156 }
157
158 void sg_disk_set_data(sg_disk_t disk, void* data)
159 {
160   disk->set_data(data);
161 }