From 34018d23d751e4818ce407b8bec5bafb158c1bb6 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Thu, 3 Jan 2019 04:01:15 +0200 Subject: libcamera: pipeline_handler: Don't index factories by name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- src/libcamera/camera_manager.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/libcamera/camera_manager.cpp') diff --git a/src/libcamera/camera_manager.cpp b/src/libcamera/camera_manager.cpp index be327f5d..91ef6753 100644 --- a/src/libcamera/camera_manager.cpp +++ b/src/libcamera/camera_manager.cpp @@ -74,20 +74,24 @@ int CameraManager::start() * file and only fallback on all handlers if there is no * configuration file. */ - std::vector handlers = PipelineHandlerFactory::handlers(); - - for (std::string const &handler : handlers) { - PipelineHandler *pipe; + std::vector &handlers = PipelineHandlerFactory::handlers(); + for (PipelineHandlerFactory *factory : handlers) { /* * Try each pipeline handler until it exhaust * all pipelines it can provide. */ - do { - pipe = PipelineHandlerFactory::create(handler, enumerator_); - if (pipe) - pipes_.push_back(pipe); - } while (pipe); + while (1) { + PipelineHandler *pipe = factory->create(); + if (!pipe->match(enumerator_)) { + delete pipe; + break; + } + + LOG(Debug) << "Pipeline handler \"" << factory->name() + << "\" matched"; + pipes_.push_back(pipe); + } } /* TODO: register hot-plug callback here */ -- cgit v1.2.1