summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-24 01:55:17 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-24 22:24:15 +0200
commit889726097613ae5ed4d83a6fd0cc3b0b562f8659 (patch)
treef8478c93c38ee0e0d6c0f724e2beec75bab7d976
parent124aaffde0b25d847442876beb16600d448d9feb (diff)
libcamera: camera_manager: Add method to unregister a camera
The new removeCamera() method is meant to be used by pipeline handlers to unregister a camera in case of device disconnection. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
-rw-r--r--include/libcamera/camera_manager.h1
-rw-r--r--src/libcamera/camera_manager.cpp21
2 files changed, 22 insertions, 0 deletions
diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
index 45e72df0..56dbd26f 100644
--- a/include/libcamera/camera_manager.h
+++ b/include/libcamera/camera_manager.h
@@ -28,6 +28,7 @@ public:
std::shared_ptr<Camera> get(const std::string &name);
void addCamera(std::shared_ptr<Camera> camera);
+ void removeCamera(Camera *camera);
static CameraManager *instance();
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index 3eccf20c..f90201ad 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -192,6 +192,27 @@ void CameraManager::addCamera(std::shared_ptr<Camera> camera)
}
/**
+ * \brief Remove a camera from the camera manager
+ * \param[in] camera The camera to be removed
+ *
+ * This function is called by pipeline handlers to unregister cameras from the
+ * camera manager. Unregistered cameras won't be reported anymore by the
+ * cameras() and get() calls, but references may still exist in applications.
+ */
+void CameraManager::removeCamera(Camera *camera)
+{
+ for (auto iter = cameras_.begin(); iter != cameras_.end(); ++iter) {
+ if (iter->get() == camera) {
+ LOG(Camera, Debug)
+ << "Unregistering camera '"
+ << camera->name() << "'";
+ cameras_.erase(iter);
+ return;
+ }
+ }
+}
+
+/**
* \brief Retrieve the camera manager instance
*
* The CameraManager is a singleton and can't be constructed manually. This