Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/mwapl/simgrid
[simgrid.git] / include / simgrid / s4u / Io.hpp
1 /* Copyright (c) 2017-2023. 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::s4u {
15
16 /** I/O Activity, representing the asynchronous disk access.
17  *
18  * They are generated from Disk::io_init(), Disk::read() Disk::read_async(), Disk::write() and Disk::write_async().
19  */
20
21 class XBT_PUBLIC Io : public Activity_T<Io> {
22 #ifndef DOXYGEN
23   friend kernel::activity::IoImpl;
24   friend kernel::EngineImpl;
25 #endif
26
27   inline static xbt::signal<void(Io const&)> on_start;
28   xbt::signal<void(Io const&)> on_this_start;
29
30 protected:
31   explicit Io(kernel::activity::IoImplPtr pimpl);
32   Io* do_start() override;
33   void fire_on_completion() const override { on_completion(*this); }
34   void fire_on_this_completion() const override { on_this_completion(*this); }
35   void fire_on_suspend() const override { on_suspend(*this); }
36   void fire_on_this_suspend() const override { on_this_suspend(*this); }
37   void fire_on_resume() const override { on_resume(*this); }
38   void fire_on_this_resume() const override { on_this_resume(*this); }
39   void fire_on_veto() const override { on_veto(const_cast<Io&>(*this)); }
40   void fire_on_this_veto() const override { on_this_veto(const_cast<Io&>(*this)); }
41
42 public:
43   enum class OpType { READ, WRITE };
44
45    /*! \static Signal fired each time that any I/O actually starts (no veto) */
46   static void on_start_cb(const std::function<void(Io const&)>& cb) { on_start.connect(cb); }
47    /*! Signal fired each time this specific I/O actually starts (no veto) */
48   void on_this_start_cb(const std::function<void(Io const&)>& cb) { on_this_start.connect(cb); }
49
50    /*! \static Initiate the creation of an I/O. Setters have to be called afterwards */
51   static IoPtr init();
52   /*! \static take a vector of s4u::IoPtr and return when one of them is finished.
53    * The return value is the rank of the first finished IoPtr. */
54   static ssize_t wait_any(const std::vector<IoPtr>& ios) { return wait_any_for(ios, -1); }
55   /*! \static Same as wait_any, but with a timeout. If the timeout occurs, parameter last is returned.*/
56   static ssize_t wait_any_for(const std::vector<IoPtr>& ios, double timeout);
57
58   double get_remaining() const override;
59   sg_size_t get_performed_ioops() const;
60   IoPtr set_disk(const_sg_disk_t disk);
61   IoPtr set_priority(double priority);
62   IoPtr set_size(sg_size_t size);
63   IoPtr set_op_type(OpType type);
64
65   static IoPtr streamto_init(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk);
66   static IoPtr streamto_async(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk,
67                               uint64_t simulated_size_in_bytes);
68   static void streamto(Host* from, const Disk* from_disk, Host* to, const Disk* to_disk,
69                        uint64_t simulated_size_in_bytes);
70
71   IoPtr set_source(Host* from, const Disk* from_disk);
72   IoPtr set_destination(Host* to, const Disk* to_disk);
73
74   IoPtr update_priority(double priority);
75
76   bool is_assigned() const override;
77 };
78
79 } // namespace simgrid::s4u
80
81 #endif /* SIMGRID_S4U_IO_HPP */