From patchwork Mon Jul 12 21:56:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 12936 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 4B0FDC3226 for ; Mon, 12 Jul 2021 21:57:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E15A268521; Mon, 12 Jul 2021 23:57:56 +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="ADx5p1oa"; 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 8E34668513 for ; Mon, 12 Jul 2021 23:57:43 +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 2A392CC for ; Mon, 12 Jul 2021 23:57:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1626127063; bh=axJWEf8Y922RXJb0H+KNMyUQkg0I2E+veG4L1mqU0xY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ADx5p1oadgAGwS80xE8E5u6o3YpHDOKnKXb3BnzYZqJ1WQQyDo6ya2+U651HLckXj jKC8Q1VojQkJ96uq/arRqK90XdFYRxxcRrJLo6TPTVeeThFWtLSX7ROSRpjIiI+MrI VomqxOO/g57DKUKK+ymUnDhl9T+9rz2HNf4HtHPY= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Jul 2021 00:56:38 +0300 Message-Id: <20210712215645.30478-24-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> References: <20210712215645.30478-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 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(); }