co_usb
Loading...
Searching...
No Matches
status.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::transfer
12{
13
21enum class status
22{
23 completed = LIBUSB_TRANSFER_COMPLETED,
24
26 error = LIBUSB_TRANSFER_ERROR,
27
29 timed_out = LIBUSB_TRANSFER_TIMED_OUT,
30
32 cancelled = LIBUSB_TRANSFER_CANCELLED,
33
36 stall = LIBUSB_TRANSFER_STALL,
37
39 no_device = LIBUSB_TRANSFER_NO_DEVICE,
40
42 overflow = LIBUSB_TRANSFER_OVERFLOW,
43};
44
45struct transfer_status_category_t : public std::error_category
46{
47 const char *name () const noexcept override
48 {
49 return "co_usb transfer status";
50 }
51
52 std::string message (int v) const override
53 {
54 switch (static_cast<status>(v))
55 {
56 using enum status;
57 case completed: return "completed";
58 case error: return "error";
59 case cancelled: return "cancelled";
60 case stall: return "device stalled";
61 case no_device: return "no such device";
62 case overflow: return "data overflow";
63 default: return "unknown";
64 }
65 }
66};
67
68inline const std::error_category &transfer_status_category ()
69{
70 static transfer_status_category_t instance;
71 return instance;
72}
73
74inline std::error_code make_transfer_status (status e) noexcept
75{
76 return {static_cast<int>(e), transfer_status_category()};
77}
78
79inline std::error_code make_transfer_status (libusb_transfer_status e) noexcept
80{
81 return {static_cast<int>(e), transfer_status_category()};
82}
83
84} // namespace co_usb::transfer
85
86namespace std
87{
88
89template <> struct is_error_code_enum<co_usb::transfer::status> : ::std::true_type
90{
91};
92
93} // namespace std
status
Status codes for transfers.
Definition status.hpp:22
Definition complete_io.hpp:18
const std::error_category & transfer_status_category()
Definition status.hpp:68
std::error_code make_transfer_status(status e) noexcept
Definition status.hpp:74
Definition flag_type.hpp:6
Definition status.hpp:87
const char * name() const noexcept override
Definition status.hpp:47
std::string message(int v) const override
Definition status.hpp:52