[libcamera-devel,v2,05/11] ipa: module: Add getAlgorithm() method
diff mbox series

Message ID 20220713084317.24268-6-dse@thaumatec.com
State Superseded
Headers show
Series
  • ipa: rkisp1: Add autofocus algorithm
Related show

Commit Message

Daniel Semkowicz July 13, 2022, 8:43 a.m. UTC
This function allows to get pointer to the algorithm of specific type
from the list of loaded algorithms.

Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
---
 src/ipa/libipa/module.cpp |  7 +++++++
 src/ipa/libipa/module.h   | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)

Comments

Jacopo Mondi July 14, 2022, 6:35 p.m. UTC | #1
I'm not really expert of this part, this looks right, I'm only
surprised we didn't have one already.. let me cc Laurent which I
presume implemented the algorith registration mechinery.


On Wed, Jul 13, 2022 at 10:43:11AM +0200, Daniel Semkowicz via libcamera-devel wrote:
> This function allows to get pointer to the algorithm of specific type
> from the list of loaded algorithms.
>
> Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
> ---
>  src/ipa/libipa/module.cpp |  7 +++++++
>  src/ipa/libipa/module.h   | 17 +++++++++++++++++
>  2 files changed, 24 insertions(+)
>
> diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
> index 77352104..7c0680fd 100644
> --- a/src/ipa/libipa/module.cpp
> +++ b/src/ipa/libipa/module.cpp
> @@ -83,6 +83,13 @@ namespace ipa {
>   * \return The list of instantiated algorithms
>   */
>
> +/**
> + * \fn Module::getAlgorithm()
> + * \brief Find and return the algorithm of requested type
> + * \tparam AlgoType Algorithm type you want to retrieve
> + * \return Pointer to the algorithm if found, else nullptr
> + */
> +
>  /**
>   * \fn Module::createAlgorithms()
>   * \brief Create algorithms from YAML configuration data
> diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
> index 4149a353..c4974635 100644
> --- a/src/ipa/libipa/module.h
> +++ b/src/ipa/libipa/module.h
> @@ -10,6 +10,7 @@
>  #include <list>
>  #include <memory>
>  #include <string>
> +#include <typeinfo>
>  #include <vector>
>
>  #include <libcamera/base/log.h>
> @@ -43,6 +44,22 @@ public:
>  		return algorithms_;
>  	}
>
> +	template<typename AlgoType>
> +	AlgoType *getAlgorithm() const
> +	{
> +		auto isSameType = [](const std::unique_ptr<Algorithm<Module>> &algoPtr) {
> +			return typeid(*algoPtr.get()) == typeid(AlgoType);
> +		};
> +
> +		auto result = std::find_if(begin(algorithms_), end(algorithms_), isSameType);
> +
> +		if (result != std::end(algorithms_)) {
> +			return static_cast<AlgoType *>(result->get());
> +		} else {
> +			return nullptr;
> +		}

                if (result != std::end(algorithms_))
                        return static_cast<AlgoType *>(result->get());

                return nullptr;


> +	}
> +
>  	int createAlgorithms(Context &context, const YamlObject &algorithms)
>  	{
>  		const auto &list = algorithms.asList();
> --
> 2.34.1
>
Laurent Pinchart July 15, 2022, 12:44 a.m. UTC | #2
On Thu, Jul 14, 2022 at 08:35:28PM +0200, Jacopo Mondi wrote:
> I'm not really expert of this part, this looks right, I'm only
> surprised we didn't have one already.. let me cc Laurent which I
> presume implemented the algorith registration mechinery.

Depending on the outcome of the discussion in 06/11, this patch may not
be needed.

> On Wed, Jul 13, 2022 at 10:43:11AM +0200, Daniel Semkowicz via libcamera-devel wrote:
> > This function allows to get pointer to the algorithm of specific type
> > from the list of loaded algorithms.
> >
> > Signed-off-by: Daniel Semkowicz <dse@thaumatec.com>
> > ---
> >  src/ipa/libipa/module.cpp |  7 +++++++
> >  src/ipa/libipa/module.h   | 17 +++++++++++++++++
> >  2 files changed, 24 insertions(+)
> >
> > diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
> > index 77352104..7c0680fd 100644
> > --- a/src/ipa/libipa/module.cpp
> > +++ b/src/ipa/libipa/module.cpp
> > @@ -83,6 +83,13 @@ namespace ipa {
> >   * \return The list of instantiated algorithms
> >   */
> >
> > +/**
> > + * \fn Module::getAlgorithm()
> > + * \brief Find and return the algorithm of requested type
> > + * \tparam AlgoType Algorithm type you want to retrieve
> > + * \return Pointer to the algorithm if found, else nullptr
> > + */
> > +
> >  /**
> >   * \fn Module::createAlgorithms()
> >   * \brief Create algorithms from YAML configuration data
> > diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
> > index 4149a353..c4974635 100644
> > --- a/src/ipa/libipa/module.h
> > +++ b/src/ipa/libipa/module.h
> > @@ -10,6 +10,7 @@
> >  #include <list>
> >  #include <memory>
> >  #include <string>
> > +#include <typeinfo>
> >  #include <vector>
> >
> >  #include <libcamera/base/log.h>
> > @@ -43,6 +44,22 @@ public:
> >  		return algorithms_;
> >  	}
> >
> > +	template<typename AlgoType>
> > +	AlgoType *getAlgorithm() const
> > +	{
> > +		auto isSameType = [](const std::unique_ptr<Algorithm<Module>> &algoPtr) {
> > +			return typeid(*algoPtr.get()) == typeid(AlgoType);
> > +		};
> > +
> > +		auto result = std::find_if(begin(algorithms_), end(algorithms_), isSameType);
> > +
> > +		if (result != std::end(algorithms_)) {
> > +			return static_cast<AlgoType *>(result->get());
> > +		} else {
> > +			return nullptr;
> > +		}
> 
>                 if (result != std::end(algorithms_))
>                         return static_cast<AlgoType *>(result->get());
> 
>                 return nullptr;
> 
> > +	}
> > +
> >  	int createAlgorithms(Context &context, const YamlObject &algorithms)
> >  	{
> >  		const auto &list = algorithms.asList();

Patch
diff mbox series

diff --git a/src/ipa/libipa/module.cpp b/src/ipa/libipa/module.cpp
index 77352104..7c0680fd 100644
--- a/src/ipa/libipa/module.cpp
+++ b/src/ipa/libipa/module.cpp
@@ -83,6 +83,13 @@  namespace ipa {
  * \return The list of instantiated algorithms
  */
 
+/**
+ * \fn Module::getAlgorithm()
+ * \brief Find and return the algorithm of requested type
+ * \tparam AlgoType Algorithm type you want to retrieve
+ * \return Pointer to the algorithm if found, else nullptr
+ */
+
 /**
  * \fn Module::createAlgorithms()
  * \brief Create algorithms from YAML configuration data
diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h
index 4149a353..c4974635 100644
--- a/src/ipa/libipa/module.h
+++ b/src/ipa/libipa/module.h
@@ -10,6 +10,7 @@ 
 #include <list>
 #include <memory>
 #include <string>
+#include <typeinfo>
 #include <vector>
 
 #include <libcamera/base/log.h>
@@ -43,6 +44,22 @@  public:
 		return algorithms_;
 	}
 
+	template<typename AlgoType>
+	AlgoType *getAlgorithm() const
+	{
+		auto isSameType = [](const std::unique_ptr<Algorithm<Module>> &algoPtr) {
+			return typeid(*algoPtr.get()) == typeid(AlgoType);
+		};
+
+		auto result = std::find_if(begin(algorithms_), end(algorithms_), isSameType);
+
+		if (result != std::end(algorithms_)) {
+			return static_cast<AlgoType *>(result->get());
+		} else {
+			return nullptr;
+		}
+	}
+
 	int createAlgorithms(Context &context, const YamlObject &algorithms)
 	{
 		const auto &list = algorithms.asList();