2 * Copyright (c) 2024 EfficiOS, Inc.
4 * SPDX-License-Identifier: MIT
7 #ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP
8 #define BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP
10 #include <babeltrace2/babeltrace.h>
12 #include "common/common.h"
13 #include "cpp-common/bt2/borrowed-object.hpp"
14 #include "cpp-common/bt2/exc.hpp"
15 #include "cpp-common/bt2/shared-object.hpp"
16 #include "cpp-common/bt2c/c-string-view.hpp"
21 struct PluginSetRefFuncs
23 static void get(const bt_plugin_set * const libObjPtr) noexcept
25 bt_plugin_set_get_ref(libObjPtr);
28 static void put(const bt_plugin_set * const libObjPtr) noexcept
30 bt_plugin_set_put_ref(libObjPtr);
34 } /* namespace internal */
36 class ConstPluginSet final : public BorrowedObject<const bt_plugin_set>
39 using Shared = SharedObject<ConstPluginSet, const bt_plugin_set, internal::PluginSetRefFuncs>;
41 explicit ConstPluginSet(const bt_plugin_set * const plugin_set) :
42 _ThisBorrowedObject {plugin_set}
46 std::uint64_t length() const noexcept
48 return bt_plugin_set_get_plugin_count(this->libObjPtr());
52 inline ConstPluginSet::Shared findAllPluginsFromDir(const bt2c::CStringView path,
53 const bool recurse, const bool failOnLoadError)
55 const bt_plugin_set *pluginSet;
57 switch (bt_plugin_find_all_from_dir(path, recurse, failOnLoadError, &pluginSet)) {
58 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK:
59 return ConstPluginSet::Shared::createWithoutRef(pluginSet);
60 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND:
61 return ConstPluginSet::Shared {};
62 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR:
64 case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR:
73 #endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP */