From patchwork Thu Jan 17 23:59:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 268 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C533860C98 for ; Fri, 18 Jan 2019 00:59:20 +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 64211D50 for ; Fri, 18 Jan 2019 00:59:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1547769560; bh=Yje3AtUt21PQk4uW1VFQ9J+pN5npOrqgOgINPDRdSro=; h=From:To:Subject:Date:In-Reply-To:References:From; b=G2jyw+FGOZ5+hNBIdlSa97m+1Z9PVqfQ+EzjHup+w0Xt2WXI09n/3J7wGdH+z/cNd 0y2Fa7UP1t9VLdLc1vk1NYBYdh7oGMLqYOiJgUpIGyTqtrvhzEqdhYzVHf9FXrQ5Vy GlWZYU32blKncBL9QzSlF+yJwSfhBp7onW9hDTgU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 18 Jan 2019 01:59:14 +0200 Message-Id: <20190117235916.1906-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190117235916.1906-1-laurent.pinchart@ideasonboard.com> References: <20190117235916.1906-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 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: Thu, 17 Jan 2019 23:59:20 -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 --- include/libcamera/camera_manager.h | 4 ++-- src/libcamera/camera_manager.cpp | 11 ++++++----- 2 files changed, 8 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..9806e399f92b 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -58,7 +58,6 @@ CameraManager::CameraManager() CameraManager::~CameraManager() { - delete dispatcher_; } /** @@ -209,14 +208,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 +225,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_.reset(new EventDispatcherPoll()); - return dispatcher_; + return dispatcher_.get(); } } /* namespace libcamera */