14#include <boost/capy/ex/executor_ref.hpp>
42 explicit device_handle (libusb_device_handle *devh) : m_storage(devh, libusb_close)
46 auto get () const noexcept -> libusb_device_handle *
48 return m_storage.get();
56 auto release () noexcept -> libusb_device_handle *
58 return m_storage.release();
67 std::unique_ptr<libusb_device_handle,
decltype(&libusb_close)> m_storage;
78template <detail::ErrorProtocol<device_handle> ErrTy>
80 typename ErrTy::template return_type<device_handle>
83 libusb_device_handle *devh = libusb_open_device_with_vid_pid(ctx, triplet.vid, triplet.pid);
88 return errp.template with_success<device_handle>(devh);
112template <detail::ErrorProtocol<device_handle> ErrTy>
114 typename ErrTy::template return_type<device_handle>
116 libusb_device_handle *devh;
117 int r = libusb_open(dev_ref.get(), &devh);
118 if (r != LIBUSB_SUCCESS)
120 return errp.template with_error<device_handle>(
123 return errp.template with_success<device_handle>(devh);
Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.
An aggregate struct to pass to functions requiring device information.
Utilities for creating error protocols.
auto open_device(boost::capy::executor_ref exec, device_triplet triplet, ErrTy &&errp) -> typename ErrTy::template return_type< device_handle >
Opens a device by triplet and returns a device_handle or reports an error per error protocol implemen...
Definition device_handle.hpp:79
Capy execution_context service wrapping a libusb event handler.
auto get_handler_service(boost::capy::executor_ref exec) -> handler_service &
Retrieve the handler_service from a given executor.
Definition handler_service.hpp:248
Definition flag_type.hpp:6
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
constexpr auto as_exception() noexcept -> detail::as_exception_t
Definition error_protocol.hpp:13
RAII wrapper around libusb_device_handle*.
Definition device_handle.hpp:35
auto release() noexcept -> libusb_device_handle *
Definition device_handle.hpp:56
device_handle(const device_handle &)=delete
device_handle & operator=(const device_handle &)=delete
device_handle(libusb_device_handle *devh)
Definition device_handle.hpp:42
device_handle & operator=(device_handle &&)=default
device_handle(device_handle &&)=default
auto close() noexcept
Definition device_handle.hpp:61
auto reset() noexcept
Definition device_handle.hpp:51
auto get() const noexcept -> libusb_device_handle *
Definition device_handle.hpp:46
Wrapper for nullable libusb_device that increments ref count on ctor and decrements on dtor.
Definition device_ref.hpp:25
An aggregate struct to pass to functions requiring device information.
Definition device_triplet.hpp:21