From patchwork Tue May 24 11:46:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16024 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 53183C3277 for ; Tue, 24 May 2022 11:46:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B977656A2; Tue, 24 May 2022 13:46:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1653392815; bh=39AzA7pClZWygLVp4g3PMPKmwcQqv7kWaSnSRhk7ilw=; 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=uDxuoKbSgWSUATOztmckUUkWh+FHuDGbkSPaulGF94lTqZYkDgrDFqzsyrrmzxr00 h/iBHicWYExOgPvT0/DcLCXngzYhcPVZLZE76+wZ5Cq42ENondlE+QqKgfXWLlRN/q YIACvRLJpMmziQv5E9w/+OeUNGmgVejmstsz1Xg2lMGX5sysj1Ys8qDlQYaNtV4i42 +nAzx/Rm3uFlSLz7AyHV7FWtv2+ofi3lzB44rSr3PPQkhHb1X29+ildFIguL8O/mKz R+PWBye4mTnIGakDCA4flubMakUdxhzze1K0MB4Qq0CDTbvlP+UvF3ag8PWzQn/smA Ag7tMpqmHtGLQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F7FA65677 for ; Tue, 24 May 2022 13:46:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QpDIZEJP"; 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 EE6498DC; Tue, 24 May 2022 13:46:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1653392799; bh=39AzA7pClZWygLVp4g3PMPKmwcQqv7kWaSnSRhk7ilw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QpDIZEJPTvobyKRH6bVl3w+ukJK1Ev67BYpRdxh3Gwa6nH+iSHUpw91MQZaWMfsHI SQ6RQ1OgvTJ8kJHYjzvwFDIiKD+ZWWI+N+O8ilCfKBWGU67yO7bybi/Eo1VeFBJnaQ 2O4GYN5ws4j1+jSzOY9PnF23HEVsCZtC8sojyLm0= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Tue, 24 May 2022 14:46:09 +0300 Message-Id: <20220524114610.41848-19-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220524114610.41848-1-tomi.valkeinen@ideasonboard.com> References: <20220524114610.41848-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 18/19] 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 | 27 +++++++++++------ src/py/libcamera/meson.build | 12 ++++++++ .../libcamera/py_properties_generated.cpp.in | 30 +++++++++++++++++++ 3 files changed, 60 insertions(+), 9 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 e3e1e178..a9264777 100755 --- a/src/py/libcamera/gen-py-controls.py +++ b/src/py/libcamera/gen-py-controls.py @@ -21,17 +21,19 @@ def find_common_prefix(strings): return prefix -def generate_py(controls): +def generate_py(controls, prop_mode): out = '' + mode_name = "properties" if prop_mode else "controls" + for ctrl in controls: name, ctrl = ctrl.popitem() if ctrl.get('draft'): - ns = 'libcamera::controls::draft::' + ns = 'libcamera::{}::draft::'.format(mode_name) container = "draft" else: - ns = 'libcamera::controls::' + ns = 'libcamera::{}::'.format(mode_name) container = "controls" cpp_enum = name + 'Enum' @@ -44,12 +46,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 not prop_mode: + # 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 +86,14 @@ def main(argv): help='Input file name.') parser.add_argument('template', type=str, help='Template file name.') + parser.add_argument('--properties', action='store_true', default=False, + help='Generate bindings for properties instead of controls') args = parser.parse_args(argv[1:]) data = open(args.input, 'rb').read() controls = yaml.safe_load(data)['controls'] - data = generate_py(controls) + data = generate_py(controls, prop_mode=args.properties) data = fill_template(args.template, data) diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build index e8010846..e0010353 100644 --- a/src/py/libcamera/meson.build +++ b/src/py/libcamera/meson.build @@ -32,6 +32,18 @@ pycamera_sources += custom_target('py_gen_controls', output : ['py_controls_generated.cpp'], command : [gen_py_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, '--properties', '-o', '@OUTPUT@', '@INPUT@']) + # Generate formats gen_py_formats_input_files = files([ 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} +}