Warn on duplicate component class registration
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 24 Feb 2016 23:01:34 +0000 (18:01 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:26 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/component-factory.h
lib/plugin-system/component-factory.c

index c3190cb1f6df1efe4f11336c10606a4bdbb73098..a04ee3d1ee63d84a4cc0bbf381e194c8e4400d25 100644 (file)
@@ -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,
 
index 6d76029170232457f515cbb730ee6d68ba86b1fc..0952f461561a6a297575602a646bdbc8a48e9c6b 100644 (file)
@@ -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;
 }
This page took 0.025779 seconds and 4 git commands to generate.