From patchwork Thu Jul 15 21:14:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12998 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 CFE37C322C for ; Thu, 15 Jul 2021 21:15:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5CD226853A; Thu, 15 Jul 2021 23:15:31 +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="TUj4uxfp"; 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 72CAA68550 for ; Thu, 15 Jul 2021 23:15:13 +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 096CE56B for ; Thu, 15 Jul 2021 23:15:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626383713; bh=axJWEf8Y922RXJb0H+KNMyUQkg0I2E+veG4L1mqU0xY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TUj4uxfp7b+HvIvdODfDl6fm3P24R5F1A76ZGj5P1yhGZyPmLwXGwlHvMi2EuGPC3 CaCdrPqdQhamiuDAw/mynX6IODVVyfWGh3kDMIXrKDjQGi0CHxhzMOj+2WAf6R/Izw vRZQnOyTNmrJ66W3kkmP2oqifVDNpVwp651QdF/c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 16 Jul 2021 00:14:52 +0300 Message-Id: <20210715211459.19373-27-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> References: <20210715211459.19373-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 26/33] 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 creation 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 upon 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(); }