From patchwork Fri Jan 18 23:26:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 276 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DD7F560C78 for ; Sat, 19 Jan 2019 00:26:21 +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 5353253E for ; Sat, 19 Jan 2019 00:26:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547853981; bh=9Djyc7v/dOhluNfzsyGTNJdHSRrI7VLC07N9DnanbEo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KnUkKjC4eJzkzaCSDdS78rHz4WW6eJ+XPtKVr9Y9khmgJJnly413mz7xcy8BY532U jX59VynCaoKaMsM7hw+rksCgSitsRNRnMredVJufGToPL1z/BcyX6InSyEQjBYduqM KsHf4FDWdtuPFLUxunhBcgmwSOPmJgMaLSVhtqTs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sat, 19 Jan 2019 01:26:15 +0200 Message-Id: <20190118232617.14631-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190118232617.14631-1-laurent.pinchart@ideasonboard.com> References: <20190118232617.14631-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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 23:26:22 -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 Reviewed-by: Jacopo Mondi --- 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 */