libcamera: pipeline_handler: Don't index factories by name
Pipeline handler factories are register in a map indexed by their name, and the list of names is used to expose the factories and look them up. This is unnecessary cumbersome, we can instead store factories in a vector and expose it directly. The pipeline factory users will still have access to the factory names through the factory name() function. The PipelineHandlerFactory::create() method becomes so simple that it can be inlined in its single caller, removing the unneeded usage of the DeviceEnumerator in the factory. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
@@ -31,29 +31,28 @@ public:
|
||||
class PipelineHandlerFactory
|
||||
{
|
||||
public:
|
||||
PipelineHandlerFactory(const char *name);
|
||||
virtual ~PipelineHandlerFactory() { };
|
||||
|
||||
virtual PipelineHandler *create() = 0;
|
||||
|
||||
static void registerType(const std::string &name, PipelineHandlerFactory *factory);
|
||||
static PipelineHandler *create(const std::string &name, DeviceEnumerator *enumerator);
|
||||
static std::vector<std::string> handlers();
|
||||
const std::string &name() const { return name_; }
|
||||
|
||||
static void registerType(PipelineHandlerFactory *factory);
|
||||
static std::vector<PipelineHandlerFactory *> &handlers();
|
||||
|
||||
private:
|
||||
static std::map<std::string, PipelineHandlerFactory *> ®istry();
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
#define REGISTER_PIPELINE_HANDLER(handler) \
|
||||
class handler##Factory : public PipelineHandlerFactory { \
|
||||
public: \
|
||||
handler##Factory() \
|
||||
{ \
|
||||
PipelineHandlerFactory::registerType(#handler, this); \
|
||||
} \
|
||||
virtual PipelineHandler *create() { \
|
||||
return new handler(); \
|
||||
} \
|
||||
}; \
|
||||
#define REGISTER_PIPELINE_HANDLER(handler) \
|
||||
class handler##Factory : public PipelineHandlerFactory { \
|
||||
public: \
|
||||
handler##Factory() : PipelineHandlerFactory(#handler) { } \
|
||||
PipelineHandler *create() final { \
|
||||
return new handler(); \
|
||||
} \
|
||||
}; \
|
||||
static handler##Factory global_##handler##Factory;
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
||||
Reference in New Issue
Block a user