Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factor Activity::cancel() through CRTP.
[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   friend kernel::activity::IoImpl;
24
25 protected:
26   explicit Io(kernel::activity::IoImplPtr pimpl);
27
28   void complete(Activity::State state) override;
29
30 public:
31   enum class OpType { READ, WRITE };
32
33   static xbt::signal<void(Io const&)> on_start;
34   static xbt::signal<void(Io const&)> on_completion;
35
36   static IoPtr init();
37   Io* start() override;
38   Io* wait() override;
39   Io* wait_for(double timeout) override;
40
41   double get_remaining() const override;
42   sg_size_t get_performed_ioops() const;
43   IoPtr set_disk(const_sg_disk_t disk);
44   IoPtr set_size(sg_size_t size);
45   IoPtr set_op_type(OpType type);
46
47   bool is_assigned() const override;
48 };
49
50 } // namespace s4u
51 } // namespace simgrid
52
53 #endif /* SIMGRID_S4U_IO_HPP */