[{"id":31815,"web_url":"https://patchwork.libcamera.org/comment/31815/","msgid":"<172937590544.2485972.6517401052839683511@ping.linuxembedded.co.uk>","date":"2024-10-19T22:11:45","subject":"Re: [PATCH v2] py: Add bindings for ControlId array information","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Paul Elder (2024-10-16 12:51:30)\n> Add python bindings for querying whether or not a ControlId is an array\n> type, and the size.\n> \n> Example usage:\n> >>> cid\n> libcamera.ControlId(28, FrameDurationLimits[2], ControlType.Integer64)\n> >>> cid.isArray\n> True\n> >>> cid.size\n> 2\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> Changes in v2:\n> - add size to __repr__\n> ---\n>  src/py/libcamera/py_main.cpp | 17 +++++++++++++++--\n>  1 file changed, 15 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp\n> index 983b76f6e998..cbde8be16d43 100644\n> --- a/src/py/libcamera/py_main.cpp\n> +++ b/src/py/libcamera/py_main.cpp\n> @@ -7,6 +7,7 @@\n>  \n>  #include \"py_main.h\"\n>  \n> +#include <limits>\n>  #include <memory>\n>  #include <stdexcept>\n>  #include <string>\n> @@ -400,10 +401,22 @@ PYBIND11_MODULE(_libcamera, m)\n>                 .def_property_readonly(\"id\", &ControlId::id)\n>                 .def_property_readonly(\"name\", &ControlId::name)\n>                 .def_property_readonly(\"type\", &ControlId::type)\n> +               .def_property_readonly(\"isArray\", &ControlId::isArray)\n> +               .def_property_readonly(\"size\", &ControlId::size)\n>                 .def(\"__str__\", [](const ControlId &self) { return self.name(); })\n>                 .def(\"__repr__\", [](const ControlId &self) {\n> -                       return py::str(\"libcamera.ControlId({}, {}, {})\")\n> -                               .format(self.id(), self.name(), self.type());\n> +                       std::string sizeStr = \"\";\n> +                       if (self.isArray()) {\n> +                               sizeStr = \"[\";\n> +                               size_t size = self.size();\n> +                               if (size == std::numeric_limits<size_t>::max())\n> +                                       sizeStr += \"n\";\n> +                               else\n> +                                       sizeStr += std::to_string(size);\n> +                               sizeStr += \"]\";\n> +                       }\n> +                       return py::str(\"libcamera.ControlId({}, {}{}, {})\")\n> +                               .format(self.id(), self.name(), sizeStr, self.type());\n>                 })\n>                 .def(\"enumerators\", &ControlId::enumerators);\n>  \n> -- \n> 2.39.2\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 E0A5FBD1F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 19 Oct 2024 22:11:51 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8CAFA6538E;\n\tSun, 20 Oct 2024 00:11:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BCBD365382\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 20 Oct 2024 00:11:48 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C6325526;\n\tSun, 20 Oct 2024 00:10:03 +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=\"sXOFTPrw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729375803;\n\tbh=dPD3NTy+ifhyH13j6utAiZLqdxzD2OsE0IKhdCfT1Mk=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=sXOFTPrw9hRJLBwCrWnsMhzgK+q2zkxM/rIJfyGSdtYZad6guDiEBqLIiqGcXe2n6\n\tHLu39vgLn3JMoM5vLgKDtCUDfopx0liQ96DZBFYH1rDMOjgsAw1CNNAz29r+eDGhfV\n\tFHKLcc0qs75PItxVw2BilHKNdq4Vjwf7iEZfiMoo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241016115130.1508308-1-paul.elder@ideasonboard.com>","References":"<20241016115130.1508308-1-paul.elder@ideasonboard.com>","Subject":"Re: [PATCH v2] py: Add bindings for ControlId array information","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Paul Elder <paul.elder@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Sat, 19 Oct 2024 23:11:45 +0100","Message-ID":"<172937590544.2485972.6517401052839683511@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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":31841,"web_url":"https://patchwork.libcamera.org/comment/31841/","msgid":"<20241020213809.GL7770@pendragon.ideasonboard.com>","date":"2024-10-20T21:38:09","subject":"Re: [PATCH v2] py: Add bindings for ControlId array information","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Paul,\n\n(CC'ing Tomi)\n\nThank you for the patch.\n\nOn Wed, Oct 16, 2024 at 08:51:30PM +0900, Paul Elder wrote:\n> Add python bindings for querying whether or not a ControlId is an array\n> type, and the size.\n> \n> Example usage:\n> >>> cid\n> libcamera.ControlId(28, FrameDurationLimits[2], ControlType.Integer64)\n> >>> cid.isArray\n> True\n> >>> cid.size\n> 2\n> \n> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nTomi, could you give this a review too ?\n\nThe patch conflicts with the master branch though, as I've pushed your\nother series. Could you rebase, re-test (and re-run though CI), and push\n?\n\nI think we'll need unit tests for Python bindings soon.\n\n> ---\n> Changes in v2:\n> - add size to __repr__\n> ---\n>  src/py/libcamera/py_main.cpp | 17 +++++++++++++++--\n>  1 file changed, 15 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp\n> index 983b76f6e998..cbde8be16d43 100644\n> --- a/src/py/libcamera/py_main.cpp\n> +++ b/src/py/libcamera/py_main.cpp\n> @@ -7,6 +7,7 @@\n>  \n>  #include \"py_main.h\"\n>  \n> +#include <limits>\n>  #include <memory>\n>  #include <stdexcept>\n>  #include <string>\n> @@ -400,10 +401,22 @@ PYBIND11_MODULE(_libcamera, m)\n>  \t\t.def_property_readonly(\"id\", &ControlId::id)\n>  \t\t.def_property_readonly(\"name\", &ControlId::name)\n>  \t\t.def_property_readonly(\"type\", &ControlId::type)\n> +\t\t.def_property_readonly(\"isArray\", &ControlId::isArray)\n> +\t\t.def_property_readonly(\"size\", &ControlId::size)\n>  \t\t.def(\"__str__\", [](const ControlId &self) { return self.name(); })\n>  \t\t.def(\"__repr__\", [](const ControlId &self) {\n> -\t\t\treturn py::str(\"libcamera.ControlId({}, {}, {})\")\n> -\t\t\t\t.format(self.id(), self.name(), self.type());\n> +\t\t\tstd::string sizeStr = \"\";\n> +\t\t\tif (self.isArray()) {\n> +\t\t\t\tsizeStr = \"[\";\n> +\t\t\t\tsize_t size = self.size();\n> +\t\t\t\tif (size == std::numeric_limits<size_t>::max())\n> +\t\t\t\t\tsizeStr += \"n\";\n> +\t\t\t\telse\n> +\t\t\t\t\tsizeStr += std::to_string(size);\n> +\t\t\t\tsizeStr += \"]\";\n> +\t\t\t}\n> +\t\t\treturn py::str(\"libcamera.ControlId({}, {}{}, {})\")\n> +\t\t\t\t.format(self.id(), self.name(), sizeStr, self.type());\n>  \t\t})\n>  \t\t.def(\"enumerators\", &ControlId::enumerators);\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 5F008C32A3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 20 Oct 2024 21:38:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4BA0265391;\n\tSun, 20 Oct 2024 23:38:16 +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 2AB6965379\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 20 Oct 2024 23:38:15 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6689478E;\n\tSun, 20 Oct 2024 23:36:29 +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=\"IHxsT7o6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729460189;\n\tbh=AfJotsU5P5ozi63Ccg08macNNa/XS7tcpD060C4Hewk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IHxsT7o6m1WT+UHlBQwXAvh+ayK+NsL41Z8E7JqNh/15D+ZOr48A/zoDiEgy7zATs\n\tF5+OaBV2uHk4pkhyDVOYJp69d7RsVKlX/2yfgj+AgVMYyZncFgEFGR4LhjhPdpfOOC\n\tnupwDsM7AgrbP6I37LHR4ZFusMegC6Irvhs97lQo=","Date":"Mon, 21 Oct 2024 00:38:09 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Paul Elder <paul.elder@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tTomi Valkeinen <tomi.valkeinen@ideasonboard.com>","Subject":"Re: [PATCH v2] py: Add bindings for ControlId array information","Message-ID":"<20241020213809.GL7770@pendragon.ideasonboard.com>","References":"<20241016115130.1508308-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20241016115130.1508308-1-paul.elder@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>"}}]