cpp-common/bt2: add basic PluginSet and bt_plugin_find_all_from_dir wrappers
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 15 Jan 2024 21:19:24 +0000 (16:19 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:38:19 +0000 (11:38 -0500)
Add a `bt2::PluginSet` class, wrapping `bt_plugin_set`.  It only
contains what I need for a test coming in a subsequent patch.

Add a `bt2::findAllPluginsFromDir` function, wrapping
`bt_plugin_find_all_from_dir`.

Change-Id: Ieca897dec5c08381deb473e701f7e41aee84e89c
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11680
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/Makefile.am
src/cpp-common/bt2/plugin.hpp [new file with mode: 0644]

index a2b3aa0a630d354cbf96723111d84756b2f26a58..dc046d9eab4b826e8e86947327f7a874c1f195be 100644 (file)
@@ -31,6 +31,7 @@ noinst_HEADERS = \
        cpp-common/bt2/message.hpp \
        cpp-common/bt2/optional-borrowed-object.hpp \
        cpp-common/bt2/plugin-dev.hpp \
+       cpp-common/bt2/plugin.hpp \
        cpp-common/bt2/private-query-executor.hpp \
        cpp-common/bt2/raw-value-proxy.hpp \
        cpp-common/bt2/self-component-class.hpp \
diff --git a/src/cpp-common/bt2/plugin.hpp b/src/cpp-common/bt2/plugin.hpp
new file mode 100644 (file)
index 0000000..0a1c1c4
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2024 EfficiOS, Inc.
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP
+#define BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP
+
+#include <babeltrace2/babeltrace.h>
+
+#include "common/common.h"
+#include "cpp-common/bt2/borrowed-object.hpp"
+#include "cpp-common/bt2/exc.hpp"
+#include "cpp-common/bt2/shared-object.hpp"
+#include "cpp-common/bt2c/c-string-view.hpp"
+
+namespace bt2 {
+namespace internal {
+
+struct PluginSetRefFuncs
+{
+    static void get(const bt_plugin_set * const libObjPtr) noexcept
+    {
+        bt_plugin_set_get_ref(libObjPtr);
+    }
+
+    static void put(const bt_plugin_set * const libObjPtr) noexcept
+    {
+        bt_plugin_set_put_ref(libObjPtr);
+    }
+};
+
+} /* namespace internal */
+
+class ConstPluginSet final : public BorrowedObject<const bt_plugin_set>
+{
+public:
+    using Shared = SharedObject<ConstPluginSet, const bt_plugin_set, internal::PluginSetRefFuncs>;
+
+    explicit ConstPluginSet(const bt_plugin_set * const plugin_set) :
+        _ThisBorrowedObject {plugin_set}
+    {
+    }
+
+    std::uint64_t length() const noexcept
+    {
+        return bt_plugin_set_get_plugin_count(this->libObjPtr());
+    }
+};
+
+inline ConstPluginSet::Shared findAllPluginsFromDir(const bt2c::CStringView path,
+                                                    const bool recurse, const bool failOnLoadError)
+{
+    const bt_plugin_set *pluginSet;
+
+    switch (bt_plugin_find_all_from_dir(path, recurse, failOnLoadError, &pluginSet)) {
+    case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_OK:
+        return ConstPluginSet::Shared::createWithoutRef(pluginSet);
+    case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_NOT_FOUND:
+        return ConstPluginSet::Shared {};
+    case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_MEMORY_ERROR:
+        throw MemoryError {};
+    case BT_PLUGIN_FIND_ALL_FROM_DIR_STATUS_ERROR:
+        throw Error {};
+    }
+
+    bt_common_abort();
+}
+
+} /* namespace bt2 */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2_PLUGIN_HPP */
This page took 0.025887 seconds and 4 git commands to generate.