From patchwork Sun Jan 6 02:33:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 153 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D3D6060B2E for ; Sun, 6 Jan 2019 03:32:27 +0100 (CET) Received: from avalon.bb.dnainternet.fi (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7478598C for ; Sun, 6 Jan 2019 03:32:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1546741947; bh=Ul2/eLTgDrmri2CL85FO+TRHiaTiObBDZCXmYikoYVg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=P3dPAmzry7mPw36XJ4sncVzQ79FblW/EIzNyc9ko7PJAogR9bQKgy8JUv00l9bYDM OZsFzSUGIk/HHCNNkMdxwjRynGTyXdl6Yu+PPXP3eAgg+oqPkBKIGrOAnqU6nG5vRb hC5LLn2nwoWv9L+1fcSSREjg9a05riaGSYit+J9Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 6 Jan 2019 04:33:21 +0200 Message-Id: <20190106023328.10989-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190106023328.10989-1-laurent.pinchart@ideasonboard.com> References: <20190106023328.10989-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/11] libcamera: camera_manager: Make the class a singleton 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: Sun, 06 Jan 2019 02:32:28 -0000 There can only be a single camera manager instance in the application. Creating it as a singleton helps avoiding mistakes. It also allows the camera manager to be used as a storage of global data, such as the future event dispatcher. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- include/libcamera/camera_manager.h | 6 ++++-- src/libcamera/camera_manager.cpp | 15 +++++++++++++++ test/list.cpp | 4 +--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/libcamera/camera_manager.h b/include/libcamera/camera_manager.h index 2768a5bd2384..56a3f32d8b6f 100644 --- a/include/libcamera/camera_manager.h +++ b/include/libcamera/camera_manager.h @@ -19,15 +19,17 @@ class PipelineHandler; class CameraManager { public: - CameraManager(); - int start(); void stop(); std::vector list() const; Camera *get(const std::string &name); + static CameraManager *instance(); + private: + CameraManager(); + DeviceEnumerator *enumerator_; std::vector pipes_; }; diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index 50a805fc665c..db2bc4b7424e 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -161,4 +161,19 @@ Camera *CameraManager::get(const std::string &name) return nullptr; } +/** + * \brief Retrieve the camera manager instance + * + * The CameraManager is a singleton and can't be constructed manually. This + * function can instead be used to retrieve the single global instance of the + * manager. + * + * \return The camera manager instance + */ +CameraManager *CameraManager::instance() +{ + static CameraManager manager; + return &manager; +} + } /* namespace libcamera */ diff --git a/test/list.cpp b/test/list.cpp index 39b8a41d1fef..49610c697c63 100644 --- a/test/list.cpp +++ b/test/list.cpp @@ -19,7 +19,7 @@ class ListTest : public Test protected: int init() { - cm = new CameraManager(); + cm = CameraManager::instance(); if (!cm) return -ENOMEM; @@ -43,8 +43,6 @@ protected: void cleanup() { cm->stop(); - - delete cm; } private: