cpp-common/bt2: add `findPlugin()`
[babeltrace.git] / 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.023662 seconds and 4 git commands to generate.