From: Simon Marchi Date: Fri, 16 Feb 2024 20:42:59 +0000 (-0500) Subject: cpp-common/bt2: add `findPlugin()` X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=98701909c49b8d6433d9991b2cbe48f7514d047e;p=babeltrace.git cpp-common/bt2: add `findPlugin()` Add the `findPlugin()` function, allowing one to find a plugin by name. The default parameter values used are the same as those used in the Python bindings. Change-Id: I659b5b0f0ae18965bbcacdac3c4e0c146c7348e4 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/11823 Reviewed-by: Philippe Proulx Tested-by: jenkins --- diff --git a/src/cpp-common/bt2/plugin-load.hpp b/src/cpp-common/bt2/plugin-load.hpp index 0f3e8d5e..00b0510c 100644 --- a/src/cpp-common/bt2/plugin-load.hpp +++ b/src/cpp-common/bt2/plugin-load.hpp @@ -14,9 +14,30 @@ #include "exc.hpp" #include "plugin-set.hpp" +#include "plugin.hpp" namespace bt2 { +inline ConstPlugin::Shared +findPlugin(const bt2c::CStringView name, const bool findInStdEnvVar = true, + const bool findInUserDir = true, const bool findInSysDir = true, + const bool findInStatic = true, const bool failOnLoadError = false) +{ + const bt_plugin *plugin; + const auto status = bt_plugin_find(name, findInStdEnvVar, findInUserDir, findInSysDir, + findInStatic, failOnLoadError, &plugin); + + if (status == BT_PLUGIN_FIND_STATUS_MEMORY_ERROR) { + throw MemoryError {}; + } else if (status == BT_PLUGIN_FIND_STATUS_ERROR) { + throw Error {}; + } else if (status == BT_PLUGIN_FIND_STATUS_NOT_FOUND) { + return ConstPlugin::Shared {}; + } + + return ConstPlugin::Shared::createWithoutRef(plugin); +} + inline ConstPluginSet::Shared findAllPluginsFromDir(const bt2c::CStringView path, const bool recurse, const bool failOnLoadError) {