8#include "boost/capy/concept/io_awaitable.hpp"
9#include "boost/capy/continuation.hpp"
10#include "boost/capy/ex/io_env.hpp"
14#include <boost/capy/io_result.hpp>
15#include <system_error>
45 boost::capy::io_env
const *
io_env =
nullptr;
46 boost::capy::continuation
cont;
76 boost::capy::io_env
const *env)
78 if (env->stop_token.stop_requested())
80 op_res->
ec = std::make_error_code(std::errc::operation_canceled);
86 auto r = libusb_hotplug_register_callback(
88 [] (libusb_context *
ctx, libusb_device *dev, libusb_hotplug_event ev,
89 void *user_data) ->
int
98 if (r != LIBUSB_SUCCESS)
103 return std::noop_coroutine();
126static_assert(boost::capy::IoAwaitable<hotplug_awaitable>,
"Not an IoAwaitable");
Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.
Strongly typed wrappers libusb hotplug flag types (flags & events).
detail::flag_type< libusb_hotplug_event, struct hotplug_event_t > event_type
enum type for libusb_hotplug_event
Definition flags.hpp:19
Definition hotplug_awaitable.hpp:18
usb_error
USB error enumeration.
Definition usb_error.hpp:20
std::error_code make_usb_error_code(usb_error e) noexcept
Definition usb_error.hpp:85
Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.
Definition device_ref.hpp:25
Definition hotplug_awaitable.hpp:37
event_type event
Definition hotplug_awaitable.hpp:39
device_ref dev
Definition hotplug_awaitable.hpp:40
std::error_code ec
Definition hotplug_awaitable.hpp:38
Definition hotplug_awaitable.hpp:44
op_result * op_res
Definition hotplug_awaitable.hpp:47
boost::capy::io_env const * io_env
Definition hotplug_awaitable.hpp:45
boost::capy::continuation cont
Definition hotplug_awaitable.hpp:46
Low-level awaitable primitive for strapping hotplug callbacks to a coroutine ecosystem.
Definition hotplug_awaitable.hpp:35
int events
Definition hotplug_awaitable.hpp:119
int dev_class
Definition hotplug_awaitable.hpp:123
op_result * op_res
Definition hotplug_awaitable.hpp:117
libusb_context * ctx
Definition hotplug_awaitable.hpp:115
resumption_t * res
Definition hotplug_awaitable.hpp:118
int vid
Definition hotplug_awaitable.hpp:121
hotplug_awaitable(libusb_context *ctx, libusb_hotplug_callback_handle *handle, op_result *op_res, resumption_t *res, int events, int flags, int vid, int pid, int dev_class)
Definition hotplug_awaitable.hpp:50
int flags
Definition hotplug_awaitable.hpp:120
bool await_ready() noexcept
Definition hotplug_awaitable.hpp:61
libusb_hotplug_callback_handle * handle
Definition hotplug_awaitable.hpp:116
std::coroutine_handle await_suspend(std::coroutine_handle<> h, boost::capy::io_env const *env)
suspends and registers the callback
Definition hotplug_awaitable.hpp:75
int pid
Definition hotplug_awaitable.hpp:122
boost::capy::io_result< event_type, device_ref > await_resume()
Definition hotplug_awaitable.hpp:106