X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fcpp-common%2Fbt2%2Fplugin-load.hpp;h=00b0510c70a47729456e335e8e0575dab3c98960;hb=98701909c49b8d6433d9991b2cbe48f7514d047e;hp=0f3e8d5e79442bdaad7a88bb3b9398d95ef8c2b3;hpb=3641e3ec94edca0ecb4d5a7675d2ec5ae4804cff;p=babeltrace.git 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) {