From patchwork Tue Aug 8 12:52:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18934 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A72C2C32B1 for ; Tue, 8 Aug 2023 12:52:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D68E8627F1; Tue, 8 Aug 2023 14:52:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1691499178; bh=poC0tU/raVEL68/bMsRJ6XkKvmnAQXlmX95+AFg0C6o=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=OrLME9fcSON9KmURyDyh3W1sZlWLq7SZ5LshOGiZcfujwUa0m0TYKmis9bzs++I9L esHiYwmuMHKhcY26ntdyRgotYO9BgKl+4ow113A7PM8fnNL0lrQ/pejx/6tzFhmPTA FUPg0FJ9jOI92UOniPhNG8aPLqb19HW8YvH4HoUlPTDzoDpBvP5DnS5dLz4y6XywyD gDSkPbybMgxUQdBt0IprdiSvnV3ffuUpdrdzTo0f4mSl+YQtFxGyIjvh+aUUgrwB0w OnO/VfxWBiqh1DEOA6VKbhwsKoA73GNEIdROU4rqgDr8+QmiifibH44ML0l5af8xce VpnZrVrmdPZSw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9C920627EE for ; Tue, 8 Aug 2023 14:52:50 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="R+YarRLb"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-60-22.net.vodafone.it [5.90.60.22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C0B308625; Tue, 8 Aug 2023 14:51:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691499103; bh=poC0tU/raVEL68/bMsRJ6XkKvmnAQXlmX95+AFg0C6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R+YarRLb2KZ7mJXlNlwvM6AWS0VOHQl7YD+151uUYmRjNtI6f1B3fenMvkACGTXub wNBhaGYl9tAlUJpZkaB3+FC7esLfJDDiqg7qRrYsvanv5hfGKE5VhYcLnb6Cdvjuou 5U7L8TSSbPPRo3By+txoISlzR2iGUbYiSVfRFZ4Q= To: libcamera-devel@lists.libcamera.org, Sophie Friedrich Date: Tue, 8 Aug 2023 14:52:26 +0200 Message-Id: <20230808125228.29043-8-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> References: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 7/9] libcamera: device_enumerator: Search for USB devices X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add support for searching a USBDevice by providing a USBDeviceMatch to the device enumerator. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/device_enumerator.h | 1 + src/libcamera/device_enumerator.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index 1d6dbcb104b8..f4ee349906f2 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 search(const MediaDeviceMatch &dm); + std::shared_ptr search(const USBDeviceMatch &dm); Signal<> devicesAdded; diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 1fde7367cfa8..0d983032e2c6 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -271,4 +271,18 @@ std::shared_ptr DeviceEnumerator::search(const MediaDeviceMatch &dm return nullptr; } +std::shared_ptr DeviceEnumerator::search(const USBDeviceMatch &dm) +{ + for (std::shared_ptr &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 */