co_usb
Loading...
Searching...
No Matches
hotplug_awaitable.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "boost/capy/concept/io_awaitable.hpp"
4#include "boost/capy/continuation.hpp"
5#include "boost/capy/ex/io_env.hpp"
7#include "co_usb/error.hpp"
8#include <boost/capy/io_result.hpp>
10
11namespace co_usb
12{
13
27{
28 hotplug_awaitable(libusb_context *ctx, int events, int flags, int vid, int pid, int dev_class);
29
33 bool await_ready() noexcept;
34
44 std::coroutine_handle<> await_suspend(std::coroutine_handle<> h,
45 boost::capy::io_env const *env);
46
47 boost::capy::io_result<hotplug_event, device_ref> await_resume();
48
49 private:
50 libusb_context *m_ctx;
51 int m_events;
52 int m_flags;
53 int m_vid;
54 int m_pid;
55 int m_dev_class;
56
58
59 usb_error m_error;
60 struct cb_data
61 {
62 boost::capy::io_env const *io_env = nullptr;
63 boost::capy::continuation cont;
64 hotplug_event event;
65 device_ref dev;
66 } m_data;
67};
68
69static_assert(boost::capy::IoAwaitable<hotplug_awaitable>, "Not an IoAwaitable");
70
71} // namespace co_usb
Definition context.hpp:14
usb_error
Definition error.hpp:10
use_service
Definition context.hpp:17
hotplug_event
enum class wrapper for hotplug events
Definition hotplug.hpp:13
Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.
Definition device_ref.hpp:17
Low-level awaitable primitive for strapping hotplug callbacks to a coroutine ecosystem.
Definition hotplug_awaitable.hpp:27
boost::capy::io_result< hotplug_event, device_ref > await_resume()
Definition hotplug_awaitable.cpp:52
std::coroutine_handle await_suspend(std::coroutine_handle<> h, boost::capy::io_env const *env)
suspends and registers the callback
Definition hotplug_awaitable.cpp:17
bool await_ready() noexcept
Definition hotplug_awaitable.cpp:12