mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 00:25:07 +03:00
libcamera: camera_manager: Introduce signals when a camera is added or removed
Emit 'cameraAdded' and 'cameraRemoved' from CameraManager to enable hotplug and hot-unplug support in application like QCam. To avoid use-after-free race between the CameraManager and the application, emit the 'cameraRemoved' with the shared_ptr version of <Camera *>. This requires to change the function signature of CameraManager::removeCamera() API. Also, until now, CameraManager::Private::addCamera() transfers the entire ownership of camera shared_ptr to CameraManager using std::move(). This patch changes the signature of Private::addCamera to accept pass-by-value camera parameter. It is done to make it clear from the caller point of view that the pointer within the caller will still be valid after this function returns. With this change in, we can emit the camera pointer via 'cameraAdded' signal without hitting a segfault. Signed-off-by: Umang Jain <email@uajain.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
dd21ededd0
commit
e9b47217b4
3 changed files with 40 additions and 6 deletions
|
@ -13,6 +13,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <libcamera/object.h>
|
||||
#include <libcamera/signal.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
|
@ -36,13 +37,16 @@ public:
|
|||
|
||||
void addCamera(std::shared_ptr<Camera> camera,
|
||||
const std::vector<dev_t> &devnums);
|
||||
void removeCamera(Camera *camera);
|
||||
void removeCamera(std::shared_ptr<Camera> camera);
|
||||
|
||||
static const std::string &version() { return version_; }
|
||||
|
||||
void setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher);
|
||||
EventDispatcher *eventDispatcher();
|
||||
|
||||
Signal<std::shared_ptr<Camera>> cameraAdded;
|
||||
Signal<std::shared_ptr<Camera>> cameraRemoved;
|
||||
|
||||
private:
|
||||
static const std::string version_;
|
||||
static CameraManager *self_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue