Commit | Line | Data |
---|---|---|
785712e1 SM |
1 | /* |
2 | * Copyright (c) 2024 EfficiOS, Inc. | |
3 | * | |
4 | * SPDX-License-Identifier: MIT | |
5 | */ | |
6 | ||
c40b7b8a SM |
7 | #ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP |
8 | #define BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP | |
785712e1 SM |
9 | |
10 | #include <babeltrace2/babeltrace.h> | |
11 | ||
12 | #include "common/common.h" | |
785712e1 SM |
13 | #include "cpp-common/bt2c/c-string-view.hpp" |
14 | ||
4993dc41 SM |
15 | #include "exc.hpp" |
16 | #include "plugin-set.hpp" | |
98701909 | 17 | #include "plugin.hpp" |
785712e1 | 18 | |
4993dc41 | 19 | namespace bt2 { |
785712e1 | 20 | |
98701909 SM |
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) | |
25 | { | |
26 | const bt_plugin *plugin; | |
27 | const auto status = bt_plugin_find(name, findInStdEnvVar, findInUserDir, findInSysDir, | |
28 | findInStatic, failOnLoadError, &plugin); | |
29 | ||
30 | if (status == BT_PLUGIN_FIND_STATUS_MEMORY_ERROR) { | |
31 | throw MemoryError {}; | |
32 | } else if (status == BT_PLUGIN_FIND_STATUS_ERROR) { | |
33 | throw Error {}; | |
34 | } else if (status == BT_PLUGIN_FIND_STATUS_NOT_FOUND) { | |
35 | return ConstPlugin::Shared {}; | |
36 | } | |
37 | ||
38 | return ConstPlugin::Shared::createWithoutRef(plugin); | |
39 | } | |
40 | ||
785712e1 SM |
41 | inline ConstPluginSet::Shared findAllPluginsFromDir(const bt2c::CStringView path, |
42 | const bool recurse, const bool failOnLoadError) | |
43 | { | |
44 | const bt_plugin_set *pluginSet; | |
45 | ||
46 | switch (bt_plugin_find_all_from_dir(path, recurse, failOnLoadError, &pluginSet)) { | |
47 | case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK: | |
48 | return ConstPluginSet::Shared::createWithoutRef(pluginSet); | |
49 | case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND: | |
50 | return ConstPluginSet::Shared {}; | |
51 | case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR: | |
52 | throw MemoryError {}; | |
53 | case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR: | |
54 | throw Error {}; | |
55 | } | |
56 | ||
57 | bt_common_abort(); | |
58 | } | |
59 | ||
60 | } /* namespace bt2 */ | |
61 | ||
c40b7b8a | 62 | #endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP */ |