From 0bc9286eb97aa4d38d643ee5c45fa6a487d12459 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 3 Oct 2022 22:55:11 +0300 Subject: libcamera: pipeline_handler: Implement factories through class templates The REGISTER_PIPELINE_HANDLER() macro defines a class type that inherits from the PipelineHandlerFactory class, and implements a constructor and a createInstance() function. Replace the code generation through macro with the C++ equivalent, a class template, as done in libipa with the Algorithm and CameraSensorHelper factories. Signed-off-by: Laurent Pinchart Reviewed-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index ad74dc82..b6139a88 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -95,23 +95,23 @@ private: Mutex lock_; unsigned int useCount_ LIBCAMERA_TSA_GUARDED_BY(lock_); - friend class PipelineHandlerFactory; + friend class PipelineHandlerFactoryBase; }; -class PipelineHandlerFactory +class PipelineHandlerFactoryBase { public: - PipelineHandlerFactory(const char *name); - virtual ~PipelineHandlerFactory() = default; + PipelineHandlerFactoryBase(const char *name); + virtual ~PipelineHandlerFactoryBase() = default; std::shared_ptr create(CameraManager *manager) const; const std::string &name() const { return name_; } - static std::vector &factories(); + static std::vector &factories(); private: - static void registerType(PipelineHandlerFactory *factory); + static void registerType(PipelineHandlerFactoryBase *factory); virtual std::unique_ptr createInstance(CameraManager *manager) const = 0; @@ -119,19 +119,23 @@ private: std::string name_; }; -#define REGISTER_PIPELINE_HANDLER(handler) \ -class handler##Factory final : public PipelineHandlerFactory \ -{ \ -public: \ - handler##Factory() : PipelineHandlerFactory(#handler) {} \ - \ -private: \ - std::unique_ptr \ - createInstance(CameraManager *manager) const \ - { \ - return std::make_unique(manager); \ - } \ -}; \ -static handler##Factory global_##handler##Factory; +template +class PipelineHandlerFactory final : public PipelineHandlerFactoryBase +{ +public: + PipelineHandlerFactory(const char *name) + : PipelineHandlerFactoryBase(name) + { + } + + std::unique_ptr + createInstance(CameraManager *manager) const override + { + return std::make_unique<_PipelineHandler>(manager); + } +}; + +#define REGISTER_PIPELINE_HANDLER(handler) \ +static PipelineHandlerFactory global_##handler##Factory(#handler); } /* namespace libcamera */ -- cgit v1.2.1