cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / cpp-common / bt2 / plugin-load.hpp
1 /*
2 * Copyright (c) 2024 EfficiOS, Inc.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP
9
10 #include <babeltrace2/babeltrace.h>
11
12 #include "common/common.h"
13 #include "cpp-common/bt2c/c-string-view.hpp"
14
15 #include "exc.hpp"
16 #include "plugin-set.hpp"
17 #include "plugin.hpp"
18
19 namespace bt2 {
20
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
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
62 #endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_LOAD_HPP */
This page took 0.030559 seconds and 4 git commands to generate.