[libcamera-devel] [PATCH 07/10] libcamera: camera_manager: Add method to unregister a camera

Niklas Söderlund niklas.soderlund at ragnatech.se
Thu Jan 24 19:06:14 CET 2019


Hi Laurent,

Thanks for your work.

On 2019-01-24 12:16:48 +0200, Laurent Pinchart wrote:
> 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 at ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  include/libcamera/camera_manager.h |  1 +
>  src/libcamera/camera_manager.cpp   | 21 +++++++++++++++++++++
>  2 files changed, 22 insertions(+)
> 
> diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h
> index 45e72df0ef65..56dbd26f64db 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 3eccf20c4ce9..f90201ade18b 100644
> --- a/src/libcamera/camera_manager.cpp
> +++ b/src/libcamera/camera_manager.cpp
> @@ -191,6 +191,27 @@ void CameraManager::addCamera(std::shared_ptr<Camera> camera)
>  	cameras_.push_back(std::move(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
>   *
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list