[{"id":34919,"web_url":"https://patchwork.libcamera.org/comment/34919/","msgid":"<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","date":"2025-07-17T15:46:28","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"Hi\n\n2025. 07. 17. 14:48 keltezéssel, Daniel Scally írta:\n> Some entities in a media graph have names that might differ from\n> implementation to implementation; for example the Camera Receiver\n> Unit and CSI-2 receiver on the KakiP board have entities with names\n> that include their address, in the form \"csi-16000400.csi2\". Passing\n> that entity name to DeviceMatch is too inflexible given it would only\n> work if that specific CSI-2 receiver were the one being used.\n> \n> Add an overload for DeviceMatch::add() such that users can pass in a\n> std::regex instead of a string. Update DeviceMatch::match() to check\n> for entities that are matched by the regular expressions added with\n> the new overload after checking for any exact matches from the vector\n> of strings. This allows us to use regex to match on patterns like\n> \"csi-[0-9a-f]{8}.csi2\".\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes 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(-)\n> \n> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> index 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\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index 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\nvoid DeviceMatch::add(std::regex entity)\n{\n     entityRegexs_.push_back(std::move(entity));\n\n\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\nWhy not `regex_match()`? I feel like maybe the whole name should be matched\nby default? I believe it would make sense from a consistency point of view\nsince `entities_` only allows full matches.\n\n\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\nI suppose another concern could be if multiple regex patterns match the same\nentity. Although that is probably the smaller issue out of the two.\n\n\nRegards,\nBarnabás Pőcze\n\n\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>","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 B883EC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Jul 2025 15:46:34 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E1F9568F84;\n\tThu, 17 Jul 2025 17:46:33 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0383061517\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Jul 2025 17:46:31 +0200 (CEST)","from [192.168.33.18] (185.221.140.39.nat.pool.zt.hu\n\t[185.221.140.39])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A844B1E74;\n\tThu, 17 Jul 2025 17:45:57 +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=\"FH0xWuew\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1752767157;\n\tbh=5tpFac5k5j5FuCyQBlUSe8PZpxfqEX73BOJRRhDd3LY=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=FH0xWuewcr1uFMPdaAgRsVdEl+9WCyUqMmatK6D6mIFNxgyLnumlOs4i1vx0SdhNd\n\ttF8Bd4MriCvRI8/p6CVS3lpWNlRt+1yHktdEjVl0aqqmbrlKUVoEI4PN1vOo8ZH94G\n\tguQnHMG13y2kX7nT2Ft2RiELSp7CCIkbEwXJ/aC8=","Message-ID":"<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","Date":"Thu, 17 Jul 2025 17:46:28 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","To":"Daniel Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250717124853.2317191-3-dan.scally@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}},{"id":35472,"web_url":"https://patchwork.libcamera.org/comment/35472/","msgid":"<175551335151.2014387.7846224393939223576@localhost>","date":"2025-08-18T10:35:51","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Barnabás,\n\nQuoting Barnabás Pőcze (2025-07-17 17:46:28)\n> Hi\n> \n> 2025. 07. 17. 14:48 keltezéssel, Daniel Scally írta:\n> > Some entities in a media graph have names that might differ from\n> > implementation to implementation; for example the Camera Receiver\n> > Unit and CSI-2 receiver on the KakiP board have entities with names\n> > that include their address, in the form \"csi-16000400.csi2\". Passing\n> > that entity name to DeviceMatch is too inflexible given it would only\n> > work if that specific CSI-2 receiver were the one being used.\n> > \n> > Add an overload for DeviceMatch::add() such that users can pass in a\n> > std::regex instead of a string. Update DeviceMatch::match() to check\n> > for entities that are matched by the regular expressions added with\n> > the new overload after checking for any exact matches from the vector\n> > of strings. This allows us to use regex to match on patterns like\n> > \"csi-[0-9a-f]{8}.csi2\".\n> > \n> > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> > ---\n> > Changes in v2:\n> > \n> >       - Instead of replacing the existing ::add() function and\n> >       matching process with regex, add an overload for ::add()\n> >       that takes a regex and incorporate that into ::match()\n> >       alongside 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(-)\n> > \n> > diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> > index 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> >       DeviceMatch(const std::string &driver);\n> >   \n> >       void add(const std::string &entity);\n> > -\n> > +     void add(const std::regex &entity);\n> >       bool match(const MediaDevice *device) const;\n> >   \n> >   private:\n> >       std::string driver_;\n> >       std::vector<std::string> entities_;\n> > +     std::vector<std::regex> entityRegexs_;\n> >   };\n> >   \n> >   class DeviceEnumerator\n> > diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> > index 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> >       entities_.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> > +     entityRegexs_.push_back(entity);\n> \n> void DeviceMatch::add(std::regex entity)\n> {\n>      entityRegexs_.push_back(std::move(entity));\n> \n> \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> >                       return false;\n> >       }\n> >   \n> > +     for (const std::regex &nameRegex : entityRegexs_) {\n> > +             bool found = false;\n> > +\n> > +             for (const MediaEntity *entity : device->entities()) {\n> > +                     if (std::regex_search(entity->name(), nameRegex)) {\n> \n> Why not `regex_match()`? I feel like maybe the whole name should be matched\n> by default? I believe it would make sense from a consistency point of view\n> since `entities_` only allows full matches.\n\nI don't know if that is really necessary. DeviceMatch is already\nlimiting on a given driver name. So forcing the match on the full name\nseems to make the calling code more complicated? And the caller is still\nfree to add ^ and $ to ensure a full match. Or am I missing something\nhere?\n\nRegards,\nStefan\n\n> \n> \n> > +                             if (found) {\n> > +                                     LOG(DeviceEnumerator, Error)\n> > +                                             << \"Multiple entities match regex\";\n> \n> I suppose another concern could be if multiple regex patterns match the same\n> entity. Although that is probably the smaller issue out of the two.\n> \n> \n> Regards,\n> Barnabás Pőcze\n> \n> \n> > +                                     return false;\n> > +                             }\n> > +\n> > +                             if (!entity->deviceNode().empty()) {\n> > +                                     found = true;\n> > +                             } else {\n> > +                                     LOG(DeviceEnumerator, Debug)\n> > +                                             << \"Skip \" << entity->name()\n> > +                                             << \": no device node\";\n> > +                             }\n> > +                     }\n> > +             }\n> > +\n> > +             if (!found)\n> > +                     return false;\n> > +     }\n> > +\n> >       return true;\n> >   }\n> >   \n>","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 10F40BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Aug 2025 10:35:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 193F569261;\n\tMon, 18 Aug 2025 12:35:56 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64C0D69257\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Aug 2025 12:35:54 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:766d:a405:f64e:fe3a])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 3BB342394; \n\tMon, 18 Aug 2025 12:34:57 +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=\"NkrecsUB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755513297;\n\tbh=tlnRBkq0PmzX6zqb5/FAx808r1fYj54GiKPk0ZQH1TM=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=NkrecsUB/SzvFTlKxF7rjPio5Z6xDFuMf1VRp3ZSHuzVDokR7IN0cFBxzXCOMxq5r\n\t3kYkid0xE01m4jIK45U6V0oLuOXgITkKdBUxzM2/qzifJgxN0vv+Mtwfs8ABWVd2P1\n\tI3YIWDtwidafonm/OoQAqhfeRY1hLrSX5xdLCtkY=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>\n\t<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 18 Aug 2025 12:35:51 +0200","Message-ID":"<175551335151.2014387.7846224393939223576@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}},{"id":36522,"web_url":"https://patchwork.libcamera.org/comment/36522/","msgid":"<kpl2q2slckb2l6jpfx74z2kljhnp5j3j4xvazi43hiayd2y4o3@f5dxijbksca7>","date":"2025-10-28T15:49:20","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Dan\n\nOn Thu, Jul 17, 2025 at 01:48:51PM +0100, Daniel Scally wrote:\n> Some entities in a media graph have names that might differ from\n> implementation to implementation; for example the Camera Receiver\n> Unit and CSI-2 receiver on the KakiP board have entities with names\n\nOn top of Barnabas' comments, I have a tiny thing here\ns/KakiP/Renesas V2H/\n\nlike for the other patches in the series\n\n> that include their address, in the form \"csi-16000400.csi2\". Passing\n> that entity name to DeviceMatch is too inflexible given it would only\n> work if that specific CSI-2 receiver were the one being used.\n>\n> Add an overload for DeviceMatch::add() such that users can pass in a\n> std::regex instead of a string. Update DeviceMatch::match() to check\n> for entities that are matched by the regular expressions added with\n> the new overload after checking for any exact matches from the vector\n> of strings. This allows us to use regex to match on patterns like\n> \"csi-[0-9a-f]{8}.csi2\".\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes 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(-)\n>\n> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> index 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\n> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> index 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> --\n> 2.34.1\n>","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 E9663BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Oct 2025 15:49:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1A1E8607E0;\n\tTue, 28 Oct 2025 16:49:26 +0100 (CET)","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 203C2606DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Oct 2025 16:49:24 +0100 (CET)","from ideasonboard.com (mob-5-90-58-13.net.vodafone.it [5.90.58.13])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4E19F16CD;\n\tTue, 28 Oct 2025 16:47:35 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"MAdbJEYT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761666455;\n\tbh=37C4kF/qSkVWqfaq0QNdqLkUDpKOSgyB+JV0EC35sCs=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=MAdbJEYTuWeU0RJLWP7tuWrjO+6QZE+ryN8XNvP7hQzatkaKLv5iLNOsJ96XIZh5d\n\tEhpG72rfUPKBAXLrPqNemGg51w1Xuq0BE5AwQdRcrr45rfgZvYBK1BEIt8giAY2aWS\n\t9KWwP3OXdwmdZ4ti9NjBz+3nZTqBAxVUCb39ZMeI=","Date":"Tue, 28 Oct 2025 16:49:20 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","Message-ID":"<kpl2q2slckb2l6jpfx74z2kljhnp5j3j4xvazi43hiayd2y4o3@f5dxijbksca7>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250717124853.2317191-3-dan.scally@ideasonboard.com>","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>"}},{"id":37166,"web_url":"https://patchwork.libcamera.org/comment/37166/","msgid":"<o7ab6nknjtserfpy25qv45xfui4l7xugmepurnouvlic3khr5n@bkx22exmup2u>","date":"2025-12-02T16:12:33","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás, Stefan\n\nOn Mon, Aug 18, 2025 at 12:35:51PM +0200, Stefan Klug wrote:\n> Hi Barnabás,\n>\n> Quoting Barnabás Pőcze (2025-07-17 17:46:28)\n> > Hi\n> >\n> > 2025. 07. 17. 14:48 keltezéssel, Daniel Scally írta:\n> > > Some entities in a media graph have names that might differ from\n> > > implementation to implementation; for example the Camera Receiver\n> > > Unit and CSI-2 receiver on the KakiP board have entities with names\n> > > that include their address, in the form \"csi-16000400.csi2\". Passing\n> > > that entity name to DeviceMatch is too inflexible given it would only\n> > > work if that specific CSI-2 receiver were the one being used.\n> > >\n> > > Add an overload for DeviceMatch::add() such that users can pass in a\n> > > std::regex instead of a string. Update DeviceMatch::match() to check\n> > > for entities that are matched by the regular expressions added with\n> > > the new overload after checking for any exact matches from the vector\n> > > of strings. This allows us to use regex to match on patterns like\n> > > \"csi-[0-9a-f]{8}.csi2\".\n> > >\n> > > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> > > ---\n> > > Changes in v2:\n> > >\n> > >       - Instead of replacing the existing ::add() function and\n> > >       matching process with regex, add an overload for ::add()\n> > >       that takes a regex and incorporate that into ::match()\n> > >       alongside 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(-)\n> > >\n> > > diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> > > index 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> > >       DeviceMatch(const std::string &driver);\n> > >\n> > >       void add(const std::string &entity);\n> > > -\n> > > +     void add(const std::regex &entity);\n> > >       bool match(const MediaDevice *device) const;\n> > >\n> > >   private:\n> > >       std::string driver_;\n> > >       std::vector<std::string> entities_;\n> > > +     std::vector<std::regex> entityRegexs_;\n> > >   };\n> > >\n> > >   class DeviceEnumerator\n> > > diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> > > index 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> > >       entities_.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> > > +     entityRegexs_.push_back(entity);\n> >\n> > void DeviceMatch::add(std::regex entity)\n> > {\n> >      entityRegexs_.push_back(std::move(entity));\n> >\n> >\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> > >                       return false;\n> > >       }\n> > >\n> > > +     for (const std::regex &nameRegex : entityRegexs_) {\n> > > +             bool found = false;\n> > > +\n> > > +             for (const MediaEntity *entity : device->entities()) {\n> > > +                     if (std::regex_search(entity->name(), nameRegex)) {\n> >\n> > Why not `regex_match()`? I feel like maybe the whole name should be matched\n> > by default? I believe it would make sense from a consistency point of view\n> > since `entities_` only allows full matches.\n>\n> I don't know if that is really necessary. DeviceMatch is already\n> limiting on a given driver name. So forcing the match on the full name\n> seems to make the calling code more complicated? And the caller is still\n> free to add ^ and $ to ensure a full match. Or am I missing something\n> here?\n\nI tend to agree with Stefan here.\nI would keep using ::regex_search() here.\n\n(I'm replying as I'm about to resubmit the series, and I wanted to\nmake sure Barnabas knows his comment wasn't ignored)\n\n>\n> Regards,\n> Stefan\n>\n> >\n> >\n> > > +                             if (found) {\n> > > +                                     LOG(DeviceEnumerator, Error)\n> > > +                                             << \"Multiple entities match regex\";\n> >\n> > I suppose another concern could be if multiple regex patterns match the same\n> > entity. Although that is probably the smaller issue out of the two.\n> >\n> >\n> > Regards,\n> > Barnabás Pőcze\n> >\n> >\n> > > +                                     return false;\n> > > +                             }\n> > > +\n> > > +                             if (!entity->deviceNode().empty()) {\n> > > +                                     found = true;\n> > > +                             } else {\n> > > +                                     LOG(DeviceEnumerator, Debug)\n> > > +                                             << \"Skip \" << entity->name()\n> > > +                                             << \": no device node\";\n> > > +                             }\n> > > +                     }\n> > > +             }\n> > > +\n> > > +             if (!found)\n> > > +                     return false;\n> > > +     }\n> > > +\n> > >       return true;\n> > >   }\n> > >\n> >","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 CAA3FC3257\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Dec 2025 16:12:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC61C60D1F;\n\tTue,  2 Dec 2025 17:12:38 +0100 (CET)","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 CB04260C8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Dec 2025 17:12:36 +0100 (CET)","from ideasonboard.com (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5C05B110;\n\tTue,  2 Dec 2025 17:10:22 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"LCPWTOL3\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764691822;\n\tbh=IodMaKJzwCdtva86jkJuf4BfCvgKiwXn/YgthdMvL2w=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LCPWTOL30Tt2BHxcJr4aTYNglrgSUTwFlZySHjE04LZnfu2V4C/xMzXh6qEHEmRWo\n\tyb5ZFsBg4lK2sqaD/JSucnts8hRT+qvbhoHPP2VucZJD7FO2TpQArWJ0ruMo3S3P60\n\ts0yQnuNKyKAzDkHr612xIyM4VJE6qmj1+2Dskwqw=","Date":"Tue, 2 Dec 2025 17:12:33 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>,\n\tDaniel Scally <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","Message-ID":"<o7ab6nknjtserfpy25qv45xfui4l7xugmepurnouvlic3khr5n@bkx22exmup2u>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>\n\t<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>\n\t<175551335151.2014387.7846224393939223576@localhost>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<175551335151.2014387.7846224393939223576@localhost>","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>"}},{"id":37167,"web_url":"https://patchwork.libcamera.org/comment/37167/","msgid":"<7fv25rjgbrobogu7yrlo3c5pzrsfhesbcwuhyy5te7vf6xflfv@dxx5prb7zszo>","date":"2025-12-02T16:17:50","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Barnabás\n\nOn Thu, Jul 17, 2025 at 05:46:28PM +0200, Barnabás Pőcze wrote:\n> Hi\n>\n> 2025. 07. 17. 14:48 keltezéssel, Daniel Scally írta:\n> > Some entities in a media graph have names that might differ from\n> > implementation to implementation; for example the Camera Receiver\n> > Unit and CSI-2 receiver on the KakiP board have entities with names\n> > that include their address, in the form \"csi-16000400.csi2\". Passing\n> > that entity name to DeviceMatch is too inflexible given it would only\n> > work if that specific CSI-2 receiver were the one being used.\n> >\n> > Add an overload for DeviceMatch::add() such that users can pass in a\n> > std::regex instead of a string. Update DeviceMatch::match() to check\n> > for entities that are matched by the regular expressions added with\n> > the new overload after checking for any exact matches from the vector\n> > of strings. This allows us to use regex to match on patterns like\n> > \"csi-[0-9a-f]{8}.csi2\".\n> >\n> > Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> > ---\n> > Changes 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(-)\n> >\n> > diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n> > index 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> > +#include <libcamera/base/regex.h>\n> >   #include <libcamera/base/signal.h>\n> >   namespace libcamera {\n> > @@ -23,12 +24,13 @@ public:\n> >   \tDeviceMatch(const std::string &driver);\n> >   \tvoid add(const std::string &entity);\n> > -\n> > +\tvoid add(const std::regex &entity);\n> >   \tbool match(const MediaDevice *device) const;\n> >   private:\n> >   \tstd::string driver_;\n> >   \tstd::vector<std::string> entities_;\n> > +\tstd::vector<std::regex> entityRegexs_;\n> >   };\n> >   class DeviceEnumerator\n> > diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n> > index 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> > + * \\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> void DeviceMatch::add(std::regex entity)\n> {\n>     entityRegexs_.push_back(std::move(entity));\n\nAren't we here trading one copy at push_back() time for one copy at\nfunction call time ?\n\n>\n>\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> > +\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>\n> Why not `regex_match()`? I feel like maybe the whole name should be matched\n> by default? I believe it would make sense from a consistency point of view\n> since `entities_` only allows full matches.\n>\n>\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>\n> I suppose another concern could be if multiple regex patterns match the same\n> entity. Although that is probably the smaller issue out of the two.\n>\n>\n> Regards,\n> Barnabás Pőcze\n>\n>\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>","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 A075EBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Dec 2025 16:17:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E3C3960C8A;\n\tTue,  2 Dec 2025 17:17:55 +0100 (CET)","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 6EA7260C8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Dec 2025 17:17:54 +0100 (CET)","from ideasonboard.com (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4BA37FE;\n\tTue,  2 Dec 2025 17:15:39 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"gGkJgMAG\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764692140;\n\tbh=wvThGHA8hHWre40ou/9WcYWHMZjGIYvdCNUwRMnk9tQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=gGkJgMAGCFWI2W6qFkzrBLZanKiXxCs3VzEXhr5EJ6r6Z9eq1mgI7nNx2ynFfsGOy\n\tsqGU97B43iD1pgZ3bF14ArGAyDn7B1tUKRY+Ru0KdspdCDpijDu0a0SgWfmaSTGoDS\n\tJHhrBOuukm8f6KPAdGotB1rCBg30rPPAylojH9HY=","Date":"Tue, 2 Dec 2025 17:17:50 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Cc":"Daniel Scally <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","Message-ID":"<7fv25rjgbrobogu7yrlo3c5pzrsfhesbcwuhyy5te7vf6xflfv@dxx5prb7zszo>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>\n\t<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>","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>"}},{"id":37168,"web_url":"https://patchwork.libcamera.org/comment/37168/","msgid":"<1355eea1-0594-4f82-b5ee-89e202a872bc@ideasonboard.com>","date":"2025-12-02T16:27:48","subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 12. 02. 17:17 keltezéssel, Jacopo Mondi írta:\n> Hi Barnabás\n> \n> On Thu, Jul 17, 2025 at 05:46:28PM +0200, Barnabás Pőcze wrote:\n>> Hi\n>>\n>> 2025. 07. 17. 14:48 keltezéssel, Daniel Scally írta:\n>>> Some entities in a media graph have names that might differ from\n>>> implementation to implementation; for example the Camera Receiver\n>>> Unit and CSI-2 receiver on the KakiP board have entities with names\n>>> that include their address, in the form \"csi-16000400.csi2\". Passing\n>>> that entity name to DeviceMatch is too inflexible given it would only\n>>> work if that specific CSI-2 receiver were the one being used.\n>>>\n>>> Add an overload for DeviceMatch::add() such that users can pass in a\n>>> std::regex instead of a string. Update DeviceMatch::match() to check\n>>> for entities that are matched by the regular expressions added with\n>>> the new overload after checking for any exact matches from the vector\n>>> of strings. This allows us to use regex to match on patterns like\n>>> \"csi-[0-9a-f]{8}.csi2\".\n>>>\n>>> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n>>> ---\n>>> Changes 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(-)\n>>>\n>>> diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h\n>>> index 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>>> +#include <libcamera/base/regex.h>\n>>>    #include <libcamera/base/signal.h>\n>>>    namespace libcamera {\n>>> @@ -23,12 +24,13 @@ public:\n>>>    \tDeviceMatch(const std::string &driver);\n>>>    \tvoid add(const std::string &entity);\n>>> -\n>>> +\tvoid add(const std::regex &entity);\n>>>    \tbool match(const MediaDevice *device) const;\n>>>    private:\n>>>    \tstd::string driver_;\n>>>    \tstd::vector<std::string> entities_;\n>>> +\tstd::vector<std::regex> entityRegexs_;\n>>>    };\n>>>    class DeviceEnumerator\n>>> diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp\n>>> index 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>>> + * \\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>> void DeviceMatch::add(std::regex entity)\n>> {\n>>      entityRegexs_.push_back(std::move(entity));\n> \n> Aren't we here trading one copy at push_back() time for one copy at\n> function call time ?\n\nNot necessarily, e.g. (which is probably the most common use case)\n\n   DeviceMatch{}.add(std::regex(\"^hello.*world$\"))\n\nshould do no copies, while with `const std::regex&` it will\ndo one copy.\n\n\n> \n>>\n>>\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>>> +\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>>\n>> Why not `regex_match()`? I feel like maybe the whole name should be matched\n>> by default? I believe it would make sense from a consistency point of view\n>> since `entities_` only allows full matches.\n>>\n>>\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>>\n>> I suppose another concern could be if multiple regex patterns match the same\n>> entity. Although that is probably the smaller issue out of the two.\n>>\n>>\n>> Regards,\n>> Barnabás Pőcze\n>>\n>>\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>>","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 098E0BD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  2 Dec 2025 16:27:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2DC2F60D24;\n\tTue,  2 Dec 2025 17:27:54 +0100 (CET)","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 361FB60C8A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Dec 2025 17:27:52 +0100 (CET)","from [192.168.33.23] (185.182.214.104.nat.pool.zt.hu\n\t[185.182.214.104])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0A401FE;\n\tTue,  2 Dec 2025 17:25:37 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iKH1no5R\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764692738;\n\tbh=p9y+q4hbqEPOWBl05nx/7ehAtL4e5X59o+QMYOaR4AU=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=iKH1no5Rd4sFuBDIY23ZQJTurqeYAFGjvpWz9IROX5QMicgidYAar9V5chps6HJqR\n\tvpS2rOlhIVRaQqWlgBYtMKnDqlayxsxmX38lZpUnEnETM7h1D07TcvQXVTAR8Vz/KB\n\tCVF6pCSrxMd5Yb/+AZ0osYw0yh+YTTZQCVzJiykM=","Message-ID":"<1355eea1-0594-4f82-b5ee-89e202a872bc@ideasonboard.com>","Date":"Tue, 2 Dec 2025 17:27:48 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to\n\tmatch entity names","To":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","Cc":"Daniel Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-3-dan.scally@ideasonboard.com>\n\t<960bc2f4-d6d4-4d0d-a3c1-93da57d6bc75@ideasonboard.com>\n\t<7fv25rjgbrobogu7yrlo3c5pzrsfhesbcwuhyy5te7vf6xflfv@dxx5prb7zszo>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<7fv25rjgbrobogu7yrlo3c5pzrsfhesbcwuhyy5te7vf6xflfv@dxx5prb7zszo>","Content-Type":"text/plain; charset=UTF-8; format=flowed","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>"}}]