{"id":23654,"url":"https://patchwork.libcamera.org/api/1.1/patches/23654/?format=json","web_url":"https://patchwork.libcamera.org/patch/23654/","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":"<20250625155308.2325438-3-dan.scally@ideasonboard.com>","date":"2025-06-25T15:53:08","name":"[v1,2/2] libcamera: media_device: Use a regex to match entity name","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"f50575f833d7ed1cf9edd52d0224349cb6e95b30","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/23654/mbox/","series":[{"id":5247,"url":"https://patchwork.libcamera.org/api/1.1/series/5247/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5247","date":"2025-06-25T15:53:06","name":"Use regular expressions for entity name matching","version":1,"mbox":"https://patchwork.libcamera.org/series/5247/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23654/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23654/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 2E5DCC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 25 Jun 2025 15:53:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A7C7868DF8;\n\tWed, 25 Jun 2025 17:53:31 +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 4D65A68DE6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 25 Jun 2025 17:53:27 +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 13DF9D77;\n\tWed, 25 Jun 2025 17:53:09 +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=\"Tl93aaI7\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1750866789;\n\tbh=aDYSWJisyufDScRZiZkGRKzIogrFovDgOxs6196AWcM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Tl93aaI7VMGdchPKXPjpcMbizzzC+sWCEp1OTksiLMVZlTu2lHou9C7vvdtbstPRI\n\t/GCGwjMV2jg1CrhZ3JJxGUYdvsSACPxSXm+D7cxEvlwV3wQdpUMxwbtCB5ctrFH2dB\n\t2g3z218ytGPfjbtseoXb4wb3LJIMkYXVMRl+/VD0=","From":"Daniel Scally <dan.scally@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Daniel Scally <dan.scally@ideasonboard.com>","Subject":"[PATCH v1 2/2] libcamera: media_device: Use a regex to match entity\n\tname","Date":"Wed, 25 Jun 2025 16:53:08 +0100","Message-Id":"<20250625155308.2325438-3-dan.scally@ideasonboard.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20250625155308.2325438-1-dan.scally@ideasonboard.com>","References":"<20250625155308.2325438-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 kernel drivers give their entities names that will differ from\nimplementation to implementation; for example the drivers for the\nCamera Receiver Unit and CSI-2 receiver in the RZ/V2H SoC give their\nentities names that include their memory address, in the format\n\"csi-16000400.csi2\". Passing that entity name to\nMediaDevice::getEntityByName() is too inflexible given it would only\nthen work if that specific CSI-2 receiver were the one being used.\n\nUpdate MediaDevice::getEntityByName() such that the string passed to\nit is used to create a std::basic_regex, and use std::regex_search()\ninstead of a direct string comparison to find a matching entity. This\nallows us to pass a string that will form a regex to match to the\nentity instead, for example \"csi-[0-9]{8}.csi2\".\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n---\n src/libcamera/media_device.cpp   | 12 ++++++++----\n src/libcamera/v4l2_subdevice.cpp |  4 ++--\n 2 files changed, 10 insertions(+), 6 deletions(-)","diff":"diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 353f34a8..27180ca5 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -9,6 +9,7 @@\n \n #include <errno.h>\n #include <fcntl.h>\n+#include <regex>\n #include <stdint.h>\n #include <string>\n #include <string.h>\n@@ -328,14 +329,17 @@ done:\n  */\n \n /**\n- * \\brief Return the MediaEntity with name \\a name\n- * \\param[in] name The entity name\n- * \\return The entity with \\a name, or nullptr if no such entity is found\n+ * \\brief Return the MediaEntity with name matching the regex \\a name\n+ * \\param[in] name Regex to match against the entity name\n+ * \\return The entity with name matching \\a name, or nullptr if no such entity\n+ * is found\n  */\n MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n {\n+\tstd::regex name_regex(name);\n+\n \tfor (MediaEntity *e : entities_)\n-\t\tif (e->name() == name)\n+\t\tif (std::regex_search(e->name(), name_regex))\n \t\t\treturn e;\n \n \treturn nullptr;\ndiff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\nindex 33279654..4868785d 100644\n--- a/src/libcamera/v4l2_subdevice.cpp\n+++ b/src/libcamera/v4l2_subdevice.cpp\n@@ -1748,10 +1748,10 @@ const std::string &V4L2Subdevice::model()\n  */\n \n /**\n- * \\brief Create a new video subdevice instance from \\a entity in media device\n+ * \\brief Create a new video subdevice instance from an entity in media device\n  * \\a media\n  * \\param[in] media The media device where the entity is registered\n- * \\param[in] entity The media entity name\n+ * \\param[in] entity A regex that will match media entity name\n  *\n  * \\return A newly created V4L2Subdevice on success, nullptr otherwise\n  */\n","prefixes":["v1","2/2"]}