summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-18 01:49:17 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-21 11:13:45 +0200
commit32bf7ef239c1310fba638f35046b0f7eb13b32bf (patch)
tree9a3134f5b3b255c47d3e4d3520af983fab1873d0 /src
parent0908669834c459bca0c52ac951ede84126f2546d (diff)
libcamera: camera_manager: Use std::unique_ptr to store event dispatcher
The CameraManager takes ownership of the dispatcher passed to the setEventDispatcher() function. Enforces this by using std::unique_ptr<>. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/camera_manager.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index 9f554be5..1430bb0d 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -12,6 +12,7 @@
#include "event_dispatcher_poll.h"
#include "log.h"
#include "pipeline_handler.h"
+#include "utils.h"
/**
* \file camera_manager.h
@@ -58,7 +59,6 @@ CameraManager::CameraManager()
CameraManager::~CameraManager()
{
- delete dispatcher_;
}
/**
@@ -209,14 +209,14 @@ CameraManager *CameraManager::instance()
* The CameraManager takes ownership of the event dispatcher and will delete it
* when the application terminates.
*/
-void CameraManager::setEventDispatcher(EventDispatcher *dispatcher)
+void CameraManager::setEventDispatcher(std::unique_ptr<EventDispatcher> dispatcher)
{
if (dispatcher_) {
LOG(Warning) << "Event dispatcher is already set";
return;
}
- dispatcher_ = dispatcher;
+ dispatcher_ = std::move(dispatcher);
}
/**
@@ -226,14 +226,16 @@ void CameraManager::setEventDispatcher(EventDispatcher *dispatcher)
* If no dispatcher has been set, a default poll-based implementation is created
* and returned, and no custom event dispatcher may be installed anymore.
*
+ * The returned event dispatcher is valid until the camera manager is destroyed.
+ *
* \return Pointer to the event dispatcher
*/
EventDispatcher *CameraManager::eventDispatcher()
{
if (!dispatcher_)
- dispatcher_ = new EventDispatcherPoll();
+ dispatcher_ = utils::make_unique<EventDispatcherPoll>();
- return dispatcher_;
+ return dispatcher_.get();
}
} /* namespace libcamera */