Lely core libraries  2.2.5
co_tqueue.hpp
Go to the documentation of this file.
1 
25 #ifndef LELY_IO2_CO_TQUEUE_HPP_
26 #define LELY_IO2_CO_TQUEUE_HPP_
27 
28 #include <lely/io2/tqueue.hpp>
29 #include <lely/util/coroutine.hpp>
30 
31 namespace lely {
32 namespace io {
33 
39  public:
41  explicit CoTimerQueueWait(ev_exec_t* exec) noexcept
43  IO_TQUEUE_WAIT_INIT(0, 0, exec, [](ev_task * task) noexcept {
44  auto wait = io_tqueue_wait_from_task(task);
45  ::std::error_code ec = util::make_error_code(wait->errc);
46  auto self = static_cast<CoTimerQueueWait*>(wait);
47  (*self)(ec);
48  }) {}
49 
51  CoTimerQueueWait() noexcept : CoTimerQueueWait(nullptr) {}
52 
53  virtual ~CoTimerQueueWait() = default;
54 
55  operator ev_task&() & noexcept { return task; }
56 
59  get_executor() const noexcept {
60  return ev::Executor(task.exec);
61  }
62 
70  virtual void operator()(::std::error_code ec) noexcept = 0;
71 };
72 
73 } // namespace io
74 } // namespace lely
75 
76 #endif // !LELY_IO2_CO_TQUEUE_HPP_
lely::io::CoTimerQueueWait::CoTimerQueueWait
CoTimerQueueWait() noexcept
Constructs a wait operation.
Definition: co_tqueue.hpp:51
ev_exec_t
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
lely::io::CoTimerQueueWait::operator()
virtual void operator()(::std::error_code ec) noexcept=0
The coroutine to be executed once the wait operation completes (or is canceled).
lely::io::CoTimerQueueWait::CoTimerQueueWait
CoTimerQueueWait(ev_exec_t *exec) noexcept
Constructs a wait operation.
Definition: co_tqueue.hpp:41
lely::io::CoTimerQueueWait
A wait operation, suitable for use with a timer queue, with a stackless coroutine as the completion t...
Definition: co_tqueue.hpp:38
IO_TQUEUE_WAIT_INIT
#define IO_TQUEUE_WAIT_INIT(sec, nsec, exec, func)
The static initializer for io_tqueue_wait.
Definition: tqueue.h:53
tqueue.hpp
io_tqueue_wait_from_task
struct io_tqueue_wait * io_tqueue_wait_from_task(struct ev_task *task)
Obtains a pointer to a timer queue wait operation from a pointer to its completion task.
Definition: tqueue.c:351
coroutine.hpp
io_tqueue_wait
A wait operation suitable for use with a timer queue.
Definition: tqueue.h:36
lely::io::CoTimerQueueWait::get_executor
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
Definition: co_tqueue.hpp:59
lely::ev::Executor
An abstract task executor. This class is a wrapper around #ev_exec_t*.
Definition: exec.hpp:38
lely::util::Coroutine
The parent class for function objects used as stackless coroutines.
Definition: coroutine.hpp:48
io_tqueue_wait::task
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition: tqueue.h:43
ev_task
An executable task.
Definition: task.h:41
lely::canopen::make_error_code
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
ev_task::exec
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43