co_usb
Loading...
Searching...
No Matches
usb_error.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <libusb.h>
9#include <system_error>
10
11namespace co_usb
12{
13
19enum class usb_error : int
20{
21 success = LIBUSB_SUCCESS,
22
24 io_error = LIBUSB_ERROR_IO,
25
27 invalid_param = LIBUSB_ERROR_INVALID_PARAM,
28
30 access_error = LIBUSB_ERROR_ACCESS,
31
33 no_device = LIBUSB_ERROR_NO_DEVICE,
34
36 not_found = LIBUSB_ERROR_NOT_FOUND,
37
39 resource_busy = LIBUSB_ERROR_BUSY,
40
42 timed_out = LIBUSB_ERROR_TIMEOUT,
43
45 overflow = LIBUSB_ERROR_OVERFLOW,
46
48 broken_pipe = LIBUSB_ERROR_PIPE,
49
51 interrupted = LIBUSB_ERROR_INTERRUPTED,
52
54 out_of_memory = LIBUSB_ERROR_NO_MEM,
55
57 not_supported = LIBUSB_ERROR_NOT_SUPPORTED,
58
59 /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
60 message strings in strerror.c when adding new error codes here. */
61
63 unknown = LIBUSB_ERROR_OTHER,
64
65};
66struct error_category_t : public std::error_category
67{
68 const char *name () const noexcept override
69 {
70 return "co_usb usb error";
71 }
72
73 std::string message (int v) const override
74 {
75 return libusb_strerror(v);
76 }
77};
78
79inline const std::error_category &usb_error_category ()
80{
81 static error_category_t instance;
82 return instance;
83}
84
85inline std::error_code make_usb_error_code (usb_error e) noexcept
86{
87 return {static_cast<int>(e), usb_error_category()};
88}
89
90inline std::error_code make_usb_error_code (libusb_error e) noexcept
91{
92 return {static_cast<int>(e), usb_error_category()};
93}
94
95} // namespace co_usb
96
97namespace std
98{
99
100template <> struct is_error_code_enum<co_usb::usb_error> : ::std::true_type
101{
102};
103
104} // namespace std
Definition flag_type.hpp:6
const std::error_category & usb_error_category()
Definition usb_error.hpp:79
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
Definition status.hpp:87
Definition usb_error.hpp:67
const char * name() const noexcept override
Definition usb_error.hpp:68
std::string message(int v) const override
Definition usb_error.hpp:73