From patchwork Fri Jul 31 19:46:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 9123 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 142F4BD878 for ; Fri, 31 Jul 2020 19:46:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 766A961E8B; Fri, 31 Jul 2020 21:46:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=uajain.com header.i=@uajain.com header.b="NsoQ9EiG"; dkim-atps=neutral Received: from o1.f.az.sendgrid.net (o1.f.az.sendgrid.net [208.117.55.132]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC029611A2 for ; Fri, 31 Jul 2020 21:46:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uajain.com; h=from:subject:mime-version:to:cc:content-type: content-transfer-encoding; s=s1; bh=yvokil5JMWjhCDA/UoZOaIQ2nDAUU3vwbkumgkxVc8A=; b=NsoQ9EiGbcOOzs0IZuV2NHz6st1oZIdI/nTJZPRK6tIkV6fdhAjLlEdIHBMsFWQjqYFP OIoWnhUnp6qKfmtb9nMSWCTQ+ms4pOdzFSNgYom8D7KDpICBsGt5TcOiqIGXKWvJfIUcnl 44kUxAyNLHrzENgt0dIrwwlq/Mb46oGtg= Received: by filterdrecv-p3iad2-d8cc6d457-6kjsg with SMTP id filterdrecv-p3iad2-d8cc6d457-6kjsg-18-5F24752D-76 2020-07-31 19:46:54.015259055 +0000 UTC m=+178710.827017285 Received: from mail.uajain.com (unknown) by ismtpd0001p1hnd1.sendgrid.net (SG) with ESMTP id EEz3QcFnSDew5BiOZLGEFg Fri, 31 Jul 2020 19:46:53.367 +0000 (UTC) From: Umang Jain Date: Fri, 31 Jul 2020 19:46:54 +0000 (UTC) Message-Id: <20200731194649.110184-1-email@uajain.com> Mime-Version: 1.0 X-SG-EID: 1Q40EQ7YGir8a9gjSIAdTjhngY657NMk9ckeo4dbHZDiOpywc/L3L9rFqlwE4KPcsqq2IL5HKct149ShwfIDnryxvi6TwoaNxnnGGh0Ir4dFzyc925uQU1fUnW8T0XHpD3STBjTz1p7Xw15mUg5P9kyV+/ogvYsGfq1k2kZ//t90BaxMEbAKSKTibkiTiPI0Czdk5lHej1PwgE/c1kmA9H7sYDbqJx+eqX+6uIqEGUsuEk6Iq5Lfd/WZiOYYFKAqkDOCwgikfbu2cEx4ONptmg== To: libcamera-devel@lists.libcamera.org Subject: [libcamera-devel] [PATCH v2] cam: Add --monitor option 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" Add --monitor to monitor new hotplug and unplug camera events from the CameraManager. Signed-off-by: Umang Jain Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/cam/main.cpp | 26 ++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/cam/main.cpp b/src/cam/main.cpp index f5aba04..b03437e 100644 --- a/src/cam/main.cpp +++ b/src/cam/main.cpp @@ -36,6 +36,8 @@ public: void quit(); private: + void cameraAdded(std::shared_ptr cam); + void cameraRemoved(std::shared_ptr cam); int parseOptions(int argc, char *argv[]); int prepareConfig(); int listControls(); @@ -121,6 +123,10 @@ int CamApp::init(int argc, char **argv) ret = prepareConfig(); if (ret) return ret; + } else if (options_.isSet(OptMonitor)) { + cm_->cameraAdded.connect(this, &CamApp::cameraAdded); + cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); + std::cout << "Monitoring new hotplug or unplug camera events…" << std::endl; } loop_ = new EventLoop(cm_->eventDispatcher()); @@ -189,6 +195,8 @@ int CamApp::parseOptions(int argc, char *argv[]) parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats"); + parser.addOption(OptMonitor, OptionNone, "Monitor for hotplug and unplug camera events", + "monitor"); options_ = parser.parse(argc, argv); if (!options_.valid()) @@ -309,6 +317,16 @@ int CamApp::infoConfiguration() return 0; } +void CamApp::cameraAdded(std::shared_ptr cam) +{ + std::cout << "Camera Added: " << cam->name() << std::endl; +} + +void CamApp::cameraRemoved(std::shared_ptr cam) +{ + std::cout << "Camera Removed: " << cam->name() << std::endl; +} + int CamApp::run() { int ret; @@ -342,10 +360,18 @@ int CamApp::run() } if (options_.isSet(OptCapture)) { + cm_->cameraAdded.connect(this, &CamApp::cameraAdded); + cm_->cameraRemoved.connect(this, &CamApp::cameraRemoved); Capture capture(camera_, config_.get(), loop_); return capture.run(options_); } + if (options_.isSet(OptMonitor)) { + ret = loop_->exec(); + if (ret) + std::cout << "Failed to run monitor loop" << std::endl; + } + return 0; } diff --git a/src/cam/main.h b/src/cam/main.h index 6f95add..ea8dfd3 100644 --- a/src/cam/main.h +++ b/src/cam/main.h @@ -15,6 +15,7 @@ enum { OptInfo = 'I', OptList = 'l', OptListProperties = 'p', + OptMonitor = 'm', OptStream = 's', OptListControls = 256, OptStrictFormats = 257,