co_usb
Loading...
Searching...
No Matches
co_usb::ev::detail::EventHandler Concept Reference

Concept defining an event handler for libusb. More...

#include <event_handler.hpp>

Concept definition

template<typename Ty>
concept co_usb::ev::detail::EventHandler = requires(Ty handler) {
{
handler.start(std::declval<libusb_context *>(), std::declval<std::stop_token>())
} -> std::same_as<bool>;
{ handler.ref() } noexcept -> std::same_as<void>;
{ handler.unref() } noexcept -> std::same_as<void>;
{ handler.stop() } -> std::same_as<void>;
}
Concept defining an event handler for libusb.
Definition event_handler.hpp:42

Detailed Description

Concept defining an event handler for libusb.

Template Parameters
TyType satisfying the EventHandler contract.

Libusb makes it non-trivial to integrate its event handling into a common fd polling loop. This abstraction allows pluggable event handling outside of executor internals.

An event handler is responsible for running libusb event processing (via libusb_handle_events... and/or polling libusb fds), and for providing the thread(s) used to run it.

A type Ty satisfies EventHandler if it provides:

  • Ty.start(libusb_context*, std::stop_token) -> bool
  • Ty.ref() noexcept -> void
  • Ty.unref() noexcept -> void
  • Ty.stop() noexcept -> void (must block until stopped)
Note
As stated before, though non-trivial, it would indeed be possible to integrate libusb fds with an existing event loop such as Corosio's. Since I do not intend on making Corosio a dependency such handler is not included. Feel free to submit a PR.