From 0859fe1f68b54169b22779655210a9759c471532 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 24 Feb 2016 18:01:34 -0500 Subject: [PATCH] Warn on duplicate component class registration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/babeltrace/plugin/component-factory.h | 3 ++ lib/plugin-system/component-factory.c | 30 ++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/include/babeltrace/plugin/component-factory.h b/include/babeltrace/plugin/component-factory.h index c3190cb1f..a04ee3d1e 100644 --- a/include/babeltrace/plugin/component-factory.h +++ b/include/babeltrace/plugin/component-factory.h @@ -43,6 +43,9 @@ enum bt_component_factory_status { /** General error. */ BT_COMPONENT_FACTORY_STATUS_ERROR = -128, + /** Duplicate component class being registered. */ + BT_COMPONENT_FACTORY_STATUS_DUPLICATE = -7, + /** Invalid plugin. */ BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN = -6, diff --git a/lib/plugin-system/component-factory.c b/lib/plugin-system/component-factory.c index 6d7602917..0952f4615 100644 --- a/lib/plugin-system/component-factory.c +++ b/lib/plugin-system/component-factory.c @@ -400,17 +400,39 @@ add_component_class(struct bt_component_factory *factory, const char *name, const char *description, bt_component_init_cb init, enum bt_component_type type) { - struct bt_component_class *class; + struct bt_component_class *component_class; enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; if (!factory || !name || !init) { ret = BT_COMPONENT_FACTORY_STATUS_INVAL; goto end; } + assert(factory->current_plugin); - class = bt_component_class_create(type, name, description, - factory->current_plugin); - g_ptr_array_add(factory->component_classes, class); + /* + * Ensure this component class does not clash with a currently + * registered class. + */ + component_class = bt_component_factory_get_component_class(factory, + bt_plugin_get_name(factory->current_plugin), type, name); + if (component_class) { + struct bt_plugin *plugin = bt_component_class_get_plugin( + component_class); + + printf_warning("Duplicate component class registration attempted. Component class %s being registered by plugin %s (path: %s) conflicts with one already registered by plugin %s (path: %s)", + name, bt_plugin_get_name(factory->current_plugin), + bt_plugin_get_path(factory->current_plugin), + bt_plugin_get_name(plugin), + bt_plugin_get_path(plugin)); + ret = BT_COMPONENT_FACTORY_STATUS_DUPLICATE; + BT_PUT(component_class); + bt_put(plugin); + goto end; + } + + component_class = bt_component_class_create(type, name, description, + factory->current_plugin); + g_ptr_array_add(factory->component_classes, component_class); end: return ret; } -- 2.34.1