Component creation
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 16 Feb 2016 19:27:45 +0000 (14:27 -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>
20 files changed:
converter/babeltrace.c
include/babeltrace/plugin/component-class-internal.h
include/babeltrace/plugin/component-class.h
include/babeltrace/plugin/component-factory-internal.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 [new file with mode: 0644]
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 568d5b8f98d9102282c40a08904bddb35b057a37..892096d1fd4ca08ff65fc4617ae5422bb54a4a32 100644 (file)
@@ -775,10 +775,8 @@ int main(int argc, char **argv)
                goto end;
        }
 
-       components = bt_component_factory_get_components(component_factory);
-       if (!components || bt_value_array_is_empty(components)) {
-               printf_error("No plugins found, exiting.");
-               ret = -1;
+       ret = bt_component_factory_get_component_class_count(component_factory);
+       if (ret <= 0) {
                goto end;
        }
 
index 48cb3d9d34d942bc1876b4bf800f123cac2dd2ab..efdf991b520283b58d72e287c01d9798cc710f24 100644 (file)
@@ -37,6 +37,7 @@ struct bt_component_class {
        enum bt_component_type type;
        GString *name;
        struct bt_plugin *plugin;
+       bt_component_init_cb init;
 };
 
 BT_HIDDEN
@@ -45,7 +46,8 @@ int bt_component_class_init(
                const char *name);
 
 BT_HIDDEN
-int bt_component_class_set_plugin(struct bt_component_class *class,
+struct bt_component_class *bt_component_class_create(
+               enum bt_component_type type, const char *name,
                struct bt_plugin *plugin);
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
index 850f5e8516507ef1964353b8cc29a48c410243d1..70e1eb5a96ce11ed7db7ebb6d4d312760900d36d 100644 (file)
@@ -45,12 +45,35 @@ enum bt_component_type {
        BT_COMPONENT_TYPE_FILTER =      2,
 };
 
+struct bt_plugin;
 struct bt_component_class;
 
-const char *bt_component_class_get_name(
+
+/**
+ * Get a component class' name.
+ *
+ * @param component_class      Component class of which to get the name
+ * @returns                    Name of the component class
+ */
+extern const char *bt_component_class_get_name(
+               struct bt_component_class *component_class);
+
+/**
+ * Get a component class' type.
+ *
+ * @param component_class      Component class of which to get the type
+ * @returns                    One of #bt_component_type
+ */
+extern enum bt_component_type bt_component_class_get_type(
                struct bt_component_class *component_class);
 
-enum bt_component_type bt_component_class_get_type(
+/**
+ * Get a component class' plug-in.
+ *
+ * @param component_class      Component class of which to get the plug-in
+ * @returns                    The plug-in which registered the component class
+ */
+extern struct bt_plugin *bt_component_class_get_plugin(
                struct bt_component_class *component_class);
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_H */
index d2f14478d9672d5907342f9938205549dcf8df04..9cb07ec22f526ea79ed3e809f49f1fc728768773 100644 (file)
 
 struct bt_component_factory {
        struct bt_object base;
-       /** Array of pointers to struct bt_plugin */
-       GPtrArray *plugins;
        /** Array of pointers to struct bt_component_class */
        GPtrArray *component_classes;
+       /* Plug-in currently registering component classes. Weak ref. */
+       struct bt_plugin *current_plugin;
 };
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H */
index cc52aabc1d0730b55d3a431e769ea0e3773f9907..f1599f28e9c8a62a11fad806f673c5b9fd537649 100644 (file)
@@ -75,18 +75,39 @@ struct bt_component_factory;
 extern struct bt_component_factory *bt_component_factory_create(void);
 
 /**
- * Get the list of components registered to this factory.
+ * Get the number of component classes registered to the component factory.
  *
- * @param factory      Component factory
+ * @param factory      A component factory instance
+ * @returns            The number of component classes registered to the
+ *                     component factory, or a negative value on error.
  */
-extern struct bt_value *bt_component_factory_get_components(
+extern int bt_component_factory_get_component_class_count(
                struct bt_component_factory *factory);
 
 /**
- * .
+ * Get component class at index.
+ *
+ * @param factory      A component factory instance
+ * @param index                Index of the component class to return
+ * @returns            A component class instance, NULL on error.
  */
-extern struct bt_value *bt_component_factory_create_component(
-               struct bt_component_factory *factory);
+extern struct bt_component_class *bt_component_factory_get_component_class_index(
+               struct bt_component_factory *factory, int index);
+
+/**
+ * Look-up component class.
+ *
+ * @param factory              A component factory instance
+ * @param plugin_name          Name of the plug-in which registered the
+ *                             component class
+ * @param type                 Component type (@see #bt_component_type)
+ * @param component_name       Component name
+ * @returns                    A component class instance, NULL on error.
+ */
+extern struct bt_component_class *bt_component_factory_get_component_class(
+               struct bt_component_factory *factory,
+               const char *plugin_name, enum bt_component_type type,
+               const char *component_name);
 
 /**
  * Recursively load and register Babeltrace plugins under a given path.
@@ -104,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_source_init_cb init);
+               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_sink_init_cb init);
+               bt_component_init_cb init);
 
 #ifdef __cplusplus
 }
index c6443e54e96e9f7ed1bb5374fee30135c8e8714d..20ab0bbe748681842c6296a9776a651f49ba6e20 100644 (file)
@@ -54,4 +54,7 @@ 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
+enum bt_component_type bt_component_get_type(struct bt_component *component);
+
 #endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
index 87263f08c4c3e3cc90a0618c754a8d4f8b0573bd..d8cbaa6fa737efbdd455ce798798f6c03d7dbd8e 100644 (file)
@@ -56,6 +56,17 @@ enum bt_component_status {
 
 struct bt_component;
 
+
+/**
+ * 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
+ * @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);
+
 /**
  * Get component's name.
  *
index fbb91de6dbabd44d7ded5816d801510c2e531fed..673b7818f4838d8ed6998a2a18ef9e1e1981a0ca 100644 (file)
@@ -30,7 +30,7 @@
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ref-internal.h>
 #include <babeltrace/plugin/component.h>
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-system.h>
 #include <babeltrace/object-internal.h>
 #include <gmodule.h>
 
diff --git a/include/babeltrace/plugin/plugin-macros.h b/include/babeltrace/plugin/plugin-macros.h
new file mode 100644 (file)
index 0000000..1e1c026
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef BABELTRACE_PLUGIN_H
+#define BABELTRACE_PLUGIN_H
+
+/*
+ * BabelTrace - Babeltrace Plug-in Helper Macros
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2015 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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.
+ */
+
+#include <babeltrace/plugin/component-factory.h>
+#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                      \
+       enum bt_component_status __bt_plugin_register_component_classes(\
+               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_SINK_COMPONENT_CLASS_ENTRY(_name, _init) \
+       bt_component_factory_register_sink_component_class(factory, \
+               _name, _init);
+
+#define BT_PLUGIN_COMPONENT_CLASSES_END\
+       \
+       return BT_COMPONENT_STATUS_OK;\
+}\
+       \
+       BT_PLUGIN_INIT(__bt_plugin_register_component_classes);\
+
+#endif /* BABELTRACE_PLUGIN_MACROS_H */
index 1423f04f699d3526c6a42e3d134f7e8c4755b8a9..0de0676818390f7bb1bdd3972a9df6a08af294db 100644 (file)
@@ -37,6 +37,11 @@ extern "C" {
 struct bt_notification;
 struct bt_notification_iterator;
 struct bt_component;
+struct bt_component_factory;
+
+typedef enum bt_component_status (*bt_plugin_init_func)(
+               struct bt_component_factory *factory);
+typedef void (*bt_plugin_exit_func)(void);
 
 /**
  * Component private data deallocation function type.
@@ -46,39 +51,17 @@ struct bt_component;
 typedef void (*bt_component_destroy_cb)(struct bt_component *component);
 
 /**
- * Source component initialization function type.
- *
- * A source component's iterator initialization callback, private data and
- * deinitialization callback must be set by this function.
- *
- * @param component    Component instance
- * @returns            One of #bt_component_status values
- */
-typedef enum bt_component_status (*bt_component_source_init_cb)(
-               struct bt_component *component);
-
-/**
- * Sink component initialization function type.
+ * Component initialization function type.
  *
- * A sink component's notification handling callback, private data and
- * deinitialization callback must be set by this function.
+ * A component's private data and required callbacks must be set by this
+ * function.
  *
  * @param component    Component instance
  * @returns            One of #bt_component_status values
  */
-typedef enum bt_component_status (*bt_component_sink_init_cb)(
+typedef enum bt_component_status (*bt_component_init_cb)(
                struct bt_component *component);
 
-/**
- * Iterator initialization function type.
- *
- * @param component    Component instance
- * @param iterator     Iterator instance
- */
-typedef enum bt_component_status (*bt_component_source_iterator_init_cb)(
-               struct bt_component *component,
-               struct bt_notification_iterator *iterator);
-
 /**
  * Get a component's private data.
  *
index 3bb7c0440e45dcdc39f25c759211670cc55e42fa..b522c91b7aec251e2ab7a80b1e93c2d6637e94cd 100644 (file)
@@ -4,8 +4,7 @@
 /*
  * BabelTrace - Babeltrace Plug-in Interface
  *
- * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Copyright 2015 Philippe Proulx <pproulx@efficios.com>
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * SOFTWARE.
  */
 
-#include <babeltrace/plugin/component-factory.h>
-#include <babeltrace/plugin/component.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-typedef enum bt_component_status (*bt_plugin_init_func)(
-               struct bt_component_factory *factory);
-typedef void (*bt_plugin_exit_func)(void);
+struct bt_plugin;
 
-/* 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                      \
-       enum bt_component_status __bt_plugin_register_component_classes(\
-               struct bt_component_factory *factory)\
-       {
+/**
+ * Get the name of a plug-in.
+ *
+ * @param plugin       An instance of a plug-in
+ * @returns            Plug-in name or NULL on error
+ */
+extern const char *bt_plugin_get_name(struct bt_plugin *plugin);
 
-#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init) \
-       bt_component_factory_register_source_component_class(factory, \
-               _name, _init);
+/**
+ * Get the name of a plug-in's author.
+ *
+ * @param plugin       An instance of a plug-in
+ * @returns            Plug-in author or NULL on error
+ */
+extern const char *bt_plugin_get_author(struct bt_plugin *plugin);
 
-#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init) \
-       bt_component_factory_register_sink_component_class(factory, \
-               _name, _init);
+/**
+ * Get the license of a plug-in.
+ *
+ * @param plugin       An instance of a plug-in
+ * @returns            Plug-in license or NULL on error
+ */
+extern const char *bt_plugin_get_license(struct bt_plugin *plugin);
 
-#define BT_PLUGIN_COMPONENT_CLASSES_END\
-       \
-       return BT_COMPONENT_STATUS_OK;\
-}\
-       \
-       BT_PLUGIN_INIT(__bt_plugin_register_component_classes);\
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* BABELTRACE_PLUGIN_H */
index 1bcd4ba599adf35e670709811ce6ff126c2364f0..f609e93eca25b7360fff9beb91322935314c3b72 100644 (file)
@@ -34,7 +34,6 @@
 
 struct bt_component_sink_class {
        struct bt_component_class parent;
-       bt_component_sink_init_cb init;
 };
 
 struct bt_component_sink {
index 5c411fc1c83f04a68793559e1d4cba3407079566..e123fd5c293e530eb5927db17973b566829b67cf 100644 (file)
@@ -34,7 +34,6 @@
 
 struct bt_component_source_class {
        struct bt_component_class parent;
-       bt_component_source_init_cb init;       
 };
 
 struct bt_component_source {
index c13358f872a33e773e919bd28d3a3704e37b0bec..49d6c3464412ac7367ad01766267c3a0a1a383d1 100644 (file)
@@ -66,8 +66,27 @@ struct bt_component_class *bt_component_class_create(
                goto end;
        }
 
-       bt_get(plugin);
-       class->plugin = plugin;
+       class->plugin = bt_get(plugin);
 end:
        return class;
 }
+
+const char *bt_component_class_get_name(
+               struct bt_component_class *component_class)
+{
+       return component_class ? component_class->name->str : NULL;
+}
+
+enum bt_component_type bt_component_class_get_type(
+               struct bt_component_class *component_class)
+{
+       return component_class ? component_class->type :
+                       BT_COMPONENT_TYPE_UNKNOWN;
+}
+
+struct bt_plugin *bt_component_class_get_plugin(
+               struct bt_component_class *component_class)
+{
+       return component_class ? bt_get(component_class->plugin) :
+                       NULL;
+}
index 1be827c4ae500ef05811a016be2ad0fcd0e88cd8..401fc608707e6cc7a96998ddb7e1d0246bb24fbf 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <babeltrace/plugin/component-factory.h>
 #include <babeltrace/plugin/component-factory-internal.h>
+#include <babeltrace/plugin/component-class-internal.h>
 #include <babeltrace/plugin/source-internal.h>
 #include <babeltrace/plugin/sink-internal.h>
 #include <babeltrace/babeltrace-internal.h>
@@ -121,8 +122,10 @@ bt_component_factory_load_file(struct bt_component_factory *factory,
                goto end;
        }
 
+       factory->current_plugin = plugin;
        component_status = bt_plugin_register_component_classes(plugin,
                        factory);
+       factory->current_plugin = NULL;
        if (component_status != BT_COMPONENT_STATUS_OK) {
                switch (component_status) {
                case BT_COMPONENT_STATUS_NOMEM:
@@ -136,7 +139,6 @@ bt_component_factory_load_file(struct bt_component_factory *factory,
                BT_PUT(plugin);
                goto end;
        }
-       g_ptr_array_add(factory->plugins, plugin);
 end:
        return ret;
 }
@@ -242,9 +244,6 @@ void bt_component_factory_destroy(struct bt_object *obj)
        assert(obj);
        factory = container_of(obj, struct bt_component_factory, base);
 
-       if (factory->plugins) {
-               g_ptr_array_free(factory->plugins, TRUE);
-       }
        if (factory->component_classes) {
                g_ptr_array_free(factory->component_classes, TRUE);
        }
@@ -261,11 +260,6 @@ struct bt_component_factory *bt_component_factory_create(void)
        }
 
        bt_object_init(factory, bt_component_factory_destroy);
-       factory->plugins = g_ptr_array_new_with_free_func(
-               (GDestroyNotify) bt_put);
-       if (!factory->plugins) {
-               goto error;
-       }
        factory->component_classes = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_put);
        if (!factory->component_classes) {
@@ -278,11 +272,84 @@ error:
        return factory;
 }
 
-struct bt_value *bt_component_factory_get_components(
+int bt_component_factory_get_component_class_count(
                struct bt_component_factory *factory)
 {
-       assert(0);
+       return factory ? factory->component_classes->len : -1;
+}
+
+struct bt_component_class *bt_component_factory_get_component_class_index(
+               struct bt_component_factory *factory, int index)
+{
+       struct bt_component_class *component_class = NULL;
+
+       if (!factory || index < 0 || index >= factory->component_classes->len) {
+               goto end;
+       }
+
+       component_class = bt_get(g_ptr_array_index(
+                       factory->component_classes, index));
+end:
+       return component_class;
+}
+
+struct bt_component_class *bt_component_factory_get_component_class(
+               struct bt_component_factory *factory,
+               const char *plugin_name, enum bt_component_type type,
+               const char *component_name)
+{
+       size_t i;
+       struct bt_component_class *component_class = NULL;
+
+       if (!factory || (!plugin_name && !component_name &&
+                       type == BT_COMPONENT_TYPE_UNKNOWN)) {
+               /* At least one criterion must be provided. */
+               goto no_match;
+       }
+
+       for (i = 0; i < factory->component_classes->len; i++) {
+               struct bt_plugin *plugin = NULL;
+
+               component_class = g_ptr_array_index(factory->component_classes,
+                               i);
+               plugin = bt_component_class_get_plugin(component_class);
+               assert(plugin);
+
+               if (type != BT_COMPONENT_TYPE_UNKNOWN) {
+                       if (type != bt_component_class_get_type(
+                                       component_class)) {
+                               continue;
+                       }
+               }
+
+               if (plugin_name) {
+                       const char *cur_plugin_name = bt_plugin_get_name(
+                                       plugin);
+
+                       assert(cur_plugin_name);
+                       if (strcmp(plugin_name, cur_plugin_name)) {
+                               continue;
+                       }
+               }
+
+               if (component_name) {
+                       const char *cur_cc_name = bt_component_class_get_name(
+                                       component_class);
+
+                       assert(cur_cc_name);
+                       if (strcmp(component_name, cur_cc_name)) {
+                               continue;
+                       }
+               }
+
+               /* All criteria met. */
+               goto match;
+       }
+
+no_match:
        return NULL;
+match:
+       return bt_get(component_class);
 }
 
 enum bt_component_factory_status bt_component_factory_load(
@@ -313,19 +380,10 @@ end:
        return ret;
 }
 
+static
 enum bt_component_factory_status
-bt_component_factory_register_source_component_class(
-               struct bt_component_factory *factory, const char *name,
-               bt_component_source_init_cb init)
-{
-       assert(0);
-       return BT_COMPONENT_FACTORY_STATUS_ERROR;
-}
-
-enum bt_component_factory_status
-bt_component_factory_register_sink_component_class(
-               struct bt_component_factory *factory, const char *name,
-               bt_component_sink_init_cb init)
+add_component_class(struct bt_component_factory *factory, const char *name,
+               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;
@@ -335,6 +393,27 @@ bt_component_factory_register_sink_component_class(
                goto end;
        }
 
+       class = bt_component_class_create(type, name,
+                       factory->current_plugin);
+       g_ptr_array_add(factory->component_classes, class);
 end:
        return ret;
 }
+
+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)
+{
+       return add_component_class(factory, name, 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)
+{
+       return add_component_class(factory, name, init,
+                       BT_COMPONENT_TYPE_SINK);
+}
index 0b7a9baa431c214bb0a382a5723efc054f70c0bd..210e2e33f0bf2f9ae9dbb32bf79827b48c491ca0 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/source-internal.h>
+#include <babeltrace/plugin/sink-internal.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler.h>
 #include <babeltrace/ref.h>
@@ -70,12 +72,12 @@ enum bt_component_status bt_component_init(struct bt_component *component,
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
+       bt_object_init(component, bt_component_destroy);
        if (!component || !class || !name || name[0] == '\0' || !destroy) {
                ret = BT_COMPONENT_STATUS_INVAL;
                goto end;
        }
 
-       bt_object_init(component, bt_component_destroy);
        component->class = bt_get(class);
        component->name = g_string_new(name);
        if (!component->name) {
@@ -87,6 +89,36 @@ end:
        return ret;
 }
 
+BT_HIDDEN
+enum bt_component_type bt_component_get_type(struct bt_component *component)
+{
+       return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN;
+}
+
+struct bt_component *bt_component_create(
+               struct bt_component_class *component_class, const char *name)
+{
+       struct bt_component *component = NULL;
+
+       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:
+               goto end;
+       }
+end:
+       return component;
+}
+
 const char *bt_component_get_name(struct bt_component *component)
 {
        const char *ret = NULL;
@@ -115,17 +147,10 @@ end:
        return ret;
 }
 
-enum bt_component_type bt_component_get_type(struct bt_component *component)
+struct bt_component_class *bt_component_get_class(
+               struct bt_component *component)
 {
-       enum bt_component_type type = BT_COMPONENT_TYPE_UNKNOWN;
-
-       if (!component) {
-               goto end;
-       }
-
-       type = component->class->type;
-end:
-       return type;
+       return component ? bt_get(component->class) : NULL;
 }
 
 enum bt_component_status bt_component_set_error_stream(
@@ -145,15 +170,7 @@ end:
 
 void *bt_component_get_private_data(struct bt_component *component)
 {
-       void *ret = NULL;
-
-       if (!component) {
-               goto end;
-       }
-
-       ret = component->user_data;
-end:
-       return ret;
+       return component ? component->user_data : NULL;
 }
 
 enum bt_component_status
index 9732678cd9a1a7fd25c0f0eeed9f01a668774f59..33cfb28046e3baa60b3d8eae2c7ea04e89233a88 100644 (file)
@@ -26,7 +26,7 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-macros.h>
 #include <babeltrace/plugin/component.h>
 #include <babeltrace/plugin/sink.h>
 #include <babeltrace/plugin/notification/notification.h>
index 48ca2134f22b211b53ff7ef9d5ea763e3bfa7f63..025bbfc71c08280d0657ebaad7314937117bb677 100644 (file)
@@ -118,3 +118,18 @@ enum bt_component_status bt_plugin_register_component_classes(
        assert(plugin && factory);
        return plugin->init(factory);
 }
+
+const char *bt_plugin_get_name(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->name : NULL;
+}
+
+const char *bt_plugin_get_author(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->author : NULL;
+}
+
+const char *bt_plugin_get_license(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->license : NULL;
+}
index bb9e1b0cc83932245279af9b42f35c9a40760609..363a66c7fe26d9e9a4bda385f9f75b1b8de18d85 100644 (file)
@@ -58,8 +58,7 @@ struct bt_component *bt_component_sink_create(
        ret = bt_component_init(&sink->parent, class, name,
                bt_component_sink_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
-               g_free(sink);
-               sink = NULL;
+               BT_PUT(sink);
                goto end;
        }
 end:
index 2dba33bd432a6bf958ffbf619d3d1af4c11f2e9a..6e76206afb6e00c26627e044d44df098aba08eaf 100644 (file)
@@ -52,6 +52,7 @@ struct bt_component *bt_component_source_create(
 {
        struct bt_component_source *source = NULL;
        enum bt_component_status ret;
+
        source = g_new0(struct bt_component_source, 1);
        if (!source) {
                goto end;
@@ -60,15 +61,14 @@ struct bt_component *bt_component_source_create(
        ret = bt_component_init(&source->parent, class, name,
                bt_component_source_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
-               g_free(source);
-               source = NULL;
+               BT_PUT(source);
                goto end;
        }
 end:
        return source ? &source->parent : NULL;
 }
 
-struct bt_notification_iterator *bt_plugin_source_create_iterator(
+struct bt_notification_iterator *bt_component_source_create_iterator(
                struct bt_component *component)
 {
        enum bt_component_status ret_component;
This page took 0.037174 seconds and 4 git commands to generate.