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:
Laurent Pinchart
2019-01-03 04:01:15 +02:00
parent a5e86d4396
commit 34018d23d7
3 changed files with 55 additions and 90 deletions
+14 -15
View File
@@ -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 *> &registry();
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 */