[libcamera-devel] [PATCH] cam: Add --monitor option
Umang Jain
email at uajain.com
Mon Jul 13 14:11:28 CEST 2020
Add --monitor to monitor new hotplug and unplug camera events from
the CameraManager.
Signed-off-by: Umang Jain <email at uajain.com>
---
src/cam/main.cpp | 24 ++++++++++++++++++++++++
src/cam/main.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 2512fe9..3488315 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();
@@ -115,6 +117,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 and unplug events..." << std::endl;
}
loop_ = new EventLoop(cm_->eventDispatcher());
@@ -179,6 +185,8 @@ 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");
options_ = parser.parse(argc, argv);
if (!options_.valid())
@@ -293,6 +301,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;
@@ -330,6 +348,12 @@ int CamApp::run()
return capture.run(loop_, 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 4a130d8..f61d288 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,
};
--
2.26.2
More information about the libcamera-devel
mailing list