summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-10-03 22:55:11 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2022-10-07 18:10:38 +0300
commit0bc9286eb97aa4d38d643ee5c45fa6a487d12459 (patch)
treef959b21afc6a8dcc7eb12f8bc3a41e7b2274b202 /include
parentba3a1adc13b9a2c2e92f438bcf5320d77bd08bd9 (diff)
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Xavier Roumegue <xavier.roumegue@oss.nxp.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/pipeline_handler.h44
1 files changed, 24 insertions, 20 deletions
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<PipelineHandler> create(CameraManager *manager) const;
const std::string &name() const { return name_; }
- static std::vector<PipelineHandlerFactory *> &factories();
+ static std::vector<PipelineHandlerFactoryBase *> &factories();
private:
- static void registerType(PipelineHandlerFactory *factory);
+ static void registerType(PipelineHandlerFactoryBase *factory);
virtual std::unique_ptr<PipelineHandler>
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<PipelineHandler> \
- createInstance(CameraManager *manager) const \
- { \
- return std::make_unique<handler>(manager); \
- } \
-}; \
-static handler##Factory global_##handler##Factory;
+template<typename _PipelineHandler>
+class PipelineHandlerFactory final : public PipelineHandlerFactoryBase
+{
+public:
+ PipelineHandlerFactory(const char *name)
+ : PipelineHandlerFactoryBase(name)
+ {
+ }
+
+ std::unique_ptr<PipelineHandler>
+ createInstance(CameraManager *manager) const override
+ {
+ return std::make_unique<_PipelineHandler>(manager);
+ }
+};
+
+#define REGISTER_PIPELINE_HANDLER(handler) \
+static PipelineHandlerFactory<handler> global_##handler##Factory(#handler);
} /* namespace libcamera */