From 70b65c659040fa5dcc7ebaeb048ce8b1e02677f7 Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Mon, 13 Jul 2020 12:11:28 +0000 Subject: cam: Add --monitor option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- src/cam/main.cpp | 28 ++++++++++++++++++++++++++++ src/cam/main.h | 1 + 2 files changed, 29 insertions(+) (limited to 'src') diff --git a/src/cam/main.cpp b/src/cam/main.cpp index f5aba041..ec59e9ea 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(); @@ -123,6 +125,12 @@ int CamApp::init(int argc, char **argv) return ret; } + 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; + } + loop_ = new EventLoop(cm_->eventDispatcher()); return 0; @@ -186,6 +194,9 @@ int CamApp::parseOptions(int argc, char *argv[]) "list-controls"); parser.addOption(OptListProperties, OptionNone, "List cameras properties", "list-properties"); + parser.addOption(OptMonitor, OptionNone, + "Monitor for hotplug and unplug camera events", + "monitor"); parser.addOption(OptStrictFormats, OptionNone, "Do not allow requested stream format(s) to be adjusted", "strict-formats"); @@ -309,6 +320,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; @@ -346,6 +367,13 @@ int CamApp::run() return capture.run(options_); } + if (options_.isSet(OptMonitor)) { + std::cout << "Press Ctrl-C to interrupt" << std::endl; + 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 6f95add3..ea8dfd33 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, -- cgit v1.2.1