24 #ifndef LELY_IO2_TQUEUE_HPP_
25 #define LELY_IO2_TQUEUE_HPP_
48 compat::invoke(::std::move(self->func_), ec);
51 func_(::std::forward<F>(f)) {}
58 typename ::std::decay<F>::type func_;
70 inline typename ::std::enable_if<
85 using Signature = void(::std::error_code);
102 func_(::std::forward<F>(f)) {}
113 operator ev_task&() & noexcept {
return task; }
122 ::std::function<Signature> func_;
136 util::throw_errc(
"TimerQueue");
146 TimerQueue& operator=(
const TimerQueue&) =
delete;
149 operator=(TimerQueue&& other) noexcept {
151 swap(tq_, other.tq_);
152 swap(dev, other.dev);
159 operator io_tqueue_t*()
const noexcept {
return tq_; }
176 wait.value = util::to_timespec(t);
183 auto now = get_timer().get_clock().gettime();
184 wait.
value = util::to_timespec(now + d);
204 typename ::std::enable_if<!::std::is_base_of<
207 submit_wait(t,
nullptr, ::std::forward<F>(f));
212 typename ::std::enable_if<!::std::is_base_of<
215 submit_wait(d,
nullptr, ::std::forward<F>(f));
234 auto value = util::to_timespec(t);
236 if (!future) util::throw_errc(
"async_wait");
244 return async_wait(
nullptr, t, pwait);
251 auto now = get_timer().get_clock().gettime();
252 return async_wait(exec, now + d, pwait);
259 return async_wait(
nullptr, d, pwait);
An abstract task executor. This class is a wrapper around #ev_exec_t*.
An abstract I/O device. This class is a wrapper around #io_dev_t*.
A reference to an abstract timer.
A wait operation suitable for use with a timerqueue.
TimerQueueWait(ev_exec_t *exec, F &&f)
Constructs a wait operation with a completion task.
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
TimerQueueWait(F &&f)
Constructs a wait operation with a completion task.
A timer queue. This class is a wrapper around #io_tqueue_t*.
TimerQueue(io_timer_t *timer, ev_exec_t *exec=nullptr)
ev::Future< void, int > async_wait(ev_exec_t *exec, const TimerBase::time_point &t, struct io_tqueue_wait **pwait=nullptr)
typename ::std::enable_if<!::std::is_base_of< io_tqueue_wait, typename ::std::decay< F >::type >::value >::type submit_wait(const TimerBase::duration &d, F &&f)
void submit_wait(io_tqueue_wait &wait) noexcept
void submit_wait(const TimerBase::time_point &t, io_tqueue_wait &wait) noexcept
void submit_wait(const TimerBase::time_point &t, ev_exec_t *exec, F &&f)
void submit_wait(const TimerBase::duration &d, io_tqueue_wait &wait)
ev::Future< void, int > async_wait(const TimerBase::time_point &t, struct io_tqueue_wait **pwait=nullptr)
void submit_wait(const TimerBase::duration &d, ev_exec_t *exec, F &&f)
bool cancel_wait(struct io_tqueue_wait &wait) noexcept
ev::Future< void, int > async_wait(const TimerBase::duration &d, struct io_tqueue_wait **pwait=nullptr)
typename ::std::enable_if<!::std::is_base_of< io_tqueue_wait, typename ::std::decay< F >::type >::value >::type submit_wait(const TimerBase::time_point &t, F &&f)
TimerBase get_timer() const noexcept
ev::Future< void, int > async_wait(ev_exec_t *exec, const TimerBase::duration &d, struct io_tqueue_wait **pwait=nullptr)
bool abort_wait(struct io_tqueue_wait &wait) noexcept
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
const struct io_timer_vtbl *const io_timer_t
An abstract timer.
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
A wait operation suitable for use with a timer queue.
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the wait operation.
struct timespec value
The absolute expiration time.
Determines whether F can be invoked with the arguments Args....
This header file is part of the I/O library; it contains the C++ interface for the abstract timer.
This header file is part of the I/O library; it contains the timer queue declarations.
io_timer_t * io_tqueue_get_timer(const io_tqueue_t *tq)
Returns a pointer to the I/O timer used by the timer queue.
void io_tqueue_destroy(io_tqueue_t *tq)
Destroys a timer queue.
size_t io_tqueue_abort_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Aborts the specified timer queue wait operation if it is pending.
size_t io_tqueue_cancel_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Cancels the specified timer queue wait operation if it is pending.
ev_future_t * io_tqueue_async_wait(io_tqueue_t *tq, ev_exec_t *exec, const struct timespec *value, struct io_tqueue_wait **pwait)
Submits an asynchronous wait operation to a timer queue and creates a future which becomes ready once...
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.
void io_tqueue_submit_wait(io_tqueue_t *tq, struct io_tqueue_wait *wait)
Submits a wait operation to a timer queue.
#define IO_TQUEUE_WAIT_INIT(sec, nsec, exec, func)
The static initializer for io_tqueue_wait.
io_tqueue_t * io_tqueue_create(io_timer_t *timer, ev_exec_t *exec)
Creates a new timer queue.
io_dev_t * io_tqueue_get_dev(const io_tqueue_t *tq)
Returns a pointer to the abstract I/O device representing the timer queue.
typename ::std::enable_if< compat::is_invocable< F, ::std::error_code >::value, detail::TimerQueueWaitWrapper< F > * >::type make_timer_queue_wait_wrapper(ev_exec_t *exec, F &&f)
Creates a wait operation with a completion task.