libcamera: pipeline_handler: Optimise factory implementation
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
@@ -107,17 +107,16 @@ public:
|
||||
PipelineHandlerFactory(const char *name);
|
||||
virtual ~PipelineHandlerFactory() { };
|
||||
|
||||
virtual std::shared_ptr<PipelineHandler> create(CameraManager *manager) = 0;
|
||||
std::shared_ptr<PipelineHandler> create(CameraManager *manager);
|
||||
|
||||
const std::string &name() const { return name_; }
|
||||
|
||||
static void registerType(PipelineHandlerFactory *factory);
|
||||
static std::vector<PipelineHandlerFactory *> &factories();
|
||||
|
||||
protected:
|
||||
void setInfo(PipelineHandler *handler, const char *name);
|
||||
|
||||
private:
|
||||
virtual PipelineHandler *createInstance(CameraManager *manager) = 0;
|
||||
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
@@ -126,12 +125,11 @@ class handler##Factory final : public PipelineHandlerFactory \
|
||||
{ \
|
||||
public: \
|
||||
handler##Factory() : PipelineHandlerFactory(#handler) {} \
|
||||
std::shared_ptr<PipelineHandler> create(CameraManager *manager) \
|
||||
\
|
||||
private: \
|
||||
PipelineHandler *createInstance(CameraManager *manager) \
|
||||
{ \
|
||||
std::shared_ptr<handler> h = \
|
||||
std::make_shared<handler>(manager); \
|
||||
setInfo(h.get(), #handler); \
|
||||
return h; \
|
||||
return new handler(manager); \
|
||||
} \
|
||||
}; \
|
||||
static handler##Factory global_##handler##Factory;
|
||||
|
||||
Reference in New Issue
Block a user