X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fplugin%2Fplugin.h;h=ba4f45516ed921a2e58c36192aa8a588939a89c4;hb=577fa92f184fd2d75fb0697e879ab563de117c2e;hp=46b2b117be7b9b089db11687f2fad155c4c88b0f;hpb=9736d991ea189f29b908e9cf18103c1452c59e05;p=babeltrace.git diff --git a/src/lib/plugin/plugin.h b/src/lib/plugin/plugin.h index 46b2b117..ba4f4551 100644 --- a/src/lib/plugin/plugin.h +++ b/src/lib/plugin/plugin.h @@ -34,6 +34,7 @@ #include #include "plugin-so.h" +#include "lib/func-status.h" /* Protection: this file uses BT_LIB_LOG*() macros directly */ #ifndef BT_LIB_LOG_SUPPORTED @@ -87,25 +88,6 @@ struct bt_plugin_set { GPtrArray *plugins; }; -static inline -const char *bt_plugin_status_string(enum bt_plugin_status status) -{ - switch (status) { - case BT_PLUGIN_STATUS_OK: - return "BT_PLUGIN_STATUS_OK"; - case BT_PLUGIN_STATUS_NOT_FOUND: - return "BT_PLUGIN_STATUS_NOT_FOUND"; - case BT_PLUGIN_STATUS_ERROR: - return "BT_PLUGIN_STATUS_ERROR"; - case BT_PLUGIN_STATUS_LOADING_ERROR: - return "BT_PLUGIN_STATUS_LOADING_ERROR"; - case BT_PLUGIN_STATUS_NOMEM: - return "BT_PLUGIN_STATUS_NOMEM"; - default: - return "(unknown)"; - } -} - static inline const char *bt_plugin_type_string(enum bt_plugin_type type) { @@ -193,7 +175,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; } @@ -205,7 +187,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; } @@ -213,7 +195,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; } @@ -221,44 +203,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; } @@ -347,7 +329,7 @@ void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major, } static inline -enum bt_plugin_status bt_plugin_add_component_class( +int bt_plugin_add_component_class( struct bt_plugin *plugin, struct bt_component_class *comp_class) { GPtrArray *comp_classes; @@ -369,6 +351,11 @@ enum bt_plugin_status bt_plugin_add_component_class( abort(); } + /* Set component class's original plugin name */ + BT_ASSERT(comp_class->plugin_name); + BT_ASSERT(plugin->info.name); + g_string_assign(comp_class->plugin_name, plugin->info.name->str); + /* Add new component class */ bt_object_get_ref(comp_class); g_ptr_array_add(comp_classes, comp_class); @@ -380,7 +367,7 @@ enum bt_plugin_status bt_plugin_add_component_class( BT_LIB_LOGD("Added component class to plugin: " "%![plugin-]+l, %![cc-]+C", plugin, comp_class); - return BT_PLUGIN_STATUS_OK; + return BT_FUNC_STATUS_OK; } static @@ -418,7 +405,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; } @@ -429,17 +416,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 */