From patchwork Fri Jan 18 00:32:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 271 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E1F3D60B2D for ; Fri, 18 Jan 2019 01:32:06 +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 6935A53F for ; Fri, 18 Jan 2019 01:32:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547771526; bh=qF1twtbU6EoasVW2D49K7A5kQ4gDeR25xbDF1JPuEdc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CiQ9fO+PXGsozspkIrLwM/rcT8SRVvthn3hpBcjjp+0hLf76NtNL804goV2/VNZOB zhzpZSM1HtyR4pmSKWElcEw+gH3PA6819Lwe24BwnMnfKjlOh/sdG77XidpijYQWFK 3HGEIOwwZGmb0pVWHvP0Tw8lzGyHl994PM+w7UH0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 18 Jan 2019 02:32:01 +0200 Message-Id: <20190118003201.3110-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190117235916.1906-3-laurent.pinchart@ideasonboard.com> References: <20190117235916.1906-3-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1.1 2/4] libcamera: camera_manager: Use std::unique_ptr to store event dispatcher 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: Fri, 18 Jan 2019 00:32:07 -0000 The CameraManager takes ownership of the dispatcher passed to the setEventDispatcher() function. Enforces this by using std::unique_ptr<>. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- Changes since v1: - Use make_unique<> in CameraManager::setEventDispatcher() --- include/libcamera/camera_manager.h | 4 ++-- src/libcamera/camera_manager.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 6cfcba3c3933..b82a8ce95b9f 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -29,7 +29,7 @@ public: static CameraManager *instance(); - void setEventDispatcher(EventDispatcher *dispatcher); + void setEventDispatcher(std::unique_ptr dispatcher); EventDispatcher *eventDispatcher(); private: @@ -41,7 +41,7 @@ private: std::unique_ptr enumerator_; std::vector pipes_; - EventDispatcher *dispatcher_; + std::unique_ptr dispatcher_; }; } /* namespace libcamera */ diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 9f554be57e33..1430bb0d75a5 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 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(); - return dispatcher_; + return dispatcher_.get(); } } /* namespace libcamera */