From patchwork Wed Jun 5 14:54:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 1359 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6597566231 for ; Wed, 5 Jun 2019 16:54:35 +0200 (CEST) Received: from pendragon.ideasonboard.com (85-76-142-100-nat.elisa-mobile.fi [85.76.142.100]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 82D1B84 for ; Wed, 5 Jun 2019 16:54:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1559746475; bh=0P2ckfzEYfae/GANwOwDna+9Dx0PPVJKJeGdrmEAkdQ=; h=From:To:Subject:Date:From; b=XFFtRW/lbPqjnlPQRPbbWpBjfBy+fhkuldpYC+grB4qUgnthPgXwrelAOdSYcV6FV cxAvvKVdrj3eXySFWlhrfJ90ef1xQvhwBjbjXx4dTcP9XlpBuKMM6ZZYjCe4JE6XVu hP2tAjy3ZwizHNLhzdFbkrYHL7E+BM3bYR2RA/m4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 5 Jun 2019 17:54:13 +0300 Message-Id: <20190605145413.9888-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: pipeline_handler: Optimise factory implementation 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: Wed, 05 Jun 2019 14:54:35 -0000 The REGISTER_PIPELINE_HANDLER() macro defines and instantiates a subclass of the PipelineHandlerFactory class that specialises the virtual create() method. Now that create() does more than just creating an instance, boilerplate code gets duplicated between different factories. Factor out the instance creation code to a new virtual createInstance() method, and turn create() into a non-virtual method of the base class that can then be defined in the .cpp file. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- src/libcamera/include/pipeline_handler.h | 11 +++----- src/libcamera/pipeline_handler.cpp | 33 +++++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h index 84307e408772..36f0b84c0d6c 100644 --- a/src/libcamera/include/pipeline_handler.h +++ b/src/libcamera/include/pipeline_handler.h @@ -107,7 +107,7 @@ public: PipelineHandlerFactory(const char *name); virtual ~PipelineHandlerFactory() { }; - virtual std::shared_ptr create(CameraManager *manager) = 0; + std::shared_ptr create(CameraManager *manager); const std::string &name() const { return name_; } @@ -115,7 +115,7 @@ public: static std::vector &factories(); protected: - void setInfo(PipelineHandler *handler, const char *name); + virtual PipelineHandler *createInstance(CameraManager *manager) = 0; private: std::string name_; @@ -126,12 +126,9 @@ class handler##Factory final : public PipelineHandlerFactory \ { \ public: \ handler##Factory() : PipelineHandlerFactory(#handler) {} \ - std::shared_ptr create(CameraManager *manager) \ + PipelineHandler *createInstance(CameraManager *manager) \ { \ - std::shared_ptr h = \ - std::make_shared(manager); \ - setInfo(h.get(), #handler); \ - return h; \ + return new handler(manager); \ } \ }; \ static handler##Factory global_##handler##Factory; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 800931d81337..af19f4a33187 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -539,17 +539,18 @@ PipelineHandlerFactory::PipelineHandlerFactory(const char *name) } /** - * \fn PipelineHandlerFactory::create() * \brief Create an instance of the PipelineHandler corresponding to the factory * \param[in] manager The camera manager * - * This virtual function is implemented by the REGISTER_PIPELINE_HANDLER() - * macro. It creates a pipeline handler instance associated with the camera - * \a manager. - * - * \return a pointer to a newly constructed instance of the PipelineHandler - * subclass corresponding to the factory + * \return A shared pointer to a new instance of the PipelineHandler subclass + * corresponding to the factory */ +std::shared_ptr PipelineHandlerFactory::create(CameraManager *manager) +{ + PipelineHandler *handler = createInstance(manager); + handler->name_ = name_.c_str(); + return std::shared_ptr(handler); +} /** * \fn PipelineHandlerFactory::name() @@ -589,15 +590,17 @@ std::vector &PipelineHandlerFactory::factories() } /** - * \brief Set the information of a given pipeline handler - * \param[in] handler The handler whose info is to be set - * \param[in] name The name of the pipeline handler + * \fn PipelineHandlerFactory::createInstance() + * \brief Create an instance of the PipelineHandler corresponding to the factory + * \param[in] manager The camera manager + * + * This virtual function is implemented by the REGISTER_PIPELINE_HANDLER() + * macro. It creates a pipeline handler instance associated with the camera + * \a manager. + * + * \return a pointer to a newly constructed instance of the PipelineHandler + * subclass corresponding to the factory */ -void PipelineHandlerFactory::setInfo(PipelineHandler *handler, - const char *name) -{ - handler->name_ = name; -} /** * \def REGISTER_PIPELINE_HANDLER