[libcamera-devel] [PATCH 1/9] libcamera: control_ids: Generate map of all supported controls
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Oct 8 00:46:34 CEST 2019
In order to deserialise a ControlList, we will need to lookup ControlId
instances based on their numerical ID. Generate a global map from the
controls definitions to support such a lookup.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
include/libcamera/control_ids.h.in | 3 +++
src/libcamera/control_ids.cpp.in | 7 +++++++
src/libcamera/gen-controls.py | 7 ++++++-
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in
index 1d0bc791e559..30b2bae8a9ae 100644
--- a/include/libcamera/control_ids.h.in
+++ b/include/libcamera/control_ids.h.in
@@ -10,6 +10,7 @@
#ifndef __LIBCAMERA_CONTROL_IDS_H__
#define __LIBCAMERA_CONTROL_IDS_H__
+#include <map>
#include <stdint.h>
#include <libcamera/controls.h>
@@ -24,6 +25,8 @@ ${ids}
${controls}
+extern const std::map<unsigned int, const ControlId *> controls;
+
} /* namespace controls */
} /* namespace libcamera */
diff --git a/src/libcamera/control_ids.cpp.in b/src/libcamera/control_ids.cpp.in
index f699ac9eea54..f0656d3147b1 100644
--- a/src/libcamera/control_ids.cpp.in
+++ b/src/libcamera/control_ids.cpp.in
@@ -20,6 +20,13 @@ namespace controls {
${controls}
+/**
+ * \brief List of all supported libcamera controls
+ */
+extern const std::map<unsigned int, const ControlId *> controls {
+${controls_map}
+};
+
} /* namespace controls */
} /* namespace libcamera */
diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
index 0899e40b4080..0c4bd79eee5b 100755
--- a/src/libcamera/gen-controls.py
+++ b/src/libcamera/gen-controls.py
@@ -23,6 +23,7 @@ ${description}
extern const Control<${type}> ${name}(${id_name}, "${name}");''')
ctrls = []
+ ctrls_map = []
for ctrl in controls:
name, ctrl = ctrl.popitem()
@@ -40,8 +41,12 @@ extern const Control<${type}> ${name}(${id_name}, "${name}");''')
}
ctrls.append(template.substitute(info))
+ ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },')
- return {'controls': '\n\n'.join(ctrls)}
+ return {
+ 'controls': '\n\n'.join(ctrls),
+ 'controls_map': '\n'.join(ctrls_map),
+ }
def generate_h(controls):
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list