{"id":23835,"url":"https://patchwork.libcamera.org/api/1.1/patches/23835/?format=json","web_url":"https://patchwork.libcamera.org/patch/23835/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20250717124853.2317191-3-dan.scally@ideasonboard.com>","date":"2025-07-17T12:48:51","name":"[v2,2/4] libcamera: device_enumerator: Support regex to match entity names","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9d94bfcf99671a142cf21ed8d87a9a3c25dbabd4","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/1.1/people/156/?format=json","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23835/mbox/","series":[{"id":5293,"url":"https://patchwork.libcamera.org/api/1.1/series/5293/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5293","date":"2025-07-17T12:48:49","name":"Use regular expressions for entity name matching","version":2,"mbox":"https://patchwork.libcamera.org/series/5293/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23835/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23835/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 34A78C32C8\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Jul 2025 12:49:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 249B268F7F;\n\tThu, 17 Jul 2025 14:49:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79F3661517\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Jul 2025 14:49:02 +0200 (CEST)","from mail.ideasonboard.com\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 640631FA4;\n\tThu, 17 Jul 2025 14:48:28 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"mQmdBjjz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1752756508;\n\tbh=AVd9Ab55yqR0mQI/Pk2d8gA9rqaX4VV6i7I8u0PGQoM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=mQmdBjjzwYDV45YAVoStsF8NymreqXv3Jd/tcUJjuGwvRsUqpP832yU+H5QJG8t9v\n\t1ynrUe22ZDXMa+omt8mOXR6rAefpEB5HrJbJplih+4DNJ9EGa2Sn1dwisKxp/SYAfz\n\ti9OnAN+GqAamHWslhEMlYB7nhXYaTSDIEnWgfrCk=","From":"Daniel Scally <dan.scally@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Daniel Scally <dan.scally@ideasonboard.com>","Subject":"[PATCH v2 2/4] libcamera: device_enumerator: Support regex to match\n\tentity names","Date":"Thu, 17 Jul 2025 13:48:51 +0100","Message-Id":"<20250717124853.2317191-3-dan.scally@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Some entities in a media graph have names that might differ from\nimplementation to implementation; for example the Camera Receiver\nUnit and CSI-2 receiver on the KakiP board have entities with names\nthat include their address, in the form \"csi-16000400.csi2\". Passing\nthat entity name to DeviceMatch is too inflexible given it would only\nwork if that specific CSI-2 receiver were the one being used.\n\nAdd an overload for DeviceMatch::add() such that users can pass in a\nstd::regex instead of a string. Update DeviceMatch::match() to check\nfor entities that are matched by the regular expressions added with\nthe new overload after checking for any exact matches from the vector\nof strings. This allows us to use regex to match on patterns like\n\"csi-[0-9a-f]{8}.csi2\".\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\nChanges in v2:\n\n\t- Instead of replacing the existing ::add() function and\n\tmatching process with regex, add an overload for ::add()\n\tthat takes a regex and incorporate that into ::match()\n\talongside the existing functionality.\n\n .../libcamera/internal/device_enumerator.h    |  4 +-\n src/libcamera/device_enumerator.cpp           | 37 ++++++++++++++++++-\n 2 files changed, 39 insertions(+), 2 deletions(-)","diff":"diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\nindex db3532a9..4e55e172 100644\n--- a/include/libcamera/internal/device_enumerator.h\n+++ b/include/libcamera/internal/device_enumerator.h\n@@ -11,6 +11,7 @@\n #include <string>\n #include <vector>\n \n+#include <libcamera/base/regex.h>\n #include <libcamera/base/signal.h>\n \n namespace libcamera {\n@@ -23,12 +24,13 @@ public:\n \tDeviceMatch(const std::string &driver);\n \n \tvoid add(const std::string &entity);\n-\n+\tvoid add(const std::regex &entity);\n \tbool match(const MediaDevice *device) const;\n \n private:\n \tstd::string driver_;\n \tstd::vector<std::string> entities_;\n+\tstd::vector<std::regex> entityRegexs_;\n };\n \n class DeviceEnumerator\ndiff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\nindex ae17862f..191758ca 100644\n--- a/src/libcamera/device_enumerator.cpp\n+++ b/src/libcamera/device_enumerator.cpp\n@@ -53,7 +53,8 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator)\n  *\n  * A DeviceMatch is created with a specific Linux device driver in mind,\n  * therefore the name of the driver is a required property. One or more Entity\n- * names can be added as match criteria.\n+ * names (or regular expressions designed to match an entity name) can be added\n+ * as match criteria.\n  *\n  * Pipeline handlers are recommended to add entities to DeviceMatch as\n  * appropriate to ensure that the media device they need can be uniquely\n@@ -81,6 +82,15 @@ void DeviceMatch::add(const std::string &entity)\n \tentities_.push_back(entity);\n }\n \n+/**\n+ * \\brief Add a regex to match a media entity name to the search pattern\n+ * \\param[in] entity The regex intended to match to an entity in the media graph\n+ */\n+void DeviceMatch::add(const std::regex &entity)\n+{\n+\tentityRegexs_.push_back(entity);\n+}\n+\n /**\n  * \\brief Compare a search pattern with a media device\n  * \\param[in] device The media device\n@@ -116,6 +126,31 @@ bool DeviceMatch::match(const MediaDevice *device) const\n \t\t\treturn false;\n \t}\n \n+\tfor (const std::regex &nameRegex : entityRegexs_) {\n+\t\tbool found = false;\n+\n+\t\tfor (const MediaEntity *entity : device->entities()) {\n+\t\t\tif (std::regex_search(entity->name(), nameRegex)) {\n+\t\t\t\tif (found) {\n+\t\t\t\t\tLOG(DeviceEnumerator, Error)\n+\t\t\t\t\t\t<< \"Multiple entities match regex\";\n+\t\t\t\t\treturn false;\n+\t\t\t\t}\n+\n+\t\t\t\tif (!entity->deviceNode().empty()) {\n+\t\t\t\t\tfound = true;\n+\t\t\t\t} else {\n+\t\t\t\t\tLOG(DeviceEnumerator, Debug)\n+\t\t\t\t\t\t<< \"Skip \" << entity->name()\n+\t\t\t\t\t\t<< \": no device node\";\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\tif (!found)\n+\t\t\treturn false;\n+\t}\n+\n \treturn true;\n }\n \n","prefixes":["v2","2/4"]}