summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-08-08 13:34:50 +0200
committerJacopo Mondi <jacopo.mondi@ideasonboard.com>2023-08-08 14:34:28 +0200
commit7e1ff7441363c59c659023a3b1e66ea01aca236d (patch)
tree520020ad184b2a83d31f2f827ff8ce8c33cf9bb3
parent2855c178b0457405f3b8bb6dfa4c7ebd0450b652 (diff)
libcamera: device_enumerator: Search for USB devices
Add support for searching a USBDevice by providing a USBDeviceMatch to the device enumerator. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
-rw-r--r--include/libcamera/internal/device_enumerator.h1
-rw-r--r--src/libcamera/device_enumerator.cpp14
2 files changed, 15 insertions, 0 deletions
diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h
index 1d6dbcb1..f4ee3499 100644
--- a/include/libcamera/internal/device_enumerator.h
+++ b/include/libcamera/internal/device_enumerator.h
@@ -31,6 +31,7 @@ public:
virtual int enumerate() = 0;
std::shared_ptr<MediaDevice> search(const MediaDeviceMatch &dm);
+ std::shared_ptr<USBDevice> search(const USBDeviceMatch &dm);
Signal<> devicesAdded;
diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
index 1fde7367..0d983032 100644
--- a/src/libcamera/device_enumerator.cpp
+++ b/src/libcamera/device_enumerator.cpp
@@ -271,4 +271,18 @@ std::shared_ptr<MediaDevice> DeviceEnumerator::search(const MediaDeviceMatch &dm
return nullptr;
}
+std::shared_ptr<USBDevice> DeviceEnumerator::search(const USBDeviceMatch &dm)
+{
+ for (std::shared_ptr<USBDevice> &usb : usbDevices_) {
+ if (dm.match(usb.get())) {
+ LOG(DeviceEnumerator, Debug)
+ << "Successful match for USB device "
+ << usb->vid() << "-" << usb->pid();
+ return usb;
+ }
+ }
+
+ return nullptr;
+}
+
} /* namespace libcamera */