From patchwork Fri Apr 23 02:09:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12088 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C5C13BDB8F for ; Fri, 23 Apr 2021 02:09:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AB74568877; Fri, 23 Apr 2021 04:09:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Xiw0AKSq"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2614568861 for ; Fri, 23 Apr 2021 04:09:42 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B931545F for ; Fri, 23 Apr 2021 04:09:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1619143781; bh=HGOQ6/6vWJ8+ScThuZGR2JWwmRkiuuAFjroHr/hHJr8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Xiw0AKSqLC6OfkY/13jFr67Tr5B/hu9EXg/G8pauetF9EFOukaLhpfo8BWNg8BhtV q8MsPeHdCr1peHmSEnedVBYqyZ+PuLApqv/MqQYHjK1vLRL9NhoK+pq1RHRV2xcItU 5gmQ25bKzwwF81APaDpIGT+Zm+aQ0dBGf2fEo2fk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 23 Apr 2021 05:09:32 +0300 Message-Id: <20210423020932.2760-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.28.1 In-Reply-To: <20210423020932.2760-1-laurent.pinchart@ideasonboard.com> References: <20210423020932.2760-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH/RFC 3/3] v4l2: Replace manual loop counters with utils::enumerate() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the newly introduced utils::enumerate() to replace manual loop counters. A local variable is needed, as utils::enumerate() requires an lvalue reference. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/v4l2/v4l2_compat_manager.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/v4l2/v4l2_compat_manager.cpp b/src/v4l2/v4l2_compat_manager.cpp index 90c0f0121a32..bf5bf8e3223d 100644 --- a/src/v4l2/v4l2_compat_manager.cpp +++ b/src/v4l2/v4l2_compat_manager.cpp @@ -23,6 +23,7 @@ #include #include "libcamera/internal/log.h" +#include "libcamera/internal/utils.h" #include "v4l2_camera_file.h" @@ -81,11 +82,11 @@ int V4L2CompatManager::start() * For each Camera registered in the system, a V4L2CameraProxy gets * created here to wrap a camera device. */ - unsigned int index = 0; - for (auto &camera : cm_->cameras()) { - V4L2CameraProxy *proxy = new V4L2CameraProxy(index, camera); + auto cameras = cm_->cameras(); + for (const auto camera : utils::enumerate(cameras)) { + V4L2CameraProxy *proxy = new V4L2CameraProxy(camera.index, + camera.value); proxies_.emplace_back(proxy); - ++index; } return 0; @@ -117,11 +118,10 @@ int V4L2CompatManager::getCameraIndex(int fd) if (!target) return -1; - unsigned int index = 0; - for (auto &camera : cm_->cameras()) { - if (camera == target) - return index; - ++index; + auto cameras = cm_->cameras(); + for (const auto camera : utils::enumerate(cameras)) { + if (camera.value == target) + return camera.index; } return -1;