cpp-common/bt2: add `findPlugin()`
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 16 Feb 2024 20:42:59 +0000 (15:42 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 29 Feb 2024 23:46:23 +0000 (18:46 -0500)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11823
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
src/cpp-common/bt2/plugin-load.hpp

index 0f3e8d5e79442bdaad7a88bb3b9398d95ef8c2b3..00b0510c70a47729456e335e8e0575dab3c98960 100644 (file)
 
 #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)
 {
This page took 0.024301 seconds and 4 git commands to generate.