diff options
author | Umang Jain <email@uajain.com> | 2020-07-13 12:11:28 +0000 |
---|---|---|
committer | Kieran Bingham <kieran.bingham@ideasonboard.com> | 2020-08-03 14:19:13 +0100 |
commit | 70b65c659040fa5dcc7ebaeb048ce8b1e02677f7 (patch) | |
tree | 88f31f173f5ad0d13173a054fc893f9804146861 /src/cam | |
parent | 785d7418619454c26631e5c1ac516abbc4f33f35 (diff) |
cam: Add --monitor option
Add --monitor to monitor new hotplug and unplug camera events from
the CameraManager.
Signed-off-by: Umang Jain <email@uajain.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/cam')
-rw-r--r-- | src/cam/main.cpp | 28 | ||||
-rw-r--r-- | src/cam/main.h | 1 |
2 files changed, 29 insertions, 0 deletions
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<Camera> cam); + void cameraRemoved(std::shared_ptr<Camera> 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<Camera> cam) +{ + std::cout << "Camera Added: " << cam->name() << std::endl; +} + +void CamApp::cameraRemoved(std::shared_ptr<Camera> 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, |