[libcamera-devel] [PATCH 06/13] libcamera: controls: Allow read only access to control values

Niklas Söderlund niklas.soderlund at ragnatech.se
Wed Aug 28 03:17:03 CEST 2019


Allow the control values in a ControlList to be examined from a const
environment.

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
 include/libcamera/controls.h |  1 +
 src/libcamera/controls.cpp   | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index fbb3a62274c64259..eee5ef87b8fd2633 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -124,6 +124,7 @@ public:
 	void clear() { controls_.clear(); }
 
 	ControlValue &operator[](ControlId id);
+	const ControlValue &operator[](ControlId id) const;
 	ControlValue &operator[](const ControlInfo *info) { return controls_[info]; }
 
 	void update(const ControlList &list);
diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp
index 54efef1bb337e945..424fe515fa69f8d8 100644
--- a/src/libcamera/controls.cpp
+++ b/src/libcamera/controls.cpp
@@ -517,6 +517,40 @@ ControlValue &ControlList::operator[](ControlId id)
 	return controls_[&iter->second];
 }
 
+/**
+ * \brief Access a control specified by \a id
+ * \param[in] id The control ID
+ *
+ * This method returns a reference to the control identified by \a id, if it
+ * exsists or an empty control if it does not.
+ *
+ * The behaviour is undefined if the control \a id is not supported by the
+ * camera that the ControlList refers to.
+ *
+ * \return A reference to the value of the control identified by \a id
+ */
+const ControlValue &ControlList::operator[](ControlId id) const
+{
+	const ControlInfoMap &controls = camera_->controls();
+	static ControlValue empty;
+
+	const auto iter = controls.find(id);
+	if (iter == controls.end()) {
+		LOG(Controls, Error)
+			<< "Camera " << camera_->name()
+			<< " does not support control " << id;
+		return empty;
+	}
+
+	const auto it = controls_.find(&iter->second);
+	if (it == controls_.end()) {
+		LOG(Controls, Error) << "list does not have control " << id;
+		return empty;
+	}
+
+	return it->second;
+}
+
 /**
  * \fn ControlList::operator[](const ControlInfo *info)
  * \brief Access or insert the control specified by \a info
-- 
2.22.1



More information about the libcamera-devel mailing list