List detected component classes
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 17 Feb 2016 22:01:31 +0000 (17: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>
19 files changed:
converter/babeltrace.c
include/babeltrace/plugin/component-class-internal.h
include/babeltrace/plugin/component-class.h
include/babeltrace/plugin/component-factory.h
include/babeltrace/plugin/component-internal.h
include/babeltrace/plugin/component.h
include/babeltrace/plugin/plugin-internal.h
include/babeltrace/plugin/plugin-macros.h
include/babeltrace/plugin/plugin-system.h
include/babeltrace/plugin/plugin.h
include/babeltrace/plugin/sink-internal.h
include/babeltrace/plugin/source-internal.h
plugins/component-class.c
plugins/component-factory.c
plugins/component.c
plugins/ctf/text/text.c
plugins/plugin.c
plugins/sink.c
plugins/source.c

index 892096d1fd4ca08ff65fc4617ae5422bb54a4a32..3081f1f074601d4ce96337e04c9215f0193bc0a0 100644 (file)
@@ -40,6 +40,8 @@
 
 #include <babeltrace/iterator.h>
 #include <babeltrace/plugin/component-factory.h>
+#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/component-class.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/values.h>
 #include <popt.h>
@@ -719,13 +721,74 @@ error_iter:
        return ret;
 }
 
-void call_plugins_hooks(void)
+static
+const char *component_type_str(enum bt_component_type type)
+{
+       switch (type) {
+       case BT_COMPONENT_TYPE_SOURCE:
+               return "source";
+       case BT_COMPONENT_TYPE_SINK:
+               return "sink";
+       case BT_COMPONENT_TYPE_FILTER:
+               return "filter";
+       case BT_COMPONENT_TYPE_UNKNOWN:
+       default:
+               return "unknown";
+       }
+}
+
+static
+void print_detected_component_classes(struct bt_component_factory *factory)
+{
+       int count, i;
+
+       if (!babeltrace_verbose) {
+               return;
+       }
+
+       count = bt_component_factory_get_component_class_count(factory);
+       if (count <= 0) {
+               fprintf(stderr, "No component classes found. Please make sure your plug-in search path is set correctly.");
+               return;
+       }
+
+       printf_verbose("Found %d component classes.\n", count);
+       for (i = 0; i < count; i++) {
+               struct bt_component_class *component_class =
+                               bt_component_factory_get_component_class_index(
+                               factory, i);
+               struct bt_plugin *plugin = bt_component_class_get_plugin(
+                               component_class);
+               const char *plugin_name = bt_plugin_get_name(plugin);
+               const char *component_name = bt_component_class_get_name(
+                               component_class);
+               const char *path = bt_plugin_get_path(plugin);
+               const char *author = bt_plugin_get_author(plugin);
+               const char *license = bt_plugin_get_license(plugin);
+               const char *plugin_description = bt_plugin_get_description(
+                               plugin);
+               const char *component_description =
+                               bt_component_class_get_description(
+                                       component_class);
+               enum bt_component_type type = bt_component_class_get_type(
+                               component_class);
+
+               printf_verbose("[%s - %s (%s)]\n", plugin_name, component_name,
+                              component_type_str(type));
+               printf_verbose("\tpath: %s\n", path);
+               printf_verbose("\tauthor: %s\n", author);
+               printf_verbose("\tlicense: %s\n", license);
+               printf_verbose("\tplugin description: %s\n",
+                               plugin_description ? plugin_description : "None");
+               printf_verbose("\tcomponent description: %s\n",
+                               component_description ? component_description : "None");
+       }
+}
+
+static
+void test_sink_notifications(struct bt_component *sink)
 {
-       bt_dummy_hook();
-       bt_lttng_live_hook();
-       bt_ctf_hook();
-       bt_ctf_text_hook();
-       bt_ctf_metadata_hook();
+       return;
 }
 
 int main(int argc, char **argv)
@@ -734,8 +797,11 @@ int main(int argc, char **argv)
        struct bt_format *fmt_write;
        struct bt_trace_descriptor *td_write;
        struct bt_context *ctx;
-       struct bt_component_factory *component_factory;
-       struct bt_value *components = NULL;
+       struct bt_component_factory *component_factory = NULL;
+       struct bt_component_class *source_class = NULL;
+       struct bt_component_class *sink_class = NULL;
+       struct bt_component *source = NULL, *sink = NULL;
+       struct bt_value *source_params = NULL, *sink_params = NULL;
        int i;
 
        call_plugins_hooks();
@@ -760,7 +826,7 @@ int main(int argc, char **argv)
                ret = -1;
                goto end;
        }
-       printf_verbose("Looking-up plugins at %s",
+       printf_verbose("Looking-up plugins at %s\n",
                        opt_plugin_path ? opt_plugin_path : "Invalid");
        component_factory = bt_component_factory_create();
        if (!component_factory) {
@@ -775,11 +841,26 @@ int main(int argc, char **argv)
                goto end;
        }
 
-       ret = bt_component_factory_get_component_class_count(component_factory);
-       if (ret <= 0) {
+       print_detected_component_classes(component_factory);
+
+       sink_class = bt_component_factory_get_component_class(component_factory,
+                       NULL, BT_COMPONENT_TYPE_SINK, "text");
+       if (!sink_class) {
+               fprintf(stderr, "Could not find text output component class. Aborting...\n");
+               ret = -1;
+               goto end;
+       }
+
+       sink = bt_component_create(sink_class, "bt_text_output", sink_params);
+       if (!sink) {
+               fprintf(stderr, "Failed to instanciate text output. Aborting...\n");
+               ret = -1;
                goto end;
        }
 
+       test_sink_notifications(sink);
+       goto end;
+
        if (opt_input_paths->len == 0) {
                ret = -1;
                goto end;
@@ -915,8 +996,14 @@ end:
        free(opt_debug_info_dir);
        free(opt_debug_info_target_prefix);
        g_ptr_array_free(opt_input_paths, TRUE);
-       BT_PUT(components);
        BT_PUT(component_factory);
+       BT_PUT(sink_class);
+       BT_PUT(source_class);
+       BT_PUT(source);
+       BT_PUT(sink);
+       BT_PUT(source_params);
+       BT_PUT(sink_params);
+
        if (partial_error)
                exit(EXIT_FAILURE);
        else
index efdf991b520283b58d72e287c01d9798cc710f24..f23f256672b0655e97d397e5d5af60783e157f0e 100644 (file)
@@ -36,6 +36,7 @@ struct bt_component_class {
        struct bt_object base;
        enum bt_component_type type;
        GString *name;
+       GString *description;
        struct bt_plugin *plugin;
        bt_component_init_cb init;
 };
@@ -48,6 +49,6 @@ int bt_component_class_init(
 BT_HIDDEN
 struct bt_component_class *bt_component_class_create(
                enum bt_component_type type, const char *name,
-               struct bt_plugin *plugin);
+               const char *description, struct bt_plugin *plugin);
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
index 70e1eb5a96ce11ed7db7ebb6d4d312760900d36d..a882668120687f0314eddb9435e61264621b07e1 100644 (file)
@@ -58,6 +58,18 @@ struct bt_component_class;
 extern const char *bt_component_class_get_name(
                struct bt_component_class *component_class);
 
+/**
+ * Get a component class' description.
+ *
+ * Component classes may provide an optional description. It may, however,
+ * opt not to.
+ *
+ * @param component_class      Component class of which to get the description
+ * @returns                    Description of the component class, or NULL.
+ */
+extern const char *bt_component_class_get_name(
+               struct bt_component_class *component_class);
+
 /**
  * Get a component class' type.
  *
index f1599f28e9c8a62a11fad806f673c5b9fd537649..02414c2849056d85070b68ba5bccd6cd39a4abb7 100644 (file)
@@ -125,12 +125,12 @@ extern enum bt_component_factory_status bt_component_factory_load(
 extern enum bt_component_factory_status
 bt_component_factory_register_source_component_class(
                struct bt_component_factory *factory, const char *name,
-               bt_component_init_cb init);
+               const char *description, bt_component_init_cb init);
 
 extern enum bt_component_factory_status
 bt_component_factory_register_sink_component_class(
                struct bt_component_factory *factory, const char *name,
-               bt_component_init_cb init);
+               const char *description, bt_component_init_cb init);
 
 #ifdef __cplusplus
 }
index 20ab0bbe748681842c6296a9776a651f49ba6e20..eb088d9b7048f870c6f2a913fdcb1ca7841ed729 100644 (file)
@@ -51,7 +51,6 @@ struct bt_component {
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               struct bt_component_class *class, const char *name,
                bt_component_destroy_cb destroy);
 
 BT_HIDDEN
index d8cbaa6fa737efbdd455ce798798f6c03d7dbd8e..53684dbd1924b9337bb922eb65ae56e5a55cda87 100644 (file)
@@ -54,18 +54,21 @@ enum bt_component_status {
        BT_COMPONENT_STATUS_OK =                0,
 };
 
-struct bt_component;
 
+struct bt_component;
+struct bt_value;
 
 /**
  * Create an instance of a component from a component class.
  *
  * @param component_class      Component class of which to create an instance
  * @param name                 Name of the new component instance, optional
+ * @param params               A dictionary of component parameters
  * @returns                    Returns a pointer to a new component instance
  */
 extern struct bt_component *bt_component_create(
-               struct bt_component_class *component_class, const char *name);
+               struct bt_component_class *component_class, const char *name,
+               struct bt_value *params);
 
 /**
  * Get component's name.
index 673b7818f4838d8ed6998a2a18ef9e1e1981a0ca..75343239563a4b4bb51ab250ad2e0c300c435f63 100644 (file)
@@ -49,13 +49,15 @@ struct bt_plugin {
        const char *name;
        const char *author;
        const char *license;
+       const char *description;
+       GString *path;
         bt_plugin_init_func init;
        bt_plugin_exit_func exit;
        GModule *module;
 };
 
 BT_HIDDEN
-struct bt_plugin *bt_plugin_create(GModule *module);
+struct bt_plugin *bt_plugin_create(GModule *module, const char *path);
 
 BT_HIDDEN
 enum bt_component_status bt_plugin_register_component_classes(
index 5011e3a68b31e322a5f027ca3d2ae8dcad96ff10..56916f7144c5eba5596a9bfa07276fce57214ea2 100644 (file)
 #include <babeltrace/plugin/component.h>
 
 /* A plugin must define the __bt_plugin_init symbol */
-#define BT_PLUGIN_NAME(_x)     const char __bt_plugin_name[] = (_x)
-#define BT_PLUGIN_AUTHOR(_x)   const char __bt_plugin_author[] = (_x)
-#define BT_PLUGIN_LICENSE(_x)  const char __bt_plugin_license[] = (_x)
-#define BT_PLUGIN_INIT(_x)     bt_plugin_init_func __bt_plugin_init = (_x)
-#define BT_PLUGIN_EXIT(_x)     bt_plugin_exit_func __bt_plugin_exit = (_x)
-
-#define BT_PLUGIN_COMPONENT_CLASSES_BEGIN                      \
+#define BT_PLUGIN_NAME(_x)             const char __bt_plugin_name[] = (_x)
+#define BT_PLUGIN_AUTHOR(_x)           const char __bt_plugin_author[] = (_x)
+#define BT_PLUGIN_LICENSE(_x)          const char __bt_plugin_license[] = (_x)
+#define BT_PLUGIN_DESCRIPTION(_x)      const char __bt_plugin_description[] = (_x)
+#define BT_PLUGIN_INIT(_x)             bt_plugin_init_func __bt_plugin_init = (_x)
+#define BT_PLUGIN_EXIT(_x)             bt_plugin_exit_func __bt_plugin_exit = (_x)
+
+#define BT_PLUGIN_COMPONENT_CLASSES_BEGIN                              \
        enum bt_component_status __bt_plugin_register_component_classes(\
-               struct bt_component_factory *factory)\
+               struct bt_component_factory *factory)                   \
        {
 
-#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init) \
-       bt_component_factory_register_source_component_class(factory, \
-               _name, _init);
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, description, _init)      \
+       bt_component_factory_register_source_component_class(factory,           \
+                       _name, description, _init);
 
-#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init) \
-       bt_component_factory_register_sink_component_class(factory, \
-               _name, _init);
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _description, _init)       \
+       bt_component_factory_register_sink_component_class(factory,             \
+                       _name, _description, _init);
 
 #define BT_PLUGIN_COMPONENT_CLASSES_END\
        \
index 0de0676818390f7bb1bdd3972a9df6a08af294db..28bed36c37e6021e2cfacecbcbac3f646d9e879a 100644 (file)
@@ -38,6 +38,7 @@ struct bt_notification;
 struct bt_notification_iterator;
 struct bt_component;
 struct bt_component_factory;
+struct bt_value;
 
 typedef enum bt_component_status (*bt_plugin_init_func)(
                struct bt_component_factory *factory);
@@ -57,10 +58,11 @@ typedef void (*bt_component_destroy_cb)(struct bt_component *component);
  * function.
  *
  * @param component    Component instance
+ * @param params       A dictionary of component parameters
  * @returns            One of #bt_component_status values
  */
 typedef enum bt_component_status (*bt_component_init_cb)(
-               struct bt_component *component);
+               struct bt_component *component, struct bt_value *params);
 
 /**
  * Get a component's private data.
index b522c91b7aec251e2ab7a80b1e93c2d6637e94cd..e5c69eed941bca37bff90aeebfac93249686d468 100644 (file)
@@ -57,6 +57,14 @@ extern const char *bt_plugin_get_author(struct bt_plugin *plugin);
  */
 extern const char *bt_plugin_get_license(struct bt_plugin *plugin);
 
+/**
+ * Get the path of a plug-in.
+ *
+ * @param plugin       An instance of a plug-in
+ * @returns            Plug-in path or NULL on error
+ */
+extern const char *bt_plugin_get_path(struct bt_plugin *plugin);
+
 #ifdef __cplusplus
 }
 #endif
index f609e93eca25b7360fff9beb91322935314c3b72..ec6f9c2f1a42620f4d115f8c266f6e1d4ad2d1f8 100644 (file)
@@ -32,6 +32,8 @@
 #include <babeltrace/plugin/component-class-internal.h>
 #include <babeltrace/plugin/plugin-system.h>
 
+struct bt_value;
+
 struct bt_component_sink_class {
        struct bt_component_class parent;
 };
@@ -47,22 +49,21 @@ struct bt_component_sink {
  * Allocate a sink component.
  *
  * @param class                        Component class
- * @param name                 Component instance name (will be copied)
+ * @param params               A dictionary of component parameters
  * @returns                    A sink component instance
  */
 BT_HIDDEN
-extern struct bt_component *bt_component_sink_create(
-               struct bt_component_class *class, const char *name);
+struct bt_component *bt_component_sink_create(
+               struct bt_component_class *class, struct bt_value *params);
 
 /**
- * Allocate a sink component class.
+ * Validate a sink component.
  *
- * @param name                 Component instance name (will be copied)
- * @returns                    A sink component class instance
+ * @param component            Sink component instance to validate
+ * @returns                    One of #bt_component_status
  */
-/* FIXME */
 BT_HIDDEN
-extern struct bt_component *bt_component_class_sink_create(
-               struct bt_component_class *class, const char *name);
+enum bt_component_status bt_component_sink_validate(
+               struct bt_component *component);
 
 #endif /* BABELTRACE_PLUGIN_SINK_INTERNAL_H */
index e123fd5c293e530eb5927db17973b566829b67cf..70c0196df82ce81321af95a4f9db6664e513265d 100644 (file)
@@ -32,6 +32,8 @@
 #include <babeltrace/plugin/component-class-internal.h>
 #include <babeltrace/plugin/plugin-system.h>
 
+struct bt_value;
+
 struct bt_component_source_class {
        struct bt_component_class parent;
 };
@@ -47,11 +49,21 @@ struct bt_component_source {
  * Allocate a source component.
  *
  * @param class                        Component class
- * @param name                 Component instance name (will be copied)
+ * @param params               A dictionary of component parameters
  * @returns                    A source component instance
  */
 BT_HIDDEN
-extern struct bt_component *bt_component_source_create(
-               struct bt_component_class *class, const char *name);
+struct bt_component *bt_component_source_create(
+               struct bt_component_class *class, struct bt_value *params);
+
+/**
+ * Validate a source component.
+ *
+ * @param component            Source component instance to validate
+ * @returns                    One of #bt_component_status
+ */
+BT_HIDDEN
+enum bt_component_status bt_component_source_validate(
+               struct bt_component *component);
 
 #endif /* BABELTRACE_PLUGIN_SOURCE_INTERNAL_H */
index 49d6c3464412ac7367ad01766267c3a0a1a383d1..e0e2e0bf2e4e9cd8c42ae8297909277279b85a6f 100644 (file)
@@ -41,6 +41,9 @@ void bt_component_class_destroy(struct bt_object *obj)
        if (class->name) {
                g_string_free(class->name, TRUE);
        }
+       if (class->description) {
+               g_string_free(class->description, TRUE);
+       }
 
        bt_put(class->plugin);
        g_free(class);
@@ -49,7 +52,7 @@ void bt_component_class_destroy(struct bt_object *obj)
 BT_HIDDEN
 struct bt_component_class *bt_component_class_create(
                enum bt_component_type type, const char *name,
-               struct bt_plugin *plugin)
+               const char *description, struct bt_plugin *plugin)
 {
        struct bt_component_class *class;
 
@@ -61,7 +64,8 @@ struct bt_component_class *bt_component_class_create(
        bt_object_init(class, bt_component_class_destroy);
        class->type = type;
        class->name = g_string_new(name);
-       if (!class->name) {
+       class->description = g_string_new(description);
+       if (!class->name || !class->description) {
                BT_PUT(class);
                goto end;
        }
@@ -90,3 +94,10 @@ struct bt_plugin *bt_component_class_get_plugin(
        return component_class ? bt_get(component_class->plugin) :
                        NULL;
 }
+
+const char *bt_component_class_get_description(
+               struct bt_component_class *component_class)
+{
+       return component_class ? component_class->description->str : NULL;
+}
+
index 401fc608707e6cc7a96998ddb7e1d0246bb24fbf..65840d4cac79e883b6a025846d2405b099b3d9a2 100644 (file)
@@ -112,7 +112,7 @@ bt_component_factory_load_file(struct bt_component_factory *factory,
        }
 
        /* Load plugin and make sure it defines the required entry points */
-       plugin = bt_plugin_create(module);
+       plugin = bt_plugin_create(module, path);
        if (!plugin) {
                ret = BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN;
                if (!g_module_close(module)) {
@@ -383,7 +383,8 @@ end:
 static
 enum bt_component_factory_status
 add_component_class(struct bt_component_factory *factory, const char *name,
-               bt_component_init_cb init, enum bt_component_type type)
+                   const char *description, bt_component_init_cb init,
+                   enum bt_component_type type)
 {
        struct bt_component_class *class;
        enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK;
@@ -393,7 +394,7 @@ add_component_class(struct bt_component_factory *factory, const char *name,
                goto end;
        }
 
-       class = bt_component_class_create(type, name,
+       class = bt_component_class_create(type, name, description,
                        factory->current_plugin);
        g_ptr_array_add(factory->component_classes, class);
 end:
@@ -403,17 +404,17 @@ end:
 enum bt_component_factory_status
 bt_component_factory_register_source_component_class(
                struct bt_component_factory *factory, const char *name,
-               bt_component_init_cb init)
+               const char *description, bt_component_init_cb init)
 {
-       return add_component_class(factory, name, init,
+       return add_component_class(factory, name, description, init,
                        BT_COMPONENT_TYPE_SOURCE);
 }
 
 enum bt_component_factory_status
 bt_component_factory_register_sink_component_class(
                struct bt_component_factory *factory, const char *name,
-               bt_component_init_cb init)
+               const char *description, bt_component_init_cb init)
 {
-       return add_component_class(factory, name, init,
+       return add_component_class(factory, name, description, init,
                        BT_COMPONENT_TYPE_SINK);
 }
index 210e2e33f0bf2f9ae9dbb32bf79827b48c491ca0..5cfbbf0e3403e9d2d7f87b4f562864a04e168c66 100644 (file)
 #include <babeltrace/compiler.h>
 #include <babeltrace/ref.h>
 
+static
+struct bt_component * (* const component_create_funcs[])(
+               struct bt_component_class *, struct bt_value *) = {
+       [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_create,
+       [BT_COMPONENT_TYPE_SINK] = bt_component_sink_create,
+};
+
+static
+enum bt_component_status (* const component_validation_funcs[])(
+               struct bt_component *) = {
+       [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_validate,
+       [BT_COMPONENT_TYPE_SINK] = bt_component_sink_validate,
+};
+
 static
 void bt_component_destroy(struct bt_object *obj)
 {
@@ -46,44 +60,34 @@ void bt_component_destroy(struct bt_object *obj)
 
        component = container_of(obj, struct bt_component, base);
 
-       /**
+       assert(component->destroy);
+       component_class = component->class;
+
+       /*
         * User data is destroyed first, followed by the concrete component
         * instance.
         */
-       assert(!component->user_data || component->user_destroy);
-       component->user_destroy(component->user_data);
-
-       g_string_free(component->name, TRUE);
-
-       assert(component->destroy);
-       component_class = component->class;
+       if (component->user_destroy) {
+               component->user_destroy(component->user_data);
+       }
 
-       /* Frees the component, which becomes invalid */
        component->destroy(component);
-       component = NULL;
-
+       g_string_free(component->name, TRUE);
        bt_put(component_class);
+       g_free(component);
 }
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               struct bt_component_class *class, const char *name,
                bt_component_destroy_cb destroy)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
-       bt_object_init(component, bt_component_destroy);
-       if (!component || !class || !name || name[0] == '\0' || !destroy) {
+       if (!component || !destroy) {
                ret = BT_COMPONENT_STATUS_INVAL;
                goto end;
        }
 
-       component->class = bt_get(class);
-       component->name = g_string_new(name);
-       if (!component->name) {
-               ret = BT_COMPONENT_STATUS_NOMEM;
-               goto end;
-       }
        component->destroy = destroy;
 end:
        return ret;
@@ -96,23 +100,41 @@ enum bt_component_type bt_component_get_type(struct bt_component *component)
 }
 
 struct bt_component *bt_component_create(
-               struct bt_component_class *component_class, const char *name)
+               struct bt_component_class *component_class, const char *name,
+               struct bt_value *params)
 {
+       int ret;
        struct bt_component *component = NULL;
+       enum bt_component_type type;
 
        if (!component_class) {
                goto end;
        }
 
-       switch (bt_component_class_get_type(component_class))
-       {
-       case BT_COMPONENT_TYPE_SOURCE:
-               component = bt_component_source_create(component_class, name);
-               break;
-       case BT_COMPONENT_TYPE_SINK:
-               component = bt_component_sink_create(component_class, name);
-               break;
-       default:
+       type = bt_component_class_get_type(component_class);
+       if (type <= BT_COMPONENT_TYPE_UNKNOWN ||
+                       type >= BT_COMPONENT_TYPE_FILTER) {
+               /* Filter components are not supported yet. */
+               goto end;
+       }
+
+       component = component_create_funcs[type](component_class, params);
+       if (!component) {
+               goto end;
+       }
+
+       bt_object_init(component, bt_component_destroy);
+       component->class = bt_get(component_class);
+       component->name = g_string_new(name);
+       if (component->name) {
+               BT_PUT(component);
+               goto end;
+       }
+
+       component_class->init(component, params);
+       ret = component_validation_funcs[type](component);
+       if (ret) {
+               BT_PUT(component);
                goto end;
        }
 end:
index 33cfb28046e3baa60b3d8eae2c7ea04e89233a88..75574973f8561ff43138234665f3f1d5070720e0 100644 (file)
 #include <stdbool.h>
 
 static
-enum bt_component_status ctf_text_init(struct bt_component *);
-static
-void ctf_text_plugin_exit(void);
+enum bt_component_status ctf_text_init(struct bt_component *,
+               struct bt_value *params);
 
 /* Initialize plug-in entry points. */
 BT_PLUGIN_NAME("ctf-text");
+BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in.");
 BT_PLUGIN_AUTHOR("Jérémie Galarneau");
-BT_PLUGIN_LICENSE("MIT License");
-BT_PLUGIN_EXIT(ctf_text_plugin_exit);
+BT_PLUGIN_LICENSE("MIT");
 
-/* Defines BT_PLUGIN_INIT. */
 BT_PLUGIN_COMPONENT_CLASSES_BEGIN
-BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(__bt_plugin_name, ctf_text_init)
+BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY("text", "Formats CTF-IR to text. Formerly known as ctf-text.", ctf_text_init)
 BT_PLUGIN_COMPONENT_CLASSES_END
 
 enum loglevel {
@@ -107,14 +105,8 @@ struct ctf_text_component {
 
 static
 enum bt_component_status ctf_text_init(
-               struct bt_component *component)
+               struct bt_component *component, struct bt_value *params)
 {
-       printf(__bt_plugin_name);
+       printf("ctf_text_init\n");
        return BT_COMPONENT_STATUS_OK;
 }
-
-static
-void ctf_text_plugin_exit(void)
-{
-       printf("in ctf_text_exit\n");
-}
index 025bbfc71c08280d0657ebaad7314937117bb677..f3d23268f7c83f326de6bb12a0d907df7a27f6fc 100644 (file)
 #include <babeltrace/plugin/plugin-internal.h>
 #include <glib.h>
 
-#define PLUGIN_SYMBOL_NAME     "__bt_plugin_name"
-#define PLUGIN_SYMBOL_AUTHOR   "__bt_plugin_author"
-#define PLUGIN_SYMBOL_LICENSE  "__bt_plugin_license"
-#define PLUGIN_SYMBOL_INIT     "__bt_plugin_init"
-#define PLUGIN_SYMBOL_EXIT     "__bt_plugin_exit"
+#define PLUGIN_SYMBOL_NAME             "__bt_plugin_name"
+#define PLUGIN_SYMBOL_AUTHOR           "__bt_plugin_author"
+#define PLUGIN_SYMBOL_LICENSE          "__bt_plugin_license"
+#define PLUGIN_SYMBOL_INIT             "__bt_plugin_init"
+#define PLUGIN_SYMBOL_EXIT             "__bt_plugin_exit"
+#define PLUGIN_SYMBOL_DESCRIPTION      "__bt_plugin_description"
 
 static
 void bt_plugin_destroy(struct bt_object *obj)
@@ -49,19 +50,23 @@ void bt_plugin_destroy(struct bt_object *obj)
                if (!g_module_close(plugin->module)) {
                                printf_error("Module close error: %s",
                                        g_module_error());
-
                }
        }
+
+       if (plugin->exit) {
+               plugin->exit();
+       }
+       g_string_free(plugin->path, TRUE);
        g_free(plugin);
 }
 
 BT_HIDDEN
-struct bt_plugin *bt_plugin_create(GModule *module)
+struct bt_plugin *bt_plugin_create(GModule *module, const char *path)
 {
        struct bt_plugin *plugin = NULL;
        gpointer symbol = NULL;
 
-       if (!module) {
+       if (!module || !path) {
                goto error;
        }
 
@@ -71,6 +76,11 @@ struct bt_plugin *bt_plugin_create(GModule *module)
        }
 
        bt_object_init(plugin, bt_plugin_destroy);
+       plugin->path = g_string_new(path);
+       if (!plugin->path) {
+               goto error;
+       }
+
        if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
                        (gpointer *) &plugin->name)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
@@ -104,6 +114,8 @@ struct bt_plugin *bt_plugin_create(GModule *module)
        }
        g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
                        (gpointer *) &plugin->author);
+       g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION,
+                       (gpointer *) &plugin->description);
 
        return plugin;
 error:
@@ -133,3 +145,13 @@ const char *bt_plugin_get_license(struct bt_plugin *plugin)
 {
        return plugin ? plugin->license : NULL;
 }
+
+const char *bt_plugin_get_path(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->path->str : NULL;
+}
+
+const char *bt_plugin_get_description(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->description : NULL;
+}
index 363a66c7fe26d9e9a4bda385f9f75b1b8de18d85..81f6cba61cd8a19135a6fd49ce7ba1edf396c805 100644 (file)
 static
 void bt_component_sink_destroy(struct bt_component *component)
 {
-       struct bt_component_sink *sink;
-
-       if (!component) {
-               return;
-       }
+       return;
+}
 
-       sink = container_of(component, struct bt_component_sink, parent);
-       g_free(sink);
+BT_HIDDEN
+enum bt_component_status bt_component_sink_validate(
+               struct bt_component *component)
+{
+       return BT_COMPONENT_STATUS_OK;
 }
 
 BT_HIDDEN
 struct bt_component *bt_component_sink_create(
-               struct bt_component_class *class, const char *name)
+               struct bt_component_class *class, struct bt_value *params)
 {
        struct bt_component_sink *sink = NULL;
        enum bt_component_status ret;
@@ -55,8 +55,7 @@ struct bt_component *bt_component_sink_create(
                goto end;
        }
 
-       ret = bt_component_init(&sink->parent, class, name,
-               bt_component_sink_destroy);
+       ret = bt_component_init(&sink->parent, bt_component_sink_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
                BT_PUT(sink);
                goto end;
index 6e76206afb6e00c26627e044d44df098aba08eaf..ed3b1642b56c2d76e5b8032771acdfa0a67009c0 100644 (file)
 static
 void bt_component_source_destroy(struct bt_component *component)
 {
-       struct bt_component_source *source;
-
-       if (!component) {
-               return;
-       }
+       return;
+}
 
-       source = container_of(component, struct bt_component_source, parent);
-       g_free(source);
+BT_HIDDEN
+enum bt_component_status bt_component_source_validate(
+               struct bt_component *component)
+{
+       return BT_COMPONENT_STATUS_OK;
 }
 
 BT_HIDDEN
 struct bt_component *bt_component_source_create(
-               struct bt_component_class *class, const char *name)
+               struct bt_component_class *class, struct bt_value *params)
 {
        struct bt_component_source *source = NULL;
        enum bt_component_status ret;
@@ -58,8 +58,7 @@ struct bt_component *bt_component_source_create(
                goto end;
        }
 
-       ret = bt_component_init(&source->parent, class, name,
-               bt_component_source_destroy);
+       ret = bt_component_init(&source->parent, bt_component_source_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
                BT_PUT(source);
                goto end;
This page took 0.039967 seconds and 4 git commands to generate.