Lely core libraries 2.3.4
co_timer.hpp
Go to the documentation of this file.
1
24#ifndef LELY_IO2_CO_TIMER_HPP_
25#define LELY_IO2_CO_TIMER_HPP_
26
27#include <lely/io2/timer.hpp>
29
30namespace lely {
31namespace io {
32
38 public:
40 explicit CoTimerWait(ev_exec_t* exec) noexcept
41 : io_timer_wait IO_TIMER_WAIT_INIT(exec, [](ev_task* task) noexcept {
42 auto wait = io_timer_wait_from_task(task);
43 auto overrun = wait->r.result;
44 ::std::error_code ec;
45 if (overrun == -1) ec = util::make_error_code(wait->r.errc);
46 auto self = static_cast<CoTimerWait*>(wait);
47 (*self)(overrun, ec);
48 }) {}
49
51 CoTimerWait() noexcept : CoTimerWait(nullptr) {}
52
53 virtual ~CoTimerWait() = default;
54
55 operator ev_task&() & noexcept { return task; }
56
59 get_executor() const noexcept {
60 return ev::Executor(task.exec);
61 }
62
71 virtual void operator()(int overrun, ::std::error_code ec) noexcept = 0;
72};
73
74} // namespace io
75} // namespace lely
76
77#endif // !LELY_IO2_CO_TIMER_HPP_
An abstract task executor. This class is a wrapper around #ev_exec_t*.
Definition: exec.hpp:38
A wait operation, suitable for use with an I/O timer, with a stackless coroutine as the completion ta...
Definition: co_timer.hpp:37
CoTimerWait() noexcept
Constructs a wait operation.
Definition: co_timer.hpp:51
CoTimerWait(ev_exec_t *exec) noexcept
Constructs a wait operation.
Definition: co_timer.hpp:40
virtual void operator()(int overrun, ::std::error_code ec) noexcept=0
The coroutine to be executed once the wait operation completes (or is canceled).
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
Definition: co_timer.hpp:59
The parent class for function objects used as stackless coroutines.
Definition: coroutine.hpp:48
This header file is part of the utilities library; it contains the C++ implementation of stackless co...
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
struct io_timer_wait * io_timer_wait_from_task(struct ev_task *task)
Obtains a pointer to an I/O timer wait operation from a pointer to its completion task.
Definition: timer.c:62
#define IO_TIMER_WAIT_INIT(exec, func)
The static initializer for io_timer_wait.
Definition: timer.h:65
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
An executable task.
Definition: task.h:41
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43
A wait operation suitable for use with an I/O timer.
Definition: timer.h:54
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
Definition: timer.h:59
This header file is part of the I/O library; it contains the C++ interface for the abstract timer.