Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b543f9499e85c5499996ada721e2fd125a90e5d2
[simgrid.git] / src / s4u / s4u_Disk.cpp
1 /* Copyright (c) 2019. 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 "src/kernel/resource/DiskImpl.hpp"
11
12 namespace simgrid {
13 namespace xbt {
14 template class Extendable<s4u::Disk>;
15 } // namespace xbt
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 Disk::Disk(const std::string& name, kernel::resource::DiskImpl* pimpl) : pimpl_(pimpl), name_(name)
24 {
25   Engine::get_instance()->disk_register(name_, this);
26 }
27
28 Disk* Disk::by_name(const std::string& name)
29 {
30   return Engine::get_instance()->disk_by_name(name);
31 }
32
33 Disk* Disk::by_name_or_null(const std::string& name)
34 {
35   return Engine::get_instance()->disk_by_name_or_null(name);
36 }
37
38 const std::unordered_map<std::string, std::string>* Disk::get_properties() const
39 {
40   return pimpl_->get_properties();
41 }
42
43 const char* Disk::get_property(const std::string& key) const
44 {
45   return this->pimpl_->get_property(key);
46 }
47
48 void Disk::set_property(const std::string& key, const std::string& value)
49 {
50   kernel::actor::simcall([this, &key, &value] { this->pimpl_->set_property(key, value); });
51 }
52
53 IoPtr Disk::io_init(sg_size_t size, Io::OpType type)
54 {
55   return IoPtr(new Io(this, size, type));
56 }
57
58 IoPtr Disk::read_async(sg_size_t size)
59 {
60   return IoPtr(io_init(size, Io::OpType::READ))->start();
61 }
62
63 sg_size_t Disk::read(sg_size_t size)
64 {
65   return IoPtr(io_init(size, Io::OpType::READ))->start()->wait()->get_performed_ioops();
66 }
67
68 IoPtr Disk::write_async(sg_size_t size)
69 {
70
71   return IoPtr(io_init(size, Io::OpType::WRITE)->start());
72 }
73
74 sg_size_t Disk::write(sg_size_t size)
75 {
76   return IoPtr(io_init(size, Io::OpType::WRITE))->start()->wait()->get_performed_ioops();
77 }
78
79 } // namespace s4u
80 } // namespace simgrid