From patchwork Wed Jul 7 02:19:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12836 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 8E04CC3226 for ; Wed, 7 Jul 2021 02:20:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 423D66850E; Wed, 7 Jul 2021 04:20:50 +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="PagYm80g"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 453BC684F3 for ; Wed, 7 Jul 2021 04:20:40 +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 48353466 for ; Wed, 7 Jul 2021 04:20:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1625624439; bh=D8wN2nj1ewx9zVjBdW0GnoNDyqWT7j2zLjQvBXBWu8Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PagYm80gNgqudfcZcv0g6QN2VM0zIBu0DMw/A+56pINoXOdlADl6g24KKyQHIcbHB dp88W6Lf1jlwzUtaeuMkkyM3TVJmPXWPHAiqa1/8rhZteNa0cO7rDtV7/055L9kuik HM1l0Zm3UMqyF3+EvSz08bVMc5WnKRAlNfwx9y/E= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Jul 2021 05:19:34 +0300 Message-Id: <20210707021941.20804-24-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> References: <20210707021941.20804-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 23/30] cam: Move camera session creation and monitoring setup to run() 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" Move creationg of the camera session and setup of the hotplug monitoring from the init() function to the run() function, to group all the code that performs operations based on command line options in a single place. The cleanup() call on session creation failure isn't required anymore, as the cleanup() function is called unconditionally open return from run(). This change allows merging two different code blocks related to hotplug monitoring. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/cam/main.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index 03e62f305f24..cba0793ac39b 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -84,26 +84,6 @@ int CamApp::init(int argc, char **argv) return ret; } - if (options_.isSet(OptCamera)) { - session_ = std::make_unique(cm_.get(), options_); - if (!session_->isValid()) { - std::cout << "Failed to create camera session" << std::endl; - cleanup(); - return -EINVAL; - } - - std::cout << "Using camera " << session_->camera()->id() - << std::endl; - - session_->captureDone.connect(this, &CamApp::captureDone); - } - - if (options_.isSet(OptMonitor)) { - cm_->cameraAdded.connect(this, &CamApp::cameraAdded); - cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); - std::cout << "Monitoring new hotplug and unplug events" << std::endl; - } - return 0; } @@ -275,6 +255,19 @@ int CamApp::run() } } + if (options_.isSet(OptCamera)) { + session_ = std::make_unique(cm_.get(), options_); + if (!session_->isValid()) { + std::cout << "Failed to create camera session" << std::endl; + return -EINVAL; + } + + std::cout << "Using camera " << session_->camera()->id() + << std::endl; + + session_->captureDone.connect(this, &CamApp::captureDone); + } + if (options_.isSet(OptListControls)) { ret = listControls(); if (ret) @@ -312,7 +305,12 @@ int CamApp::run() } if (options_.isSet(OptMonitor)) { + std::cout << "Monitoring new hotplug and unplug events" << std::endl; std::cout << "Press Ctrl-C to interrupt" << std::endl; + + cm_->cameraAdded.connect(this, &CamApp::cameraAdded); + cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); + loop_.exec(); }