[libcamera-devel] [PATCH 2/9] libcamera: controls: Support getting and setting controls by ControlId
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Oct 8 00:46:35 CEST 2019
The ControlList class has template get() and set() methods to get and
set control values. The methods require a reference to a Control
instance, which is only available when calling them with a hardcoded
control. In order to support serialisation and deserialisation of
ControlList, we need a way to get and set control values based on a
ControlId. Add new get() and set() overload methods to do so.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
include/libcamera/controls.h | 3 +++
src/libcamera/controls.cpp | 46 ++++++++++++++++++++++++++++++++++--
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 90426753f40f..49ff1a6f747f 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -156,6 +156,9 @@ public:
val->set<T>(value);
}
+ const ControlValue &get(const ControlId &id) const;
+ void set(const ControlId &id, const ControlValue &value);
+
private:
const ControlValue *find(const ControlId &id) const;
ControlValue *find(const ControlId &id);
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index f3260edce0bc..f862a09adef9 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -445,7 +445,7 @@ bool ControlList::contains(const ControlId &id) const
*/
/**
- * \fn template<typename T> const T &ControlList::get() const
+ * \fn template<typename T> const T &ControlList::get(const Control<T> &ctrl) const
* \brief Get the value of a control
* \param[in] ctrl The control
*
@@ -460,7 +460,7 @@ bool ControlList::contains(const ControlId &id) const
*/
/**
- * \fn template<typename T> void ControlList::set()
+ * \fn template<typename T> void ControlList::set(const Control< T > &ctrl, const T &value)
* \brief Set the control value to \a value
* \param[in] ctrl The control
* \param[in] value The control value
@@ -473,6 +473,48 @@ bool ControlList::contains(const ControlId &id) const
* camera that the list refers to.
*/
+/**
+ * \brief Get the value of control \a id
+ * \param[in] id The control ID
+ *
+ * The behaviour is undefined if the control \a id is not present in the list.
+ * Use ControlList::contains() to test for the presence of a control in the
+ * list before retrieving its value.
+ *
+ * \return The control value
+ */
+const ControlValue &ControlList::get(const ControlId &id) const
+{
+ const ControlValue *val = find(id);
+ if (!val) {
+ static ControlValue zero;
+ return zero;
+ }
+
+ return *val;
+}
+
+/**
+ * \brief Set the value of control \a id to \a value
+ * \param[in] id The control ID
+ * \param[in] value The control value
+ *
+ * This method sets the value of a control in the control list. If the control
+ * is already present in the list, its value is updated, otherwise it is added
+ * to the list.
+ *
+ * The behaviour is undefined if the control \a ctrl is not supported by the
+ * camera that the list refers to.
+ */
+void ControlList::set(const ControlId &id, const ControlValue &value)
+{
+ ControlValue *val = find(id);
+ if (!val)
+ return;
+
+ *val = value;
+}
+
const ControlValue *ControlList::find(const ControlId &id) const
{
const auto iter = controls_.find(&id);
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list