lib: keep plugin name, if any, in component class structure
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 19 Jun 2019 21:08:09 +0000 (17:08 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 6 Jul 2019 03:47:50 +0000 (23:47 -0400)
This is to make the plugin name available when having a component class
object in an upcoming error reporting API.

We don't keep the `bt_plugin` object itself because it's a component
class's owner, and a component class can outlive its containing plugin:
only the shared object data is kept alive in that case.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I9cfbac32d88a6e7edac238b5a63b232695613b8c
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1523
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
src/lib/graph/component-class.c
src/lib/graph/component-class.h
src/lib/plugin/plugin.h

index 9d7e17b57bbb447b1a8be8d3a19246e515fdf4be..d17dbd4c1c5192fdb22a837351b3eddfb83280f5 100644 (file)
@@ -83,6 +83,11 @@ void destroy_component_class(struct bt_object *obj)
                class->help = NULL;
        }
 
+       if (class->plugin_name) {
+               g_string_free(class->plugin_name, TRUE);
+               class->plugin_name = NULL;
+       }
+
        if (class->destroy_listeners) {
                g_array_free(class->destroy_listeners, TRUE);
                class->destroy_listeners = NULL;
@@ -117,6 +122,12 @@ int bt_component_class_init(struct bt_component_class *class,
                goto error;
        }
 
+       class->plugin_name = g_string_new(NULL);
+       if (!class->plugin_name) {
+               BT_LOGE_STR("Failed to allocate a GString.");
+               goto error;
+       }
+
        class->destroy_listeners = g_array_new(FALSE, TRUE,
                sizeof(struct bt_component_class_destroy_listener));
        if (!class->destroy_listeners) {
index bded3328a3981eb0e0a0f85ac822de128d2f2cbf..c6757ed3080dd6f3ab3d230743d0123f5b45ca3c 100644 (file)
@@ -54,6 +54,7 @@ struct bt_component_class {
        GString *name;
        GString *description;
        GString *help;
+       GString *plugin_name;
 
        /* Array of struct bt_component_class_destroy_listener */
        GArray *destroy_listeners;
index 202c69bede6cee35272eec13c569059d909abaf1..417d116c436fe609ddb3e78a0708da60f4867eee 100644 (file)
@@ -351,6 +351,11 @@ int 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);
This page took 0.026034 seconds and 4 git commands to generate.