From 9ab024f7c27d9b6b3ab433502eab02d4a29a3da4 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 21 Mar 2020 19:56:35 +0200 Subject: libcamera: device_enumerator: Convey device ownership through unique_ptr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace usage of shared_ptr with unique_ptr to convey media device ownership internally in the enumerators when creating the media device. Once a media device has all its dependencies met, it is converted to a shared_ptr to keep the external API unchanged. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Kieran Bingham --- src/libcamera/device_enumerator.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libcamera/device_enumerator.cpp') diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index 89ed67eb..dd17e3e3 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -208,9 +208,9 @@ DeviceEnumerator::~DeviceEnumerator() * * \return Created media device instance on success, or nullptr otherwise */ -std::shared_ptr DeviceEnumerator::createDevice(const std::string &deviceNode) +std::unique_ptr DeviceEnumerator::createDevice(const std::string &deviceNode) { - std::shared_ptr media = std::make_shared(deviceNode); + std::unique_ptr media = std::make_unique(deviceNode); int ret = media->populate(); if (ret < 0) { @@ -236,12 +236,12 @@ std::shared_ptr DeviceEnumerator::createDevice(const std::string &d * This method shall be called after all members of the entities of the * media graph have been confirmed to be initialized. */ -void DeviceEnumerator::addDevice(const std::shared_ptr &media) +void DeviceEnumerator::addDevice(std::unique_ptr &&media) { LOG(DeviceEnumerator, Debug) << "Added device " << media->deviceNode() << ": " << media->driver(); - devices_.push_back(media); + devices_.push_back(std::move(media)); } /** @@ -290,7 +290,7 @@ void DeviceEnumerator::removeDevice(const std::string &deviceNode) */ std::shared_ptr DeviceEnumerator::search(const DeviceMatch &dm) { - for (std::shared_ptr media : devices_) { + for (std::shared_ptr &media : devices_) { if (media->busy()) continue; -- cgit v1.2.1