Message ID | 20190927024417.725906-4-niklas.soderlund@ragnatech.se |
---|---|
State | Superseded |
Headers | show |
Series |
|
Related | show |
Hi Niklas, Thank you for the patch. On Fri, Sep 27, 2019 at 04:44:07AM +0200, Niklas Söderlund wrote: > Allow the control values in a ControlList to be examined from a const > environment. I think this patch and the next one can be dropped if you rebase on top of the control rework series I've just sent. > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> > --- > include/libcamera/controls.h | 1 + > src/libcamera/controls.cpp | 35 +++++++++++++++++++++++++++++++++++ > 2 files changed, 36 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 44cb09d9102d93f6..6271a0bd7518dda5 100644 > --- a/src/libcamera/controls.cpp > +++ b/src/libcamera/controls.cpp > @@ -523,6 +523,41 @@ ControlValue &ControlList::operator[](ControlId id) > return controls_[&iter->second]; > } > > +/** > + * \brief Access the control specified by \a id > + * \param[in] id The control ID > + * > + * This method returns a const reference to the control identified by \a id. If > + * no such controls is present in the list, a const reference to an empty > + * control value is returned. > + * > + * The behaviour is undefined if the control \a id is not supported by the > + * camera that the ControlList refers to. > + * > + * \return A const 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 camctrl = controls.find(id); > + if (camctrl == controls.end()) { > + LOG(Controls, Error) > + << "Camera " << camera_->name() > + << " does not support control " << id; > + return empty; > + } > + > + const auto ctrl = controls_.find(&camctrl->second); > + if (ctrl == controls_.end()) { > + LOG(Controls, Error) << "list does not have control " << id; > + return empty; > + } > + > + return ctrl->second; > +} > + > /** > * \fn ControlList::operator[](const ControlInfo *info) > * \brief Access or insert the control specified by \a info
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 44cb09d9102d93f6..6271a0bd7518dda5 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -523,6 +523,41 @@ ControlValue &ControlList::operator[](ControlId id) return controls_[&iter->second]; } +/** + * \brief Access the control specified by \a id + * \param[in] id The control ID + * + * This method returns a const reference to the control identified by \a id. If + * no such controls is present in the list, a const reference to an empty + * control value is returned. + * + * The behaviour is undefined if the control \a id is not supported by the + * camera that the ControlList refers to. + * + * \return A const 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 camctrl = controls.find(id); + if (camctrl == controls.end()) { + LOG(Controls, Error) + << "Camera " << camera_->name() + << " does not support control " << id; + return empty; + } + + const auto ctrl = controls_.find(&camctrl->second); + if (ctrl == controls_.end()) { + LOG(Controls, Error) << "list does not have control " << id; + return empty; + } + + return ctrl->second; +} + /** * \fn ControlList::operator[](const ControlInfo *info) * \brief Access or insert the control specified by \a info
Allow the control values in a ControlList to be examined from a const environment. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> --- include/libcamera/controls.h | 1 + src/libcamera/controls.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)