From patchwork Tue Aug 8 12:52:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18933 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 014CCBDB13 for ; Tue, 8 Aug 2023 12:52:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40F2B627F6; 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=1691499177; bh=YwkM69XCB4/whxxS4LwF7y8ZyetkH0w+mBXx1IjHZVM=; 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=QGjooKJQP7WwQbeSmkd6f5zf9m6+En2UHG2HvViSr6+bcXqqzuaTKu6buOgWZs+NO ljkDkMteqzRBV195BECEeulN25SRgLdW6j0AC36oA7umxgYgEnBUjflqC44KCfht+w EB+FRxRk6YiIStXQ8V5T92XIaIpcCbOwqQ7mdTkY9HzjFctMtyPtNiBNNDhzBhafFU 5B2TU3m1UzqUY1CMrvDAcI9tVYnxfFELfkIcRKisqabxkij/8hQmrBiXTkf4V8Vap6 HoQauc7Tzo1YV7dG7IoXhUF0mQ0nG5O3I4l/GRx9qA/y4HgAp2NOlnErQPe5B0nFJc P83qj0FXPfBeg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EA46627EF 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="OoIZt5k1"; 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 EE29E8624; Tue, 8 Aug 2023 14:51:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691499102; bh=YwkM69XCB4/whxxS4LwF7y8ZyetkH0w+mBXx1IjHZVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OoIZt5k1oVNT2B9CGaCjCB4KVcmEXbglw9rle/gK+kK1C5skDJOPhjRw8CBXeIzJT 7S/WIFJ1Mosoy/gu8C7GZz+Lb8EGscr3CIR7ZEXfroeGwFxRhM7u6Vf4QKVtFe9JAG btTjA1raOE2Tk/p7UlQzxLnm0MckQ31phjPHtkzU= To: libcamera-devel@lists.libcamera.org, Sophie Friedrich Date: Tue, 8 Aug 2023 14:52:25 +0200 Message-Id: <20230808125228.29043-7-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 6/9] libcamera: device_match: Introduce USBDeviceMatch 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" Introduce a USB-specific DeviceMatch derived class. Generalize the DeviceMatch::match() function by making its only parameter a CameraDevice instance and dynamically cast to the correct derived class in the overloaded match() functions. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/device_match.h | 21 ++++++++++++++++--- src/libcamera/device_match.cpp | 25 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/device_match.h b/include/libcamera/internal/device_match.h index 6df7dece1031..e6608cac2f85 100644 --- a/include/libcamera/internal/device_match.h +++ b/include/libcamera/internal/device_match.h @@ -12,12 +12,12 @@ namespace libcamera { -class MediaDevice; +class CameraDevice; class DeviceMatch { public: - virtual bool match(const MediaDevice *device) const = 0; + virtual bool match(const CameraDevice *device) const = 0; }; class MediaDeviceMatch : public DeviceMatch @@ -26,11 +26,26 @@ public: void add(const std::string &entity); MediaDeviceMatch(const std::string &driver); - bool match(const MediaDevice *device) const override; + bool match(const CameraDevice *device) const override; private: std::string driver_; std::vector entities_; }; +class USBDeviceMatch : public DeviceMatch +{ +public: + USBDeviceMatch(const std::string &vid, const std::string &pid) + : vid_(vid), pid_(pid) + { + } + + bool match(const CameraDevice *device) const override; + +private: + std::string vid_; + std::string pid_; +}; + }; /* namespace libcamera */ diff --git a/src/libcamera/device_match.cpp b/src/libcamera/device_match.cpp index 17937d435c88..8870649cb53b 100644 --- a/src/libcamera/device_match.cpp +++ b/src/libcamera/device_match.cpp @@ -7,7 +7,9 @@ #include "libcamera/internal/device_match.h" +#include "libcamera/internal/camera_device.h" #include "libcamera/internal/media_device.h" +#include "libcamera/internal/usb_device.h" /** * \file device_match.h @@ -84,15 +86,17 @@ void MediaDeviceMatch::add(const std::string &entity) * * \return True if the media device matches the search pattern, false otherwise */ -bool MediaDeviceMatch::match(const MediaDevice *device) const +bool MediaDeviceMatch::match(const CameraDevice *device) const { - if (driver_ != device->driver()) + const MediaDevice *media = static_cast(device); + + if (driver_ != media->driver()) return false; for (const std::string &name : entities_) { bool found = false; - for (const MediaEntity *entity : device->entities()) { + for (const MediaEntity *entity : media->entities()) { if (name == entity->name()) { found = true; break; @@ -106,4 +110,19 @@ bool MediaDeviceMatch::match(const MediaDevice *device) const return true; } +/** + * \brief Compare a search pattern with a USB device + * \param[in] device The USB device + * + * Matching is performed on the USB device vendorId and productId. + * + * \return True if the USB device matches the search pattern, false otherwise + */ +bool USBDeviceMatch::match(const CameraDevice *device) const +{ + const USBDevice *usb = static_cast(device); + + return usb->vid() == vid_ && usb->pid() == pid_; +} + } /* namespace libcamera */