X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Flib%2Fplugin%2Fplugin.h;h=7ab4170dfa97e445dc8c87f0d811db22b8715135;hp=d7f2d68fcbbc0d79685152f878a8e0bd8d915029;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=91d8147391efdc4d42cc4e1c171a65c0372a008f diff --git a/src/lib/plugin/plugin.h b/src/lib/plugin/plugin.h index d7f2d68f..7ab4170d 100644 --- a/src/lib/plugin/plugin.h +++ b/src/lib/plugin/plugin.h @@ -1,52 +1,37 @@ -#ifndef BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H -#define BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H - /* + * SPDX-License-Identifier: MIT + * * Copyright 2017-2018 Philippe Proulx * Copyright 2015 Jérémie Galarneau - * - * 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. */ +#ifndef BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H +#define BABELTRACE_PLUGIN_PLUGIN_INTERNAL_H + #include "common/macros.h" +#include "common/common.h" #include "lib/graph/component-class.h" -#include +#include #include #include "lib/object.h" #include #include "common/assert.h" -#include "lib/lib-logging.h" #include +#include #include "plugin-so.h" +#include "lib/func-status.h" + +/* Protection: this file uses BT_LIB_LOG*() macros directly */ +#ifndef BT_LIB_LOG_SUPPORTED +# error Please include "lib/logging.h" before including this file. +#endif enum bt_plugin_type { BT_PLUGIN_TYPE_SO = 0, BT_PLUGIN_TYPE_PYTHON = 1, }; -enum bt_plugin_status { - BT_PLUGIN_STATUS_OK = 0, - BT_PLUGIN_STATUS_ERROR = -1, - BT_PLUGIN_STATUS_NOMEM = -12, -}; - struct bt_plugin { struct bt_object base; enum bt_plugin_type type; @@ -89,29 +74,14 @@ 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_ERROR: - return "BT_PLUGIN_STATUS_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) { 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)"; } @@ -124,7 +94,7 @@ void bt_plugin_destroy(struct bt_object *obj) BT_ASSERT(obj); plugin = container_of(obj, struct bt_plugin, base); - BT_LIB_LOGD("Destroying plugin object: %!+l", plugin); + BT_LIB_LOGI("Destroying plugin object: %!+l", plugin); if (plugin->destroy_spec_data) { plugin->destroy_spec_data(plugin); @@ -191,7 +161,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; } @@ -203,7 +173,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; } @@ -211,7 +181,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; } @@ -219,44 +189,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; } @@ -277,7 +247,7 @@ void bt_plugin_set_path(struct bt_plugin *plugin, const char *path) BT_ASSERT(path); g_string_assign(plugin->info.path, path); plugin->info.path_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's path: %![plugin-]+l, path=\"%s\"", + BT_LIB_LOGD("Set plugin's path: %![plugin-]+l, path=\"%s\"", plugin, path); } @@ -288,7 +258,7 @@ void bt_plugin_set_name(struct bt_plugin *plugin, const char *name) BT_ASSERT(name); g_string_assign(plugin->info.name, name); plugin->info.name_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's name: %![plugin-]+l, name=\"%s\"", + BT_LIB_LOGD("Set plugin's name: %![plugin-]+l, name=\"%s\"", plugin, name); } @@ -300,7 +270,7 @@ void bt_plugin_set_description(struct bt_plugin *plugin, BT_ASSERT(description); g_string_assign(plugin->info.description, description); plugin->info.description_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's description: %![plugin-]+l", plugin); + BT_LIB_LOGD("Set plugin's description: %![plugin-]+l", plugin); } static inline @@ -310,7 +280,7 @@ void bt_plugin_set_author(struct bt_plugin *plugin, const char *author) BT_ASSERT(author); g_string_assign(plugin->info.author, author); plugin->info.author_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's author: %![plugin-]+l, author=\"%s\"", + BT_LIB_LOGD("Set plugin's author: %![plugin-]+l, author=\"%s\"", plugin, author); } @@ -321,7 +291,7 @@ void bt_plugin_set_license(struct bt_plugin *plugin, const char *license) BT_ASSERT(license); g_string_assign(plugin->info.license, license); plugin->info.license_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's path: %![plugin-]+l, license=\"%s\"", + BT_LIB_LOGD("Set plugin's path: %![plugin-]+l, license=\"%s\"", plugin, license); } @@ -339,13 +309,13 @@ void bt_plugin_set_version(struct bt_plugin *plugin, unsigned int major, } plugin->info.version_set = BT_TRUE; - BT_LIB_LOGV("Set plugin's version: %![plugin-]+l, " + BT_LIB_LOGD("Set plugin's version: %![plugin-]+l, " "major=%u, minor=%u, patch=%u, extra=\"%s\"", plugin, major, minor, patch, extra); } 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; @@ -364,9 +334,14 @@ enum bt_plugin_status bt_plugin_add_component_class( comp_classes = plugin->sink_comp_classes; break; default: - abort(); + bt_common_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); @@ -378,7 +353,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 @@ -416,7 +391,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; } @@ -427,17 +402,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_LOGV("Added plugin to plugin set: " + 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 */