From patchwork Fri May 27 14:44:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16087 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id BD12EC326D for ; Fri, 27 May 2022 14:45:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4F19F65636; Fri, 27 May 2022 16:45:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653662728; bh=6RKw8LfMXsi6/Us3IdxwjAaG3NpSyQzKwfTXix2+MuA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=uuGpUQpYZV4dNBX72JJisO5TwHye6E1XiZQ3EKH5niOD5B5tTCdeOQ50bXH/4S8Yo PJXVTF/bEAjWlDP+kOavobmBD3rfomhFB97VAad/0TZjf99cgqL/mT0us+lJP/FuBu b5TXmhaghcp6WBuu0REBwgeajzaFppLEtJpS2olRHctAv32wAuP/VWlWC+6ndDAlvn CKuR9BlkNPTT7KKDB1M6JNm0Kv9wK8SdsFoTPU7tHq6iUYscGm4gRe6V80AYdcI+Si /1Xitruc6+4kFi+QoO/BdsQwjFK7/MxpplyUY7wYKzxvhf+GhroQvNKVzCBR0/AHg7 cvn8IlDWkWNkg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B8F3633A6 for ; Fri, 27 May 2022 16:45:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cPuMpdnO"; dkim-atps=neutral Received: from deskari.lan (91-156-85-209.elisa-laajakaista.fi [91.156.85.209]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A916E1C26; Fri, 27 May 2022 16:45:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653662712; bh=6RKw8LfMXsi6/Us3IdxwjAaG3NpSyQzKwfTXix2+MuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cPuMpdnOn6GBWA+Wvu/2aSKB9gBwfTksm8/1Y9uz93e7WAWUg4btwzQsmuRFvNWMU qxqpADdm7xMtiRXgbrOdic2rPVsxB4zUuSWDgjn86w1T2+iU32+BUveqGVZHK5sL2p QnKmWrmA5zs+mAGt+0KqK15WGn0Z8CtHwB6z3qIQ= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 27 May 2022 17:44:32 +0300 Message-Id: <20220527144447.94891-16-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> References: <20220527144447.94891-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 15/30] py: Generate bindings for properties X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Generate bindings for properties in a very similar way as done for controls. We do need to distinguish between the two, and thus I added --properties flag to gen-py-controls.py. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- src/py/libcamera/gen-py-controls.py | 29 ++++++++++++------ src/py/libcamera/meson.build | 14 ++++++++- src/py/libcamera/py_main.cpp | 2 ++ .../libcamera/py_properties_generated.cpp.in | 30 +++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/py/libcamera/py_properties_generated.cpp.in diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py index 4c072e60..99f3bbcf 100755 --- a/src/py/libcamera/gen-py-controls.py +++ b/src/py/libcamera/gen-py-controls.py @@ -21,17 +21,17 @@ def find_common_prefix(strings): return prefix -def generate_py(controls): +def generate_py(controls, mode): out = '' for ctrl in controls: name, ctrl = ctrl.popitem() if ctrl.get('draft'): - ns = 'libcamera::controls::draft::' + ns = 'libcamera::{}::draft::'.format(mode) container = 'draft' else: - ns = 'libcamera::controls::' + ns = 'libcamera::{}::'.format(mode) container = 'controls' out += f'\t{container}.def_readonly_static("{name}", static_cast(&{ns}{name}));\n\n' @@ -44,12 +44,17 @@ def generate_py(controls): out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum) - if name == 'LensShadingMapMode': - prefix = 'LensShadingMapMode' - elif name == 'SceneFlicker': - # If we strip the prefix, we would get '50Hz', which is illegal name - prefix = '' + if mode == 'controls': + # Adjustments for controls + if name == 'LensShadingMapMode': + prefix = 'LensShadingMapMode' + elif name == 'SceneFlicker': + # If we strip the prefix, we would get '50Hz', which is illegal name + prefix = '' + else: + prefix = find_common_prefix([e['name'] for e in enum]) else: + # Adjustments for properties prefix = find_common_prefix([e['name'] for e in enum]) for entry in enum: @@ -79,12 +84,18 @@ def main(argv): help='Input file name.') parser.add_argument('template', type=str, help='Template file name.') + parser.add_argument('--mode', type=str, required=True, + help='Mode is either "controls" or "properties"') args = parser.parse_args(argv[1:]) + if args.mode not in ['controls', 'properties']: + print(f'Invalid mode option "{args.mode}"', file=sys.stderr) + return -1 + data = open(args.input, 'rb').read() controls = yaml.safe_load(data)['controls'] - data = generate_py(controls) + data = generate_py(controls, args.mode) data = fill_template(args.template, data) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index e8010846..afa7efed 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -30,7 +30,19 @@ gen_py_controls = files('gen-py-controls.py') pycamera_sources += custom_target('py_gen_controls', input : gen_py_controls_input_files, output : ['py_controls_generated.cpp'], - command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@']) + command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@', '@INPUT@']) + +# Generate properties + +gen_py_property_enums_input_files = files([ + '../../libcamera/property_ids.yaml', + 'py_properties_generated.cpp.in', +]) + +pycamera_sources += custom_target('py_gen_properties', + input : gen_py_property_enums_input_files, + output : ['py_properties_generated.cpp'], + command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@', '@INPUT@']) # Generate formats diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index f903f1d2..3220a9e6 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -130,12 +130,14 @@ void init_py_enums(py::module &m); void init_py_controls_generated(py::module &m); void init_py_formats_generated(py::module &m); void init_py_geometry(py::module &m); +void init_py_properties_generated(py::module &m); PYBIND11_MODULE(_libcamera, m) { init_py_enums(m); init_py_controls_generated(m); init_py_geometry(m); + init_py_properties_generated(m); /* Forward declarations */ diff --git a/src/py/libcamera/py_properties_generated.cpp.in b/src/py/libcamera/py_properties_generated.cpp.in new file mode 100644 index 00000000..044b2b2a --- /dev/null +++ b/src/py/libcamera/py_properties_generated.cpp.in @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2022, Tomi Valkeinen + * + * Python bindings - Auto-generated properties + * + * This file is auto-generated. Do not edit. + */ + +#include + +#include + +namespace py = pybind11; + +class PyProperties +{ +}; + +class PyDraftProperties +{ +}; + +void init_py_properties_generated(py::module& m) +{ + auto controls = py::class_(m, "properties"); + auto draft = py::class_(controls, "draft"); + +${controls} +}