co_usb
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <libusb-1.0/libusb.h>
4#include <system_error>
5
6namespace co_usb
7{
8
9enum class usb_error : int
10{
12
15
18
21
24
27
30
33
36
39
42
45
48
49 /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
50 message strings in strerror.c when adding new error codes here. */
51
54
55};
56struct error_category_t : public std::error_category
57{
58 const char *name () const noexcept override
59 {
60 return "co_usb usb error";
61 }
62
63 std::string message (int v) const override
64 {
65 return libusb_strerror(v);
66 }
67};
68
69inline const std::error_category &usb_error_category ()
70{
72 return instance;
73}
74
75inline std::error_code make_usb_error_code (usb_error e) noexcept
76{
77 return {static_cast<int>(e), usb_error_category()};
78}
79
80inline std::error_code make_usb_error_code (libusb_error e) noexcept
81{
82 return {static_cast<int>(e), usb_error_category()};
83}
84
85} // namespace co_usb
86
87namespace std
88{
89
90template <> struct is_error_code_enum<co_usb::usb_error> : ::std::true_type
91{
92};
93
94} // namespace std
Definition context.hpp:14
const std::error_category & usb_error_category()
Definition error.hpp:69
usb_error
Definition error.hpp:10
std::error_code make_usb_error_code(usb_error e) noexcept
Definition error.hpp:75
use_service
Definition context.hpp:17
Definition error.hpp:88
Definition error.hpp:57
const char * name() const noexcept override
Definition error.hpp:58
std::string message(int v) const override
Definition error.hpp:63