co_usb
Loading...
Searching...
No Matches
device_triplet.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <libusb.h>
9
10namespace co_usb
11{
12
21{
22 int vid = LIBUSB_HOTPLUG_MATCH_ANY;
23 int pid = LIBUSB_HOTPLUG_MATCH_ANY;
24 int dev_class = LIBUSB_HOTPLUG_MATCH_ANY;
25
26 constexpr bool operator==(device_triplet const &other) const noexcept
27 {
28 return other.vid == this->vid && other.pid == this->pid &&
29 other.dev_class == this->dev_class;
30 }
31};
32
34{
35 constexpr bool operator()(const device_triplet &lhs, const device_triplet &rhs) const
36 {
37 constexpr auto cmp = [] (int const lhs, int const rhs) -> bool
38 {
39 return (lhs == rhs) || lhs == LIBUSB_HOTPLUG_MATCH_ANY ||
40 rhs == LIBUSB_HOTPLUG_MATCH_ANY;
41 };
42 return cmp(lhs.vid, rhs.vid) && cmp(lhs.pid, rhs.pid) && cmp(lhs.dev_class, rhs.dev_class);
43 }
44};
45
46inline auto triplet_from_descriptor (libusb_device_descriptor const &desc)
47{
48 return device_triplet{
49 .vid = desc.idVendor, .pid = desc.idProduct, .dev_class = desc.bDeviceClass};
50}
51
52}; // namespace co_usb
Definition flag_type.hpp:6
auto triplet_from_descriptor(libusb_device_descriptor const &desc)
Definition device_triplet.hpp:46
An aggregate struct to pass to functions requiring device information.
Definition device_triplet.hpp:21
int pid
Definition device_triplet.hpp:23
constexpr bool operator==(device_triplet const &other) const noexcept
Definition device_triplet.hpp:26
int dev_class
Definition device_triplet.hpp:24
int vid
Definition device_triplet.hpp:22
Definition device_triplet.hpp:34
constexpr bool operator()(const device_triplet &lhs, const device_triplet &rhs) const
Definition device_triplet.hpp:35