[08/10] RFC ipa: libipa: Inject the registered name into an algorithm
diff mbox series

Message ID 20261117-sklug-digital-gain-support-v1-v1-8-f0aa342ca877@ideasonboard.com
State New
Headers show
Series
  • libipa: agc: Add digital gain support
Related show

Commit Message

Stefan Klug Nov. 17, 2026, 8:47 a.m. UTC
When algorithms are handled it is helpful to be able to deduce the
name an algorithm was registered with from the algorithm instance.
Allow that by injecting the name into the instance after construction.

ToDo:
- We could as well force every algorithm to implement name() and could then drop
this clunky logic. But maybe there are other reasons for this kind of registry.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/libipa/algorithm.h | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/algorithm.h b/src/ipa/libipa/algorithm.h
index 4ddb16ef3920..b47765700317 100644
--- a/src/ipa/libipa/algorithm.h
+++ b/src/ipa/libipa/algorithm.h
@@ -18,6 +18,9 @@  class ValueNode;
 
 namespace ipa {
 
+template<typename _Module>
+class AlgorithmFactoryBase;
+
 template<typename _Module>
 class Algorithm
 {
@@ -59,6 +62,15 @@  public:
 			     [[maybe_unused]] ControlList &metadata)
 	{
 	}
+
+	const std::string &name() const
+	{
+		return name_;
+	}
+
+private:
+	std::string name_;
+	friend class AlgorithmFactoryBase<_Module>;
 };
 
 template<typename _Module>
@@ -77,6 +89,11 @@  public:
 
 	virtual std::unique_ptr<Algorithm<_Module>> create() const = 0;
 
+	void injectName(Algorithm<_Module> *instance) const
+	{
+		instance->name_ = name();
+	}
+
 private:
 	std::string name_;
 };
@@ -94,7 +111,9 @@  public:
 
 	std::unique_ptr<Algorithm<typename _Algorithm::Module>> create() const override
 	{
-		return std::make_unique<_Algorithm>();
+		auto instance = std::make_unique<_Algorithm>();
+		AlgorithmFactoryBase<typename _Algorithm::Module>::injectName(instance.get());
+		return instance;
 	}
 };