Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
832631d656e1454f172b56f1cd94d808f2b7dd41
[simgrid.git] / include / simgrid / s4u / Io.hpp
1 /* Copyright (c) 2017-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 #ifndef SIMGRID_S4U_IO_HPP
7 #define SIMGRID_S4U_IO_HPP
8
9 #include <simgrid/forward.h>
10 #include <simgrid/s4u/Activity.hpp>
11
12 #include <string>
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** I/O Activity, representing the asynchronous disk access.
18  *
19  * They are generated from Disk::io_init(), Disk::read() Disk::read_async(), Disk::write() and Disk::write_async().
20  */
21
22 class XBT_PUBLIC Io : public Activity_T<Io> {
23 public:
24   enum class OpType { READ, WRITE };
25
26 private:
27   Disk* disk_       = nullptr;
28   sg_size_t size_   = 0;
29   OpType type_      = OpType::READ;
30
31   Io();
32
33 public:
34 #ifndef DOXYGEN
35   friend Disk;    // Factory of IOs
36
37   ~Io() override = default;
38 #endif
39
40   static xbt::signal<void(Io const&)> on_start;
41   static xbt::signal<void(Io const&)> on_completion;
42
43   static IoPtr init();
44   Io* start() override;
45   Io* wait() override;
46   Io* wait_for(double timeout) override;
47   Io* cancel() override;
48
49   double get_remaining() const override;
50   sg_size_t get_performed_ioops() const;
51   IoPtr set_disk(sg_disk_t disk);
52   IoPtr set_size(sg_size_t size);
53   IoPtr set_op_type(OpType type);
54
55   bool is_assigned() const override { return disk_ != nullptr; }
56 };
57
58 } // namespace s4u
59 } // namespace simgrid
60
61 #endif /* SIMGRID_S4U_IO_HPP */