24 #ifndef LELY_IO2_CAN_RT_HPP_ 25 #define LELY_IO2_CAN_RT_HPP_ 42 id, static_cast<uint_least8_t>(flags),
45 auto msg = read->r.msg;
49 compat::invoke(::std::move(self->func_), msg, ec);
52 func_(::std::forward<F>(f)) {}
62 typename ::std::decay<F>::type func_;
73 inline typename ::std::enable_if<
78 ::std::forward<F>(f));
89 using Signature = void(
const can_msg*, ::std::error_code);
95 id, static_cast<uint_least8_t>(flags),
100 auto msg = read->
r.
msg;
101 ::std::error_code ec;
103 self->func_(msg, ec);
106 func_(::std::forward<F>(f)) {}
121 ::std::function<Signature> func_;
132 auto err = read->r.err;
133 ::std::error_code ec;
136 compat::invoke(::std::move(self->func_), err, ec);
139 func_(::std::forward<F>(f)) {}
149 typename ::std::decay<F>::type func_;
160 inline typename ::std::enable_if<
175 using Signature = void(
const can_err*, ::std::error_code);
184 auto err = read->
r.
err;
185 ::std::error_code ec;
187 self->func_(err, ec);
190 func_(::std::forward<F>(f)) {}
205 ::std::function<Signature> func_;
219 util::throw_errc(
"CanRouter");
234 swap(rt_, other.rt_);
235 swap(dev, other.dev);
242 operator io_can_rt_t*()
const noexcept {
return rt_; }
281 *
this,
id, static_cast<uint_least8_t>(flags), pread_msg);
282 if (!future) util::throw_errc(
"async_read_frame");
294 typename ::std::enable_if<!::std::is_base_of<
317 if (!future) util::throw_errc(
"async_read_error");
325 if (!future) util::throw_errc(
"async_shutdown");
336 #endif // !LELY_IO2_CAN_RT_HPP_ A CAN or CAN FD format frame.
A CAN frame read operation suitable for use with a CAN frame router.
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
CanFlag
The error flags of a CAN bus, which are not mutually exclusive.
void io_can_rt_destroy(io_can_rt_t *rt)
Destroys a CAN frame router.
CanRouterReadFrame(uint_least32_t id, CanFlag flags, F &&f)
Constructs a CAN frame read operation with a completion task.
Determines whether F can be invoked with the arguments Args....
CanRouter(io_can_chan_t *chan, ev_exec_t *exec)
ev::Future< void, void > async_shutdown()
void submit_read_frame(struct io_can_rt_read_msg &read_msg) noexcept
void submit_read_error(struct io_can_rt_read_err &read_err) noexcept
size_t io_can_rt_abort_read_err(io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
Aborts the specified CAN error frame read operation if it is pending.
typename ::std::enable_if< compat::is_invocable< F, const can_err *, ::std::error_code >::value, detail::CanRouterReadErrorWrapper< F > * >::type make_can_router_read_error_wrapper(F &&f)
Creates a CAN error frame read operation with a completion task.
CanRouterReadError(F &&f)
Constructs a CAN error frame read operation with a completion task.
struct io_can_rt_read_msg_result r
The result of the read operation.
typename ::std::enable_if< compat::is_invocable< F, const can_msg *, ::std::error_code >::value, detail::CanRouterReadFrameWrapper< F > * >::type make_can_router_read_frame_wrapper(uint_least32_t id, CanFlag flags, F &&f)
Creates a CAN frame read operation with a completion task.
io_dev_t * io_can_rt_get_dev(const io_can_rt_t *rt)
Returns a pointer to the abstract I/O device representing the CAN frame router.
io_can_rt_t * io_can_rt_create(io_can_chan_t *chan, ev_exec_t *exec)
Creates a new CAN frame router.
const struct io_can_chan_vtbl *const io_can_chan_t
An abstract CAN channel.
ev_future_t * io_can_rt_async_read_msg(io_can_rt_t *rt, uint_least32_t id, uint_least8_t flags, struct io_can_rt_read_msg **pread_msg)
Submits an asynchronous CAN frame read operation to a CAN frame router and creates a future which bec...
#define IO_CAN_RT_READ_ERR_INIT(func)
The static initializer for io_can_rt_read_err.
void io_can_rt_submit_read_err(io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
Submits a CAN error frame read operation to a CAN frame router.
typename ::std::enable_if<!::std::is_base_of< io_can_rt_read_err, typename ::std::decay< F >::type >::value >::type submit_read_error(F &&f)
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
io_can_chan_t * io_can_rt_get_chan(const io_can_rt_t *rt)
Returns a pointer to the CAN channel used by the CAN frame router.
const struct can_err * err
A pointer to the received CAN error frame, or NULL on error (or if the operation is canceled)...
uint_least32_t id
The identifier of the CAN frame to be received.
struct io_can_rt_read_err * io_can_rt_read_err_from_task(struct ev_task *task)
Obtains a pointer to a CAN error frame read operation from a pointer to its completion task...
This header file is part of the I/O library; it contains the CAN frame router declarations.
size_t io_can_rt_abort_read_msg(io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
Aborts the specified CAN frame read operation if it is pending.
size_t io_can_rt_cancel_read_msg(io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
Cancels the specified CAN frame read operation if it is pending.
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
ev_future_t * io_can_rt_async_read_err(io_can_rt_t *rt, struct io_can_rt_read_err **pread_err)
Submits an asynchronous CAN error frame read operation to a CAN frame router and creates a future whi...
size_t io_can_rt_cancel_read_err(io_can_rt_t *rt, struct io_can_rt_read_err *read_err)
Cancels the specified CAN error frame read operation if it is pending.
struct io_can_rt_read_msg * io_can_rt_read_msg_from_task(struct ev_task *task)
Obtains a pointer to a CAN frame read operation from a pointer to its completion task.
void submit_read_frame(uint_least32_t id, CanFlag flags, F &&f)
const struct can_msg * msg
A pointer to the received CAN frame, or NULL on error (or if the operation is canceled).
A CAN frame rounter. This class is a wrapper around io_can_rt_t*.
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
bool abort_read_error(struct io_can_rt_read_err &read_err) noexcept
struct io_can_rt_read_err_result r
The result of the read operation.
An abstract task executor. This class is a wrapper around ev_exec_t*.
bool cancel_read_frame(struct io_can_rt_read_msg &read_msg) noexcept
bool abort_read_frame(struct io_can_rt_read_msg &read_msg) noexcept
ev::Future< const can_msg *, int > async_read_frame(uint_least32_t id, CanFlag flags, struct io_can_rt_read_msg **pread_msg=nullptr)
A CAN frame read operation suitable for use with a CAN frame router.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
A CAN error frame read operation suitable for use with a CAN frame router.
A CAN error frame read operation suitable for use with a CAN frame router.
bool cancel_read_error(struct io_can_rt_read_err &read_err) noexcept
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
void io_can_rt_submit_read_msg(io_can_rt_t *rt, struct io_can_rt_read_msg *read_msg)
Submits a CAN frame read operation to a CAN frame router.
CanChannelBase get_channel() const noexcept
This header file is part of the I/O library; it contains the C++ interface for the abstract CAN bus...
uint_least8_t flags
The flags of the CAN frame to be received (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR, CAN_FLAG_FDF, CAN_FLAG_BRS and CAN_FLAG_ESI).
const struct io_dev_vtbl *const io_dev_t
An abstract I/O device.
#define IO_CAN_RT_READ_MSG_INIT(id, flags, func)
The static initializer for io_can_rt_read_msg.
ev::Future< const can_err *, int > async_read_error(struct io_can_rt_read_err **pread_err=nullptr)
ev_future_t * io_can_rt_async_shutdown(io_can_rt_t *rt)
Shuts down a CAN frame router, cancels all pending operations and creates a (void) future which becom...
An abstract I/O device. This class is a wrapper around io_dev_t*.
A reference to an abstract CAN channel.