Document libbabeltrace2's C API
[babeltrace.git] / src / lib / plugin / plugin.h
index 417d116c436fe609ddb3e78a0708da60f4867eee..5f8e6b11dbd0650ea1dfe132712ef0ebb8d54de3 100644 (file)
  */
 
 #include "common/macros.h"
+#include "common/common.h"
 #include "lib/graph/component-class.h"
-#include <babeltrace2/plugin/plugin-const.h>
+#include <babeltrace2/plugin/plugin-loading.h>
 #include <babeltrace2/plugin/plugin-dev.h>
 #include "lib/object.h"
 #include <babeltrace2/types.h>
 #include "common/assert.h"
 #include <glib.h>
+#include <stdbool.h>
 
 #include "plugin-so.h"
 #include "lib/func-status.h"
@@ -93,9 +95,9 @@ const char *bt_plugin_type_string(enum bt_plugin_type type)
 {
        switch (type) {
        case BT_PLUGIN_TYPE_SO:
-               return "BT_PLUGIN_TYPE_SO";
+               return "SO";
        case BT_PLUGIN_TYPE_PYTHON:
-               return "BT_PLUGIN_TYPE_PYTHON";
+               return "PYTHON";
        default:
                return "(unknown)";
        }
@@ -175,7 +177,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
 
        plugin = g_new0(struct bt_plugin, 1);
        if (!plugin) {
-               BT_LOGE_STR("Failed to allocate one plugin.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one plugin.");
                goto error;
        }
 
@@ -187,7 +189,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->src_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -195,7 +197,7 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->flt_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
@@ -203,44 +205,44 @@ struct bt_plugin *bt_plugin_create_empty(enum bt_plugin_type type)
                g_ptr_array_new_with_free_func(
                        (GDestroyNotify) bt_object_put_ref);
        if (!plugin->sink_comp_classes) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                goto error;
        }
 
        /* Create empty info */
        plugin->info.name = g_string_new(NULL);
        if (!plugin->info.name) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.path = g_string_new(NULL);
        if (!plugin->info.path) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.description = g_string_new(NULL);
        if (!plugin->info.description) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.author = g_string_new(NULL);
        if (!plugin->info.author) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.license = g_string_new(NULL);
        if (!plugin->info.license) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
        plugin->info.version.extra = g_string_new(NULL);
        if (!plugin->info.version.extra) {
-               BT_LOGE_STR("Failed to allocate a GString.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
                goto error;
        }
 
@@ -348,7 +350,7 @@ int bt_plugin_add_component_class(
                comp_classes = plugin->sink_comp_classes;
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 
        /* Set component class's original plugin name */
@@ -405,7 +407,7 @@ struct bt_plugin_set *bt_plugin_set_create(void)
        plugin_set->plugins = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_put_ref);
        if (!plugin_set->plugins) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
                goto end;
        }
@@ -416,17 +418,49 @@ end:
        return plugin_set;
 }
 
+static inline
+bool bt_plugin_set_contains_plugin(struct bt_plugin_set *plugin_set,
+               const char *name)
+{
+       uint64_t i;
+       bool contains = false;
+
+       BT_ASSERT(plugin_set);
+       BT_ASSERT(name);
+
+       for (i = 0; i < plugin_set->plugins->len; i++) {
+               const struct bt_plugin *plugin = plugin_set->plugins->pdata[i];
+
+               if (strcmp(plugin->info.name->str, name) == 0) {
+                       contains = true;
+                       goto end;
+               }
+       }
+
+end:
+       return contains;
+}
+
 static inline
 void bt_plugin_set_add_plugin(struct bt_plugin_set *plugin_set,
                struct bt_plugin *plugin)
 {
        BT_ASSERT(plugin_set);
        BT_ASSERT(plugin);
+
+       if (bt_plugin_set_contains_plugin(plugin_set,
+                       plugin->info.name->str)) {
+               goto end;
+       }
+
        bt_object_get_ref(plugin);
        g_ptr_array_add(plugin_set->plugins, plugin);
        BT_LIB_LOGD("Added plugin to plugin set: "
                "plugin-set-addr=%p, %![plugin-]+l",
                plugin_set, plugin);
+
+end:
+       return;
 }
 
 #endif /* BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H */
This page took 0.026663 seconds and 4 git commands to generate.