Jinja2 templates help separate the logic related to the template from the generation of the data. The python code becomes much clearer as a result. As an added bonus, we can use a single template file for both controls and properties. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Acked-by: Paul Elder <paul.elder@ideasonboard.com>
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
|
|
*
|
|
* Python bindings - Auto-generated {{mode}}
|
|
*
|
|
* This file is auto-generated. Do not edit.
|
|
*/
|
|
|
|
#include <libcamera/{{header}}>
|
|
|
|
#include <pybind11/pybind11.h>
|
|
|
|
#include "py_main.h"
|
|
|
|
namespace py = pybind11;
|
|
|
|
class Py{{mode|capitalize}}
|
|
{
|
|
};
|
|
|
|
{% for vendor in vendors -%}
|
|
class Py{{vendor|capitalize}}{{mode|capitalize}}
|
|
{
|
|
};
|
|
|
|
{% endfor -%}
|
|
|
|
void init_py_{{mode}}_generated(py::module& m)
|
|
{
|
|
auto {{mode}} = py::class_<Py{{mode|capitalize}}>(m, "{{mode}}");
|
|
{%- for vendor in vendors %}
|
|
auto {{vendor}} = py::class_<Py{{vendor|capitalize}}{{mode|capitalize}}>({{mode}}, "{{vendor}}");
|
|
{%- endfor %}
|
|
|
|
{% for ctrl in controls %}
|
|
{{ctrl.klass}}.def_readonly_static("{{ctrl.name}}", static_cast<const libcamera::ControlId *>(&libcamera::{{mode}}::{{ctrl.namespace}}{{ctrl.name}}));
|
|
{%- if ctrl.is_enum %}
|
|
|
|
py::enum_<libcamera::{{mode}}::{{ctrl.namespace}}{{ctrl.name}}Enum>({{ctrl.klass}}, "{{ctrl.name}}Enum")
|
|
{%- for enum in ctrl.enum_values %}
|
|
.value("{{enum.py_name}}", libcamera::{{mode}}::{{ctrl.namespace}}{{enum.name}})
|
|
{%- endfor %}
|
|
;
|
|
{%- endif %}
|
|
{% endfor -%}
|
|
}
|