Patch Detail
Show a patch.
GET /api/patches/18933/?format=api
{ "id": 18933, "url": "https://patchwork.libcamera.org/api/patches/18933/?format=api", "web_url": "https://patchwork.libcamera.org/patch/18933/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20230808125228.29043-7-jacopo.mondi@ideasonboard.com>", "date": "2023-08-08T12:52:25", "name": "[libcamera-devel,RFC,6/9] libcamera: device_match: Introduce USBDeviceMatch", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "9b19ac786578eb9041d4c9b4c5c8d9d6c52a5fe3", "submitter": { "id": 143, "url": "https://patchwork.libcamera.org/api/people/143/?format=api", "name": "Jacopo Mondi", "email": "jacopo.mondi@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/18933/mbox/", "series": [ { "id": 4002, "url": "https://patchwork.libcamera.org/api/series/4002/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4002", "date": "2023-08-08T12:52:19", "name": "libcamera: Generalize device match and support USB devices", "version": 1, "mbox": "https://patchwork.libcamera.org/series/4002/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/18933/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/18933/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 014CCBDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 8 Aug 2023 12:52:57 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 40F2B627F6;\n\tTue, 8 Aug 2023 14:52:57 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EA46627EF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 8 Aug 2023 14:52:50 +0200 (CEST)", "from uno.localdomain (mob-5-90-60-22.net.vodafone.it [5.90.60.22])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EE29E8624; \n\tTue, 8 Aug 2023 14:51:41 +0200 (CEST)" ], "DKIM-Signature": [ "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1691499177;\n\tbh=YwkM69XCB4/whxxS4LwF7y8ZyetkH0w+mBXx1IjHZVM=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=QGjooKJQP7WwQbeSmkd6f5zf9m6+En2UHG2HvViSr6+bcXqqzuaTKu6buOgWZs+NO\n\tljkDkMteqzRBV195BECEeulN25SRgLdW6j0AC36oA7umxgYgEnBUjflqC44KCfht+w\n\tEB+FRxRk6YiIStXQ8V5T92XIaIpcCbOwqQ7mdTkY9HzjFctMtyPtNiBNNDhzBhafFU\n\t5B2TU3m1UzqUY1CMrvDAcI9tVYnxfFELfkIcRKisqabxkij/8hQmrBiXTkf4V8Vap6\n\tHoQauc7Tzo1YV7dG7IoXhUF0mQ0nG5O3I4l/GRx9qA/y4HgAp2NOlnErQPe5B0nFJc\n\tP83qj0FXPfBeg==", "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1691499102;\n\tbh=YwkM69XCB4/whxxS4LwF7y8ZyetkH0w+mBXx1IjHZVM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OoIZt5k1oVNT2B9CGaCjCB4KVcmEXbglw9rle/gK+kK1C5skDJOPhjRw8CBXeIzJT\n\t7S/WIFJ1Mosoy/gu8C7GZz+Lb8EGscr3CIR7ZEXfroeGwFxRhM7u6Vf4QKVtFe9JAG\n\tbtTjA1raOE2Tk/p7UlQzxLnm0MckQ31phjPHtkzU=" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"OoIZt5k1\"; dkim-atps=neutral", "To": "libcamera-devel@lists.libcamera.org, Sophie Friedrich <dev@flowerpot.me>", "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", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [RFC 6/9] libcamera: device_match: Introduce\n\tUSBDeviceMatch", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "From": "Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>", "Reply-To": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Cc": "Jacopo Mondi <jacopo.mondi@ideasonboard.com>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Introduce a USB-specific DeviceMatch derived class.\n\nGeneralize the DeviceMatch::match() function by making its only\nparameter a CameraDevice instance and dynamically cast to the correct\nderived class in the overloaded match() functions.\n\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n---\n include/libcamera/internal/device_match.h | 21 ++++++++++++++++---\n src/libcamera/device_match.cpp | 25 ++++++++++++++++++++---\n 2 files changed, 40 insertions(+), 6 deletions(-)", "diff": "diff --git a/include/libcamera/internal/device_match.h b/include/libcamera/internal/device_match.h\nindex 6df7dece1031..e6608cac2f85 100644\n--- a/include/libcamera/internal/device_match.h\n+++ b/include/libcamera/internal/device_match.h\n@@ -12,12 +12,12 @@\n \n namespace libcamera {\n \n-class MediaDevice;\n+class CameraDevice;\n \n class DeviceMatch\n {\n public:\n-\tvirtual bool match(const MediaDevice *device) const = 0;\n+\tvirtual bool match(const CameraDevice *device) const = 0;\n };\n \n class MediaDeviceMatch : public DeviceMatch\n@@ -26,11 +26,26 @@ public:\n \tvoid add(const std::string &entity);\n \tMediaDeviceMatch(const std::string &driver);\n \n-\tbool match(const MediaDevice *device) const override;\n+\tbool match(const CameraDevice *device) const override;\n \n private:\n \tstd::string driver_;\n \tstd::vector<std::string> entities_;\n };\n \n+class USBDeviceMatch : public DeviceMatch\n+{\n+public:\n+\tUSBDeviceMatch(const std::string &vid, const std::string &pid)\n+\t\t: vid_(vid), pid_(pid)\n+\t{\n+\t}\n+\n+\tbool match(const CameraDevice *device) const override;\n+\n+private:\n+\tstd::string vid_;\n+\tstd::string pid_;\n+};\n+\n }; /* namespace libcamera */\ndiff --git a/src/libcamera/device_match.cpp b/src/libcamera/device_match.cpp\nindex 17937d435c88..8870649cb53b 100644\n--- a/src/libcamera/device_match.cpp\n+++ b/src/libcamera/device_match.cpp\n@@ -7,7 +7,9 @@\n \n #include \"libcamera/internal/device_match.h\"\n \n+#include \"libcamera/internal/camera_device.h\"\n #include \"libcamera/internal/media_device.h\"\n+#include \"libcamera/internal/usb_device.h\"\n \n /**\n * \\file device_match.h\n@@ -84,15 +86,17 @@ void MediaDeviceMatch::add(const std::string &entity)\n *\n * \\return True if the media device matches the search pattern, false otherwise\n */\n-bool MediaDeviceMatch::match(const MediaDevice *device) const\n+bool MediaDeviceMatch::match(const CameraDevice *device) const\n {\n-\tif (driver_ != device->driver())\n+\tconst MediaDevice *media = static_cast<const MediaDevice *>(device);\n+\n+\tif (driver_ != media->driver())\n \t\treturn false;\n \n \tfor (const std::string &name : entities_) {\n \t\tbool found = false;\n \n-\t\tfor (const MediaEntity *entity : device->entities()) {\n+\t\tfor (const MediaEntity *entity : media->entities()) {\n \t\t\tif (name == entity->name()) {\n \t\t\t\tfound = true;\n \t\t\t\tbreak;\n@@ -106,4 +110,19 @@ bool MediaDeviceMatch::match(const MediaDevice *device) const\n \treturn true;\n }\n \n+/**\n+ * \\brief Compare a search pattern with a USB device\n+ * \\param[in] device The USB device\n+ *\n+ * Matching is performed on the USB device vendorId and productId.\n+ *\n+ * \\return True if the USB device matches the search pattern, false otherwise\n+ */\n+bool USBDeviceMatch::match(const CameraDevice *device) const\n+{\n+\tconst USBDevice *usb = static_cast<const USBDevice *>(device);\n+\n+\treturn usb->vid() == vid_ && usb->pid() == pid_;\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "RFC", "6/9" ] }