2 * Copyright (c) 2024 EfficiOS, Inc.
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP
10 #include <babeltrace2/babeltrace.h>
12 #include "common/common.h"
13 #include "cpp-common/bt2c/c-string-view.hpp"
16 #include "plugin-set.hpp"
21 inline ConstPlugin::Shared
22 findPlugin(const bt2c::CStringView name, const bool findInStdEnvVar = true,
23 const bool findInUserDir = true, const bool findInSysDir = true,
24 const bool findInStatic = true, const bool failOnLoadError = false)
26 const bt_plugin *plugin;
27 const auto status = bt_plugin_find(name, findInStdEnvVar, findInUserDir, findInSysDir,
28 findInStatic, failOnLoadError, &plugin);
30 if (status == BT_PLUGIN_FIND_STATUS_MEMORY_ERROR) {
32 } else if (status == BT_PLUGIN_FIND_STATUS_ERROR) {
34 } else if (status == BT_PLUGIN_FIND_STATUS_NOT_FOUND) {
35 return ConstPlugin::Shared {};
38 return ConstPlugin::Shared::createWithoutRef(plugin);
41 inline ConstPluginSet::Shared findAllPluginsFromFile(const bt2c::CStringView path,
42 const bool failOnLoadError)
44 const bt_plugin_set *pluginSet;
46 switch (bt_plugin_find_all_from_file(path, failOnLoadError, &pluginSet)) {
47 case BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_OK:
48 return ConstPluginSet::Shared::createWithoutRef(pluginSet);
49 case BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_NOT_FOUND:
50 return ConstPluginSet::Shared {};
51 case BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_MEMORY_ERROR:
53 case BT_PLUGIN_FIND_ALL_FROM_FILE_STATUS_ERROR:
60 inline ConstPluginSet::Shared findAllPluginsFromDir(const bt2c::CStringView path,
61 const bool recurse, const bool failOnLoadError)
63 const bt_plugin_set *pluginSet;
65 switch (bt_plugin_find_all_from_dir(path, recurse, failOnLoadError, &pluginSet)) {
66 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK:
67 return ConstPluginSet::Shared::createWithoutRef(pluginSet);
68 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND:
69 return ConstPluginSet::Shared {};
70 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR:
72 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR:
81 #endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP */