Lely core libraries 2.3.4
co_can_rt.hpp
Go to the documentation of this file.
1
25#ifndef LELY_IO2_CO_CAN_RT_HPP_
26#define LELY_IO2_CO_CAN_RT_HPP_
27
28#include <lely/io2/can_rt.hpp>
30
31namespace lely {
32namespace io {
33
39 public:
42 CanFlag flags = CanFlag::NONE) noexcept
44 id, static_cast<uint_least8_t>(flags), [](ev_task* task) noexcept {
45 auto read_msg = io_can_rt_read_msg_from_task(task);
46 auto msg = read_msg->r.msg;
47 ::std::error_code ec;
48 if (!msg) ec = util::make_error_code(read_msg->r.errc);
49 auto self = static_cast<CoCanRouterReadFrame*>(read_msg);
50 (*self)(msg, ec);
51 }) {}
52
53 virtual ~CoCanRouterReadFrame() = default;
54
55 operator ev_task&() & noexcept { return task; }
56
58 ev::Executor
62
72 virtual void operator()(const can_msg* msg,
73 ::std::error_code ec) noexcept = 0;
74};
75
81 public:
85 auto read_err = io_can_rt_read_err_from_task(task);
86 auto err = read_err->r.err;
87 ::std::error_code ec;
88 if (!err) ec = util::make_error_code(read_err->r.errc);
89 auto self = static_cast<CoCanRouterReadError*>(read_err);
90 (*self)(err, ec);
91 }) {}
92
93 virtual ~CoCanRouterReadError() = default;
94
95 operator ev_task&() & noexcept { return task; }
96
98 ev::Executor
102
112 virtual void operator()(const can_err* err,
113 ::std::error_code ec) noexcept = 0;
114};
115
116} // namespace io
117} // namespace lely
118
119#endif // !LELY_IO2_CO_CAN_RT_HPP_
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.
Definition can_rt.c:522
#define IO_CAN_RT_READ_MSG_INIT(id, flags, func)
The static initializer for io_can_rt_read_msg.
Definition can_rt.h:77
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.
Definition can_rt.c:516
#define IO_CAN_RT_READ_ERR_INIT(func)
The static initializer for io_can_rt_read_err.
Definition can_rt.h:111
This header file is part of the I/O library; it contains the C++ interface for the CAN frame router.
A CANopen value.
Definition val.hpp:42
An abstract task executor. This class is a wrapper around #ev_exec_t*.
Definition exec.hpp:38
A CAN error frame read operation suitable for use with a CAN frame router, with a stackless coroutine...
Definition co_can_rt.hpp:80
CoCanRouterReadError() noexcept
Constructs a CAN error frame read operation.
Definition co_can_rt.hpp:83
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
Definition co_can_rt.hpp:99
virtual void operator()(const can_err *err, ::std::error_code ec) noexcept=0
The coroutine to be executed once the read operation completes (or is canceled).
A CAN frame read operation suitable for use with a CAN frame router, with a stackless coroutine as th...
Definition co_can_rt.hpp:38
CoCanRouterReadFrame(uint_least32_t id, CanFlag flags=CanFlag::NONE) noexcept
Constructs a CAN frame read operation.
Definition co_can_rt.hpp:41
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
Definition co_can_rt.hpp:59
virtual void operator()(const can_msg *msg, ::std::error_code ec) noexcept=0
The coroutine to be executed once the read operation completes (or is canceled).
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...
CanFlag
The error flags of a CAN bus, which are not mutually exclusive.
Definition msg.hpp:33
A CAN error frame.
Definition err.h:28
A CAN or CAN FD format frame.
Definition msg.h:87
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 CAN error frame read operation suitable for use with a CAN frame router.
Definition can_rt.h:100
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
Definition can_rt.h:105
A CAN frame read operation suitable for use with a CAN frame router.
Definition can_rt.h:52
struct ev_task task
The task (to be) submitted upon completion (or cancellation) of the read operation.
Definition can_rt.h:69
uint_least8_t flags
The flags of the CAN frame to be received (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR,...
Definition can_rt.h:64