13#include <system_error>
45 throw std::system_error{ec};
53 : m_devh(other.m_devh), m_interface_num(other.m_interface_num)
55 other.m_devh =
nullptr;
68 throw std::system_error{ec};
70 m_devh = other.m_devh;
71 m_interface_num = other.m_interface_num;
72 other.m_devh =
nullptr;
81 auto release (std::error_code &ec)
noexcept ->
void
87 int r = libusb_release_interface(m_devh, m_interface_num);
88 if (r != LIBUSB_SUCCESS)
95 auto devh () const noexcept -> libusb_device_handle *
102 return m_interface_num;
106 : m_devh(detail::device_handle_of(devh_src)), m_interface_num(
interface_num)
111 libusb_device_handle *m_devh{
nullptr};
114static_assert(detail::DeviceHandleSource<interface>,
"Not a proper device handle source");
124template <detail::ErrorProtocol<
interface> ErrTy>
127 typename ErrTy::template return_type<interface>
132 int r = libusb_claim_interface(devh, interface_num);
133 if (r != LIBUSB_SUCCESS)
137 return errp.template with_success<interface>(devh, interface_num);
A type which can provide a co_usb::detail::DeviceHandlePointer.
Definition device_handle_source.hpp:42
Utilities for creating error protocols.
auto device_handle_of(Ty &&devh) -> libusb_device_handle *
Obtains a libusb_device_handle * from a co_usb::detail::DeviceHandlePointer.
Definition device_handle_source.hpp:57
auto claim_interface(detail::DeviceHandleSource auto const &devh_src, int interface_num, ErrTy &&errp=as_exception()) -> typename ErrTy::template return_type< interface >
Claims the interface and returns a interface or reports an error per error protocol implementation.
Definition interface.hpp:125
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 for an interface.
Definition interface.hpp:31
~interface() noexcept(false)
Releases the interface.
Definition interface.hpp:39
interface & operator=(interface &&other)
Definition interface.hpp:58
interface & operator=(interface const &)=delete
interface(interface const &)=delete
auto interface_num() const noexcept -> int
Definition interface.hpp:100
auto release(std::error_code &ec) noexcept -> void
Releases the interface.
Definition interface.hpp:81
auto devh() const noexcept -> libusb_device_handle *
Definition interface.hpp:95