Lely core libraries  2.2.5
fiber_driver.cpp
Go to the documentation of this file.
1 
25 #include "coapp.hpp"
26 
27 #if !LELY_NO_COAPP_MASTER
28 
30 
31 namespace lely {
32 
33 namespace canopen {
34 
35 namespace detail {
36 
37 FiberDriverBase::FiberDriverBase(ev_exec_t* exec_)
38 #if !_WIN32 && _POSIX_MAPPED_FILES
39  : thrd(ev::FiberFlag::SAVE_ERROR | ev::FiberFlag::GUARD_STACK),
40 #else
41  : thrd(ev::FiberFlag::SAVE_ERROR),
42 #endif
43  exec(exec_),
44  strand(exec) {
45 }
46 
47 } // namespace detail
48 
49 FiberDriver::FiberDriver(ev_exec_t* exec, AsyncMaster& master, uint8_t id)
50  : FiberDriverBase(exec ? exec
51  : static_cast<ev_exec_t*>(master.GetExecutor())),
52  BasicDriver(FiberDriverBase::exec, master, id) {}
53 
54 void
55 FiberDriver::Wait(SdoFuture<void> f, ::std::error_code& ec) {
56  fiber_await(f);
57  try {
58  f.get().value();
59  } catch (const ::std::system_error& e) {
60  ec = e.code();
61  } catch (const ev::future_not_ready& e) {
62  ec = ::std::make_error_code(::std::errc::operation_canceled);
63  }
64 }
65 
66 void
67 FiberDriver::USleep(uint_least64_t usec) {
68  Wait(AsyncWait(::std::chrono::microseconds(usec)));
69 }
70 
71 void
72 FiberDriver::USleep(uint_least64_t usec, ::std::error_code& ec) {
73  Wait(AsyncWait(::std::chrono::microseconds(usec)), ec);
74 }
75 
76 } // namespace canopen
77 
78 } // namespace lely
79 
80 #endif // !LELY_NO_COAPP_MASTER
ev_exec_t
const struct ev_exec_vtbl *const ev_exec_t
An abstract task executor.
Definition: ev.h:29
lely::canopen::BasicDriver
The base class for drivers for remote CANopen nodes.
Definition: driver.hpp:278
lely::canopen::AsyncMaster
An asynchronous CANopen master.
Definition: master.hpp:1296
fiber_driver.hpp
lely::canopen::BasicDriver::AsyncWait
SdoFuture< void > AsyncWait(const time_point &t)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
Definition: driver.hpp:424
lely::canopen::FiberDriver::USleep
void USleep(uint_least64_t usec)
Suspends the calling fiber for usec microseconds.
Definition: fiber_driver.cpp:67
lely::canopen::FiberDriver::Wait
T Wait(SdoFuture< T > f)
Waits for the specified future to become ready by suspending the calling fiber.
Definition: fiber_driver.hpp:106
lely::ev::Future
A future.
Definition: future.hpp:50
lely::ev::Future::get
result_type & get()
Returns the result of a ready future.
Definition: future.hpp:490
coapp.hpp
lely::ev::future_not_ready
The exception thrown when retrieving the result of a future which is not ready or does not contain a ...
Definition: future.hpp:45
lely::canopen::make_error_code
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
Definition: sdo_error.cpp:170
lely::canopen::FiberDriver::FiberDriver
FiberDriver(ev_exec_t *exec, AsyncMaster &master, uint8_t id)
Creates a new CANopen driver and its associated fiber executor.
Definition: fiber_driver.cpp:49