From 79ab0e925a782a6781d38237435fcfc29ddd2e20 Mon Sep 17 00:00:00 2001
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Date: Sun, 26 Apr 2020 02:08:37 +0300
Subject: libcamera: v4l2_device: Simplify usage of getControls()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The V4L2Device::getControls() function takes a ControlList that needs to
be pre-populated with dummy entries for the controls that need to be
read. This is a cumbersome API, especially when reading a single
control. Make it nicer by passing the list of V4L2 controls as a vector
of control IDs, and returning a ControlList.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 test/v4l2_videodevice/controls.cpp | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

(limited to 'test/v4l2_videodevice')

diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp
index da9e0111..347af211 100644
--- a/test/v4l2_videodevice/controls.cpp
+++ b/test/v4l2_videodevice/controls.cpp
@@ -57,18 +57,20 @@ protected:
 		const ControlInfo &u8 = infoMap.find(VIVID_CID_U8_4D_ARRAY)->second;
 
 		/* Test getting controls. */
-		ControlList ctrls(infoMap);
-		ctrls.set(V4L2_CID_BRIGHTNESS, -1);
-		ctrls.set(V4L2_CID_CONTRAST, -1);
-		ctrls.set(V4L2_CID_SATURATION, -1);
-		ctrls.set(VIVID_CID_U8_4D_ARRAY, 0);
-
-		int ret = capture_->getControls(&ctrls);
-		if (ret) {
+		ControlList ctrls = capture_->getControls({ V4L2_CID_BRIGHTNESS,
+							    V4L2_CID_CONTRAST,
+							    V4L2_CID_SATURATION,
+							    VIVID_CID_U8_4D_ARRAY });
+		if (ctrls.empty()) {
 			cerr << "Failed to get controls" << endl;
 			return TestFail;
 		}
 
+		if (ctrls.infoMap() != &infoMap) {
+			cerr << "Incorrect infoMap for retrieved controls" << endl;
+			return TestFail;
+		}
+
 		if (ctrls.get(V4L2_CID_BRIGHTNESS).get<int32_t>() == -1 ||
 		    ctrls.get(V4L2_CID_CONTRAST).get<int32_t>() == -1 ||
 		    ctrls.get(V4L2_CID_SATURATION).get<int32_t>() == -1) {
@@ -97,7 +99,7 @@ protected:
 		std::fill(u8Values.begin(), u8Values.end(), u8.min().get<uint8_t>());
 		ctrls.set(VIVID_CID_U8_4D_ARRAY, Span<const uint8_t>(u8Values));
 
-		ret = capture_->setControls(&ctrls);
+		int ret = capture_->setControls(&ctrls);
 		if (ret) {
 			cerr << "Failed to set controls" << endl;
 			return TestFail;
-- 
cgit v1.2.1