[libcamera-devel,v3,2/2] libcamera: control: initialise control info to ControlTypeNone by default
diff mbox series

Message ID 20220902224939.111640-2-Rauch.Christian@gmx.de
State Superseded
Headers show
Series
  • [libcamera-devel,v3,1/2] libcamera: serialiser: store/load all ControlValue types
Related show

Commit Message

Christian Rauch Sept. 2, 2022, 10:49 p.m. UTC
The default ControlInfo constructor allows to partially initialised the
min/max/def values. Uninitialised values are assigned to 0 by default. This
implicit initialisation makes it impossible to distinguish between and
uninitialised and an explicitly 0-initialised ControlValue.

Default construct the ControlValue in the ControlInfo default contructor to
explicitly represent uninitialised values by the ControlTypeNone type.

Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>
---
 include/libcamera/controls.h   | 6 +++---
 test/controls/control_info.cpp | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

--
2.34.1

Comments

Nicolas Dufresne via libcamera-devel Sept. 3, 2022, 12:52 a.m. UTC | #1
On Sat, Sep 03, 2022 at 12:49:39AM +0200, Christian Rauch via libcamera-devel wrote:
> The default ControlInfo constructor allows to partially initialised the

s/to partially initialised/partially initialising/

> min/max/def values. Uninitialised values are assigned to 0 by default. This
> implicit initialisation makes it impossible to distinguish between and

s/and/an/

> uninitialised and an explicitly 0-initialised ControlValue.
> 
> Default construct the ControlValue in the ControlInfo default contructor to
> explicitly represent uninitialised values by the ControlTypeNone type.
> 
> Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  include/libcamera/controls.h   | 6 +++---
>  test/controls/control_info.cpp | 4 ++--
>  2 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
> index ebc168fc..38d0a3e8 100644
> --- a/include/libcamera/controls.h
> +++ b/include/libcamera/controls.h
> @@ -268,9 +268,9 @@ private:
>  class ControlInfo
>  {
>  public:
> -	explicit ControlInfo(const ControlValue &min = 0,
> -			     const ControlValue &max = 0,
> -			     const ControlValue &def = 0);
> +	explicit ControlInfo(const ControlValue &min = {},
> +			     const ControlValue &max = {},
> +			     const ControlValue &def = {});
>  	explicit ControlInfo(Span<const ControlValue> values,
>  			     const ControlValue &def = {});
>  	explicit ControlInfo(std::set<bool> values, bool def);
> diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp
> index 2827473b..56b4101f 100644
> --- a/test/controls/control_info.cpp
> +++ b/test/controls/control_info.cpp
> @@ -26,8 +26,8 @@ protected:
>  		 */
>  		ControlInfo brightness;
> 
> -		if (brightness.min().get<int32_t>() != 0 ||
> -		    brightness.max().get<int32_t>() != 0) {
> +		if (brightness.min().type() != ControlType::ControlTypeNone ||
> +		    brightness.max().type() != ControlType::ControlTypeNone) {
>  			cout << "Invalid control range for Brightness" << endl;
>  			return TestFail;
>  		}
> --
> 2.34.1
>

Patch
diff mbox series

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index ebc168fc..38d0a3e8 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -268,9 +268,9 @@  private:
 class ControlInfo
 {
 public:
-	explicit ControlInfo(const ControlValue &min = 0,
-			     const ControlValue &max = 0,
-			     const ControlValue &def = 0);
+	explicit ControlInfo(const ControlValue &min = {},
+			     const ControlValue &max = {},
+			     const ControlValue &def = {});
 	explicit ControlInfo(Span<const ControlValue> values,
 			     const ControlValue &def = {});
 	explicit ControlInfo(std::set<bool> values, bool def);
diff --git a/test/controls/control_info.cpp b/test/controls/control_info.cpp
index 2827473b..56b4101f 100644
--- a/test/controls/control_info.cpp
+++ b/test/controls/control_info.cpp
@@ -26,8 +26,8 @@  protected:
 		 */
 		ControlInfo brightness;

-		if (brightness.min().get<int32_t>() != 0 ||
-		    brightness.max().get<int32_t>() != 0) {
+		if (brightness.min().type() != ControlType::ControlTypeNone ||
+		    brightness.max().type() != ControlType::ControlTypeNone) {
 			cout << "Invalid control range for Brightness" << endl;
 			return TestFail;
 		}