13#include <system_error>
38 throw std::system_error{ec};
46 : m_devh(other.m_devh), m_interface_num(other.m_interface_num)
48 other.m_devh =
nullptr;
61 throw std::system_error{ec};
63 m_devh = other.m_devh;
64 m_interface_num = other.m_interface_num;
65 other.m_devh =
nullptr;
74 auto attach (std::error_code &ec)
noexcept ->
void
80 int r = libusb_attach_kernel_driver(m_devh, m_interface_num);
81 if (r != LIBUSB_SUCCESS)
88 auto devh () const noexcept -> libusb_device_handle *
95 return m_interface_num;
99 : m_devh(detail::device_handle_of(devh_src)), m_interface_num(driver_guard_num)
104 libusb_device_handle *m_devh{
nullptr};
107static_assert(detail::DeviceHandleSource<driver_guard>,
"Not a proper device handle source");
117template <detail::ErrorProtocol<driver_guard> ErrTy>
120 typename ErrTy::template return_type<driver_guard>
124 int r = libusb_detach_kernel_driver(devh, interface_num);
125 if (r != LIBUSB_SUCCESS)
127 return errp.template with_error<driver_guard>(
130 return errp.template with_success<driver_guard>(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 detach_driver(detail::DeviceHandleSource auto const &devh_src, int interface_num, ErrTy &&errp=as_exception()) -> typename ErrTy::template return_type< driver_guard >
Detaches the kernel driver and returns a driver_guard or reports an error per error protocol implemen...
Definition driver_guard.hpp:118
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 detaching and reattaching kernel driver.
Definition driver_guard.hpp:31
auto devh() const noexcept -> libusb_device_handle *
Definition driver_guard.hpp:88
driver_guard(detail::DeviceHandleSource auto const &devh_src, int driver_guard_num)
Definition driver_guard.hpp:98
driver_guard & operator=(driver_guard &&other)
Definition driver_guard.hpp:51
~driver_guard() noexcept(false)
Definition driver_guard.hpp:32
auto interface_num() const noexcept -> int
Definition driver_guard.hpp:93
driver_guard(driver_guard &&other) noexcept
Definition driver_guard.hpp:45
driver_guard(driver_guard const &)=delete
driver_guard & operator=(driver_guard const &)=delete
auto attach(std::error_code &ec) noexcept -> void
Reattaches the detached kernel driver.
Definition driver_guard.hpp:74