lib: remove unused includes
[babeltrace.git] / src / lib / plugin / plugin.c
index 16850d80ec2ab68bc8ca26c24138cdb4516e302d..8ee34e7fa6c7c4be37c0909184d9913336f9e9cf 100644 (file)
@@ -1,39 +1,22 @@
 /*
+ * SPDX-License-Identifier: MIT
+ *
  * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
  */
 
 #define BT_LOG_TAG "LIB/PLUGIN"
 #include "lib/logging.h"
 
 #include "common/assert.h"
-#include "lib/assert-pre.h"
+#include "lib/assert-cond.h"
 #include "common/macros.h"
 #include "compat/compiler.h"
+#include "compat/limits.h"
 #include "common/common.h"
-#include <babeltrace2/plugin/plugin-const.h>
-#include <babeltrace2/graph/component-class-const.h>
-#include <babeltrace2/current-thread.h>
+#include <babeltrace2/plugin/plugin-loading.h>
+#include <babeltrace2/graph/component-class.h>
+#include <babeltrace2/error-reporting.h>
 #include "lib/graph/component-class.h"
 #include <babeltrace2/types.h>
 #include <glib.h>
@@ -41,7 +24,6 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <inttypes.h>
 #include <sys/stat.h>
 #include <ftw.h>
 #include <pthread.h>
@@ -170,20 +152,23 @@ void fini_python_plugin_provider(void) {
 }
 #endif
 
+BT_EXPORT
 uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set *plugin_set)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin_set, "Plugin set");
+       BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set);
        return (uint64_t) plugin_set->plugins->len;
 }
 
+BT_EXPORT
 const struct bt_plugin *bt_plugin_set_borrow_plugin_by_index_const(
                const struct bt_plugin_set *plugin_set, uint64_t index)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin_set, "Plugin set");
+       BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set);
        BT_ASSERT_PRE_DEV_VALID_INDEX(index, plugin_set->plugins->len);
        return g_ptr_array_index(plugin_set->plugins, index);
 }
 
+BT_EXPORT
 enum bt_plugin_find_all_from_static_status bt_plugin_find_all_from_static(
                bt_bool fail_on_load_error,
                const struct bt_plugin_set **plugin_set_out)
@@ -195,6 +180,7 @@ enum bt_plugin_find_all_from_static_status bt_plugin_find_all_from_static(
                (void *) plugin_set_out);
 }
 
+BT_EXPORT
 enum bt_plugin_find_all_from_file_status bt_plugin_find_all_from_file(
                const char *path, bt_bool fail_on_load_error,
                const struct bt_plugin_set **plugin_set_out)
@@ -202,8 +188,8 @@ enum bt_plugin_find_all_from_file_status bt_plugin_find_all_from_file(
        enum bt_plugin_find_all_from_file_status status;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(path, "Path");
-       BT_ASSERT_PRE_NON_NULL(path, "Plugin set (output)");
+       BT_ASSERT_PRE_NON_NULL("path", path, "Path");
+       BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out);
        BT_LOGI("Creating plugins from file: path=\"%s\"", path);
 
        /* Try shared object plugins */
@@ -273,6 +259,7 @@ void destroy_gstring(void *data)
        g_string_free(data, TRUE);
 }
 
+BT_EXPORT
 enum bt_plugin_find_all_status bt_plugin_find_all(bt_bool find_in_std_env_var,
                bt_bool find_in_user_dir, bt_bool find_in_sys_dir,
                bt_bool find_in_static, bt_bool fail_on_load_error,
@@ -286,7 +273,7 @@ enum bt_plugin_find_all_status bt_plugin_find_all(bt_bool find_in_std_env_var,
        uint64_t dir_i, plugin_i;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(plugin_set_out, "Plugin set (output)");
+       BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out);
        BT_LOGI("Finding all plugins in standard directories and built-in plugins: "
                "find-in-std-env-var=%d, find-in-user-dir=%d, "
                "find-in-sys-dir=%d, find-in-static=%d",
@@ -460,6 +447,7 @@ end:
        return status;
 }
 
+BT_EXPORT
 enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
                bt_bool find_in_std_env_var, bt_bool find_in_user_dir,
                bt_bool find_in_sys_dir, bt_bool find_in_static,
@@ -470,8 +458,8 @@ enum bt_plugin_find_status bt_plugin_find(const char *plugin_name,
        uint64_t i;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(plugin_name, "Name");
-       BT_ASSERT_PRE_NON_NULL(plugin_out, "Plugin (output)");
+       BT_ASSERT_PRE_NAME_NON_NULL(plugin_name);
+       BT_ASSERT_PRE_PLUGIN_OUT_NON_NULL(plugin_out);
        BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
                "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, "
                "find-in-sys-dir=%d, find-in-static=%d",
@@ -526,7 +514,8 @@ static struct {
 
 static
 int nftw_append_all_from_dir(const char *file,
-               const struct stat *sb, int flag, struct FTW *s)
+               const struct stat *sb __attribute__((unused)),
+               int flag, struct FTW *s)
 {
        int ret = 0;
        const char *name = file + s->base;
@@ -664,6 +653,7 @@ end:
        return status;
 }
 
+BT_EXPORT
 enum bt_plugin_find_all_from_dir_status bt_plugin_find_all_from_dir(
                const char *path, bt_bool recurse, bt_bool fail_on_load_error,
                const struct bt_plugin_set **plugin_set_out)
@@ -672,7 +662,7 @@ enum bt_plugin_find_all_from_dir_status bt_plugin_find_all_from_dir(
                BT_FUNC_STATUS_OK;
 
        BT_ASSERT_PRE_NO_ERROR();
-       BT_ASSERT_PRE_NON_NULL(plugin_set_out, "Plugin set (output)");
+       BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out);
        BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
                path, recurse);
        *plugin_set_out = bt_plugin_set_create();
@@ -722,37 +712,43 @@ end:
        return status;
 }
 
+BT_EXPORT
 const char *bt_plugin_get_name(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return plugin->info.name_set ? plugin->info.name->str : NULL;
 }
 
+BT_EXPORT
 const char *bt_plugin_get_author(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return plugin->info.author_set ? plugin->info.author->str : NULL;
 }
 
+BT_EXPORT
 const char *bt_plugin_get_license(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return plugin->info.license_set ? plugin->info.license->str : NULL;
 }
 
+BT_EXPORT
 const char *bt_plugin_get_path(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return plugin->info.path_set ? plugin->info.path->str : NULL;
 }
 
+BT_EXPORT
 const char *bt_plugin_get_description(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return plugin->info.description_set ?
                plugin->info.description->str : NULL;
 }
 
+BT_EXPORT
 enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plugin,
                unsigned int *major, unsigned int *minor, unsigned int *patch,
                const char **extra)
@@ -760,7 +756,7 @@ enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plug
        enum bt_property_availability avail =
                BT_PROPERTY_AVAILABILITY_AVAILABLE;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
 
        if (!plugin->info.version_set) {
                BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin);
@@ -788,21 +784,24 @@ end:
        return avail;
 }
 
+BT_EXPORT
 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return (uint64_t) plugin->src_comp_classes->len;
 }
 
+BT_EXPORT
 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return (uint64_t) plugin->flt_comp_classes->len;
 }
 
+BT_EXPORT
 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin *plugin)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        return (uint64_t) plugin->sink_comp_classes->len;
 }
 
@@ -811,11 +810,12 @@ struct bt_component_class *borrow_component_class_by_index(
                const struct bt_plugin *plugin, GPtrArray *comp_classes,
                uint64_t index)
 {
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
        BT_ASSERT_PRE_DEV_VALID_INDEX(index, comp_classes->len);
        return g_ptr_array_index(comp_classes, index);
 }
 
+BT_EXPORT
 const struct bt_component_class_source *
 bt_plugin_borrow_source_component_class_by_index_const(
                const struct bt_plugin *plugin, uint64_t index)
@@ -824,6 +824,7 @@ bt_plugin_borrow_source_component_class_by_index_const(
                plugin->src_comp_classes, index);
 }
 
+BT_EXPORT
 const struct bt_component_class_filter *
 bt_plugin_borrow_filter_component_class_by_index_const(
                const struct bt_plugin *plugin, uint64_t index)
@@ -832,6 +833,7 @@ bt_plugin_borrow_filter_component_class_by_index_const(
                plugin->flt_comp_classes, index);
 }
 
+BT_EXPORT
 const struct bt_component_class_sink *
 bt_plugin_borrow_sink_component_class_by_index_const(
                const struct bt_plugin *plugin, uint64_t index)
@@ -848,8 +850,8 @@ struct bt_component_class *borrow_component_class_by_name(
        struct bt_component_class *comp_class = NULL;
        size_t i;
 
-       BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin");
-       BT_ASSERT_PRE_DEV_NON_NULL(name, "Name");
+       BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin);
+       BT_ASSERT_PRE_DEV_NAME_NON_NULL(name);
 
        for (i = 0; i < comp_classes->len; i++) {
                struct bt_component_class *comp_class_candidate =
@@ -868,6 +870,7 @@ struct bt_component_class *borrow_component_class_by_name(
        return comp_class;
 }
 
+BT_EXPORT
 const struct bt_component_class_source *
 bt_plugin_borrow_source_component_class_by_name_const(
                const struct bt_plugin *plugin, const char *name)
@@ -876,6 +879,7 @@ bt_plugin_borrow_source_component_class_by_name_const(
                plugin->src_comp_classes, name);
 }
 
+BT_EXPORT
 const struct bt_component_class_filter *
 bt_plugin_borrow_filter_component_class_by_name_const(
                const struct bt_plugin *plugin, const char *name)
@@ -884,6 +888,7 @@ bt_plugin_borrow_filter_component_class_by_name_const(
                plugin->flt_comp_classes, name);
 }
 
+BT_EXPORT
 const struct bt_component_class_sink *
 bt_plugin_borrow_sink_component_class_by_name_const(
                const struct bt_plugin *plugin, const char *name)
@@ -892,21 +897,25 @@ bt_plugin_borrow_sink_component_class_by_name_const(
                plugin->sink_comp_classes, name);
 }
 
+BT_EXPORT
 void bt_plugin_get_ref(const struct bt_plugin *plugin)
 {
        bt_object_get_ref(plugin);
 }
 
+BT_EXPORT
 void bt_plugin_put_ref(const struct bt_plugin *plugin)
 {
        bt_object_put_ref(plugin);
 }
 
+BT_EXPORT
 void bt_plugin_set_get_ref(const struct bt_plugin_set *plugin_set)
 {
        bt_object_get_ref(plugin_set);
 }
 
+BT_EXPORT
 void bt_plugin_set_put_ref(const struct bt_plugin_set *plugin_set)
 {
        bt_object_put_ref(plugin_set);
This page took 0.027535 seconds and 4 git commands to generate.