From patchwork Tue Jan 15 15:18:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 240 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DF5F860C8A for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77C2E4F8 for ; Tue, 15 Jan 2019 16:18:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547565535; bh=wIyEthRVn+dkk80COo3O7gLrLmoXEdkapwc5+9KikkM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=M1cStOQC2WpS7oAOPF5zPQ/FZMis6Rx6DZV0mrl4b9txmGXlotDdkhdKMZkU3EqvN ojJhsaLJcQfGFEfwDjuiLHcSu9Z9tQB7VwTASuTP9XgEMayU9VBPHNRK9cI9PoRUd+ YVmigf9ARQyWF5VGcNEv7IPtc49qAWirQl0rhrjo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 15 Jan 2019 17:18:49 +0200 Message-Id: <20190115151849.1547-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> References: <20190115151849.1547-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 8/8] libcamera: camera_manager: Turn enumerator into a unique_ptr<> X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2019 15:18:56 -0000 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 Reviewed-by: Niklas Söderlund --- include/libcamera/camera_manager.h | 3 ++- src/libcamera/camera_manager.cpp | 8 ++------ src/libcamera/device_enumerator.cpp | 9 ++++----- src/libcamera/include/device_enumerator.h | 3 ++- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 15e7c162032a..6cfcba3c3933 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -7,6 +7,7 @@ #ifndef __LIBCAMERA_CAMERA_MANAGER_H__ #define __LIBCAMERA_CAMERA_MANAGER_H__ +#include #include #include @@ -37,7 +38,7 @@ private: void operator=(const CameraManager &) = delete; ~CameraManager(); - DeviceEnumerator *enumerator_; + std::unique_ptr enumerator_; std::vector pipes_; EventDispatcher *dispatcher_; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index a17bf3d13a04..ae5542bc332d 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 18d7e86843e8..55c510e3b79a 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::create() { - DeviceEnumerator *enumerator; + std::unique_ptr enumerator; /** * \todo Add compile time checks to only try udev enumerator if libudev * is available. */ - enumerator = new DeviceEnumeratorUdev(); + enumerator = utils::make_unique(); 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 b68c815827dd..c5541c5f8d12 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 +#include #include #include @@ -34,7 +35,7 @@ private: class DeviceEnumerator { public: - static DeviceEnumerator *create(); + static std::unique_ptr create(); virtual ~DeviceEnumerator();