@@ -83,6 +83,40 @@ namespace ipa {
* \return The list of instantiated algorithms
*/
+/**
+ * \fn int Module::createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
+ * \brief Create and initialise a self-enumerating algorithm by name
+ *
+ * This function creates an algorithm instance from the registered algorithm
+ * factories using only the algorithm name, without requiring YAML configuration
+ * data.
+ *
+ * This is useful for algorithms that don't require external configuration
+ * parameters and can self-configure or use default values.
+ *
+ * \param[in] context The IPA context to pass to the algorithm's init function
+ * \param[in] name The name of the algorithm to instantiate
+ *
+ * \return 0 on success, negative errno value on failure:
+ * -EINVAL if the algorithm is not found in the factory registry
+ * Other negative values if algorithm initialisation fails
+ */
+
+/**
+ * \fn int Module::createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
+ * \brief Common helper fucntion to allow createSelfEnumeratingAlgorithm and createAlgorithm share code
+ *
+ * Worker method which allows sharing of common code in the Yaml and self-initialising algorithm case
+ *
+ * \param[in] context The IPA context to pass to the algorithm's init function
+ * \param[in] algoData Yaml object.
+ * \param[in] name The name of the algorithm to instantiate
+ *
+ * \return 0 on success, negative errno value on failure:
+ * -EINVAL if the algorithm is not found in the factory registry
+ * Other negative values if algorithm initialisation fails
+ */
+
/**
* \fn Module::createAlgorithms()
* \brief Create algorithms from YAML configuration data
@@ -70,22 +70,26 @@ public:
factories().push_back(factory);
}
-private:
- int createAlgorithm(Context &context, const YamlObject &data)
+ int createSelfEnumeratingAlgorithm(Context &context, const std::string &name)
{
- const auto &[name, algoData] = *data.asDict().begin();
+ YamlObject dummy;
- /*
- * Optionally, algorithms can be disabled via the tuning file
- * by including enabled: false as a parameter within the
- * algorithm tuning data. This is not an error, so we return 0.
- */
- if (!algoData["enabled"].get<bool>(true)) {
- LOG(IPAModuleAlgo, Info)
- << "Algorithm '" << name << "' disabled via tuning file";
- return 0;
+ std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
+ if (!algo) {
+ LOG(IPAModuleAlgo, Error)
+ << "Algorithm '" << name << "' not found";
+ return -EINVAL;
}
+ context.selfInitialising = true;
+
+ return createAlgorithmCommon(context, dummy, name);
+ }
+
+private:
+
+ int createAlgorithmCommon(Context &context, const YamlObject &algoData, const std::string &name)
+ {
std::unique_ptr<Algorithm<Module>> algo = createAlgorithm(name);
if (!algo) {
LOG(IPAModuleAlgo, Error)
@@ -104,9 +108,28 @@ private:
<< "Instantiated algorithm '" << name << "'";
algorithms_.push_back(std::move(algo));
+
return 0;
}
+ int createAlgorithm(Context &context, const YamlObject &data)
+ {
+ const auto &[name, algoData] = *data.asDict().begin();
+
+ /*
+ * Optionally, algorithms can be disabled via the tuning file
+ * by including enabled: false as a parameter within the
+ * algorithm tuning data. This is not an error, so we return 0.
+ */
+ if (!algoData["enabled"].get<bool>(true)) {
+ LOG(IPAModuleAlgo, Info)
+ << "Algorithm '" << name << "' disabled via tuning file";
+ return 0;
+ }
+
+ return createAlgorithmCommon(context, algoData, name);
+ }
+
static std::unique_ptr<Algorithm<Module>> createAlgorithm(const std::string &name)
{
for (const AlgorithmFactoryBase<Module> *factory : factories()) {
Create an algorithm without having YAML data input. Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- src/ipa/libipa/module.cpp | 34 ++++++++++++++++++++++++++++ src/ipa/libipa/module.h | 47 +++++++++++++++++++++++++++++---------- 2 files changed, 69 insertions(+), 12 deletions(-)