Lely core libraries  2.2.5
dev.hpp
Go to the documentation of this file.
1 
24 #ifndef LELY_IO2_DEV_HPP_
25 #define LELY_IO2_DEV_HPP_
26 
27 #include <lely/ev/exec.hpp>
28 #include <lely/io2/ctx.hpp>
29 #include <lely/io2/dev.h>
30 
31 namespace lely {
32 namespace io {
33 
35 class Device {
36  public:
37  explicit Device(io_dev_t* dev_) noexcept : dev(dev_) {}
38 
39  operator io_dev_t*() const noexcept { return dev; }
40 
43  get_ctx() const noexcept {
44  return ContextBase(io_dev_get_ctx(*this));
45  }
46 
49  get_executor() const noexcept {
50  return ev::Executor(io_dev_get_exec(*this));
51  }
52 
54  bool
55  cancel(ev_task& task) noexcept {
56  return io_dev_cancel(*this, &task) != 0;
57  }
58 
60  ::std::size_t
61  cancel_all() noexcept {
62  return io_dev_cancel(*this, nullptr);
63  }
64 
66  bool
67  abort(ev_task& task) noexcept {
68  return io_dev_abort(*this, &task) != 0;
69  }
70 
72  ::std::size_t
73  abort_all() noexcept {
74  return io_dev_abort(*this, nullptr);
75  }
76 
77  protected:
78  io_dev_t* dev{nullptr};
79 };
80 
81 } // namespace io
82 } // namespace lely
83 
84 #endif // !LELY_IO2_DEV_HPP_
A refence to an I/O context. This class is a wrapper around io_ctx_t*.
Definition: ctx.hpp:49
ContextBase get_ctx() const noexcept
Definition: dev.hpp:43
ev_exec_t * io_dev_get_exec(const io_dev_t *dev)
Returns a pointer to the executor used by the I/O device to execute asynchronous tasks.
Definition: dev.h:86
::std::size_t abort_all() noexcept
Definition: dev.hpp:73
This header file is part of the I/O library; it contains the C++ interface for the I/O context...
size_t io_dev_cancel(io_dev_t *dev, struct ev_task *task)
Cancels the asynchronous operation submitted to *dev, if its task has not yet been submitted to its e...
Definition: dev.h:92
size_t io_dev_abort(io_dev_t *dev, struct ev_task *task)
Aborts the asynchronous operation submitted to *dev, if its task has not yet been submitted to its ex...
Definition: dev.h:98
io_ctx_t * io_dev_get_ctx(const io_dev_t *dev)
Returns a pointer to the I/O context with which the I/O device is registered.
Definition: dev.h:80
This header file is part of the event library; it contains the C++ interface for the abstract task ex...
ev::Executor get_executor() const noexcept
Definition: dev.hpp:49
An executable task.
Definition: task.h:41
An abstract task executor. This class is a wrapper around ev_exec_t*.
Definition: exec.hpp:38
::std::size_t cancel_all() noexcept
Definition: dev.hpp:61
Definition: buf.hpp:32
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
Definition: dev.h:35
This header file is part of the I/O library; it contains the abstract I/O device interface.
bool abort(ev_task &task) noexcept
Definition: dev.hpp:67
bool cancel(ev_task &task) noexcept
Definition: dev.hpp:55
An abstract I/O device. This class is a wrapper around io_dev_t*.
Definition: dev.hpp:35