summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-15 15:32:59 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2019-01-16 18:23:43 +0200
commit62eae99ed29ddba069068944f823332b9ca30c4e (patch)
tree6256732231d6fe1cd7fa693484b089a25e3623c0 /src
parenta2f095947f847cb7d3f058a74514109928b1df9f (diff)
libcamera: camera_manager: Turn enumerator into a unique_ptr<>
Convey the fact that the CameraManager class owns the DeviceEnumerator instance it creates by using std::unique_ptr<> to store the pointer. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Diffstat (limited to 'src')
-rw-r--r--src/libcamera/camera_manager.cpp8
-rw-r--r--src/libcamera/device_enumerator.cpp9
-rw-r--r--src/libcamera/include/device_enumerator.h3
3 files changed, 8 insertions, 12 deletions
diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp
index 2ee83d4d..9f554be5 100644
--- a/src/libcamera/camera_manager.cpp
+++ b/src/libcamera/camera_manager.cpp
@@ -73,7 +73,6 @@ CameraManager::~CameraManager()
*/
int CameraManager::start()
{
-
if (enumerator_)
return -ENODEV;
@@ -95,7 +94,7 @@ int CameraManager::start()
*/
while (1) {
PipelineHandler *pipe = factory->create();
- if (!pipe->match(enumerator_)) {
+ if (!pipe->match(enumerator_.get())) {
delete pipe;
break;
}
@@ -130,10 +129,7 @@ void CameraManager::stop()
pipes_.clear();
- if (enumerator_)
- delete enumerator_;
-
- enumerator_ = nullptr;
+ enumerator_.reset(nullptr);
}
/**
diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp
index 18d7e868..55c510e3 100644
--- a/src/libcamera/device_enumerator.cpp
+++ b/src/libcamera/device_enumerator.cpp
@@ -14,6 +14,7 @@
#include "device_enumerator.h"
#include "log.h"
#include "media_device.h"
+#include "utils.h"
/**
* \file device_enumerator.h
@@ -128,20 +129,18 @@ bool DeviceMatch::match(const MediaDevice *device) const
* \return A pointer to the newly created device enumerator on success, or
* nullptr if an error occurs
*/
-DeviceEnumerator *DeviceEnumerator::create()
+std::unique_ptr<DeviceEnumerator> DeviceEnumerator::create()
{
- DeviceEnumerator *enumerator;
+ std::unique_ptr<DeviceEnumerator> enumerator;
/**
* \todo Add compile time checks to only try udev enumerator if libudev
* is available.
*/
- enumerator = new DeviceEnumeratorUdev();
+ enumerator = utils::make_unique<DeviceEnumeratorUdev>();
if (!enumerator->init())
return enumerator;
- delete enumerator;
-
/*
* Either udev is not available or udev initialization failed. Fall back
* on the sysfs enumerator.
diff --git a/src/libcamera/include/device_enumerator.h b/src/libcamera/include/device_enumerator.h
index b68c8158..c5541c5f 100644
--- a/src/libcamera/include/device_enumerator.h
+++ b/src/libcamera/include/device_enumerator.h
@@ -8,6 +8,7 @@
#define __LIBCAMERA_DEVICE_ENUMERATOR_H__
#include <map>
+#include <memory>
#include <string>
#include <vector>
@@ -34,7 +35,7 @@ private:
class DeviceEnumerator
{
public:
- static DeviceEnumerator *create();
+ static std::unique_ptr<DeviceEnumerator> create();
virtual ~DeviceEnumerator();