Lely core libraries  2.2.5
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>
29 #include <lely/util/coroutine.hpp>
30 
31 namespace lely {
32 namespace io {
33 
39  public:
41  explicit CoCanRouterReadFrame(uint_least32_t id,
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 
59  get_executor() const noexcept {
60  return ev::Executor(task.exec);
61  }
62 
72  virtual void operator()(const can_msg* msg,
73  ::std::error_code ec) noexcept = 0;
74 };
75 
81  public:
83  explicit CoCanRouterReadError() noexcept
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 
99  get_executor() const noexcept {
100  return ev::Executor(task.exec);
101  }
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_
A CAN or CAN FD format frame.
Definition: msg.h:87
CanFlag
The error flags of a CAN bus, which are not mutually exclusive.
Definition: msg.hpp:33
This header file is part of the utilities library; it contains the C++ implementation of stackless co...
ev::Executor get_executor() const noexcept
Returns the executor to which the completion task is (to be) submitted.
Definition: co_can_rt.hpp:59
CoCanRouterReadError() noexcept
Constructs a CAN error frame read operation.
Definition: co_can_rt.hpp:83
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:99
The parent class for function objects used as stackless coroutines.
Definition: coroutine.hpp:48
A CAN error frame.
Definition: err.h:28
#define IO_CAN_RT_READ_ERR_INIT(func)
The static initializer for io_can_rt_read_err.
Definition: can_rt.h:111
ev_exec_t * exec
A pointer to the executor to which the task is (to be) submitted.
Definition: task.h:43
This header file is part of the I/O library; it contains the C++ interface for the CAN frame router...
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:512
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
A CAN error frame read operation suitable for use with a CAN frame router, with a stackless coroutine...
Definition: co_can_rt.hpp:80
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:506
An executable task.
Definition: task.h:41
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).
An abstract task executor. This class is a wrapper around ev_exec_t*.
Definition: exec.hpp:38
A CAN frame read operation suitable for use with a CAN frame router.
Definition: can_rt.h:52
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
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:69
Definition: buf.hpp:32
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).
Definition: can_rt.h:64
#define IO_CAN_RT_READ_MSG_INIT(id, flags, func)
The static initializer for io_can_rt_read_msg.
Definition: can_rt.h:77