Move initialization of components to init functions
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 13 Jul 2015 01:56:53 +0000 (21:56 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 16:57:25 +0000 (12:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
13 files changed:
include/babeltrace/plugin/component-factory-internal.h
include/babeltrace/plugin/component-factory.h
include/babeltrace/plugin/component-internal.h
include/babeltrace/plugin/notification/iterator-internal.h
include/babeltrace/plugin/notification/iterator.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.c
plugins/iterator.c
plugins/sink.c
plugins/source.c

index 69c16419396c908949e9f4ce91af87c113f76582..0508cd860728e51374c47cc4ba1cfe041b068885 100644 (file)
 #include <babeltrace/plugin/component-internal.h>
 #include <babeltrace/plugin/plugin-system.h>
 
-/** Component initialization functions */
-/**
- * Allocate a source component.
- *
- * @param name                 Component instance name (will be copied)
- * @param private_data         Private component implementation data
- * @param destroy_cb           Component private data clean-up callback
- * @param iterator_init_cb     Iterator initialization callback
- * @returns                    A source component instance
- */
-BT_HIDDEN
-extern struct bt_component *bt_component_source_create(const char *name,
-               void *private_data, bt_component_destroy_cb destroy_func,
-               bt_component_source_iterator_init_cb iterator_init_cb);
-
-/**
- * Allocate a sink component.
- *
- * @param name                 Component instance name (will be copied)
- * @param private_data         Private component implementation data
- * @param destroy_cb           Component private data clean-up callback
- * @param notification_cb      Notification handling callback
- * @returns                    A sink component instance
- */
-BT_HIDDEN
-extern struct bt_component *bt_component_sink_create(const char *name,
-               void *private_data, bt_component_destroy_cb destroy_func,
-               bt_component_sink_handle_notification_cb notification_cb);
+struct bt_component_factory {
+       int a;
+};
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H */
index 29e2eb5fe643384a1c4c34f56217bcefd7d857bd..350bf72ddafa5dc444100d52a083dd8c4521548f 100644 (file)
@@ -41,13 +41,11 @@ enum bt_component_status bt_component_factory_create(const char *path);
 
 enum bt_component_status bt_component_factory_register_source_component_class(
        struct bt_component_factory *factory, const char *name,
-       bt_component_init_cb init, bt_component_fini_cb fini,
-       bt_component_source_iterator_create_cb iterator_create_cb);
+       bt_component_source_init_cb init);
 
 enum bt_component_status bt_component_factory_register_sink_component_class(
        struct bt_component_factory *factory, const char *name,
-       bt_component_init_cb init, bt_component_fini_cb fini,
-       bt_component_sink_handle_notification_cb handle_notification_cb);
+       bt_component_sink_init_cb init);
 
 void bt_component_factory_destroy(struct bt_component_factory *factory);
 
index ea6c489daf681d64bc3b22fe615c4e9218c4be84..7f35eaf55af99a5f918aca8e8c72a255bfd7a07b 100644 (file)
@@ -40,17 +40,16 @@ struct bt_component {
        enum bt_component_type type;
        /** No ownership taken */
        FILE *error_stream;
+       /** source, sink or filter destroy */
+       bt_component_destroy_cb destroy;
 
        void *user_data;
-       bt_component_destroy_cb user_data_destroy;
-       bt_component_destroy_cb destroy;
+       bt_component_destroy_cb user_destroy;
 };
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               const char *name, void *user_data,
-               bt_component_destroy_cb destroy_func,
-               enum bt_component_type component_type,
-               bt_component_destroy_cb component_destroy);
+               const char *name, enum bt_component_type component_type,
+               bt_component_destroy_cb destroy);
 
 #endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
index 6d1676e1d8733704f38c933807f1d35ae5354caf..5a47377689d3378fe1bc29381a38fb606d14dd2a 100644 (file)
@@ -36,6 +36,7 @@ struct bt_notification_iterator {
        bt_notification_iterator_get_cb get;
        bt_notification_iterator_next_cb next;
        void *user_data;
+       bt_notification_iterator_destroy_cb user_destroy;
 };
 
 /**
@@ -58,13 +59,4 @@ BT_HIDDEN
 enum bt_notification_iterator_status bt_notification_iterator_validate(
                struct bt_notification_iterator *iterator);
 
-/**
- * Destroy a notification iterator.
- *
- * @param iterator             Notification iterator instance
- */
-BT_HIDDEN
-void bt_notification_iterator_destroy(
-               struct bt_notification_iterator *iterator);
-
 #endif /* BABELTRACE_PLUGIN_ITERATOR_INTERNAL_H */
index 22807e41ab6f509c0660f7f2e7aea0603f5f98e6..480f50c7800d22fff4ac89e552fe473d38766985 100644 (file)
@@ -116,8 +116,7 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator);
  * @see bt_notification_iterator_get_notification()
  */
 extern enum bt_notification_iterator_status *bt_notification_iterator_seek(
-               struct bt_notification_iterator *iterator,
-               int whence,
+               struct bt_notification_iterator *iterator, int whence,
                int64_t time);
 
 /**
index 9a9332006a477b0e2345fb2ad9b44e71c59351d8..6eee12fbe3dc92ed657fa8c0d564df8c3cbec41a 100644 (file)
@@ -49,20 +49,92 @@ struct bt_component;
 typedef void (*bt_component_destroy_cb)(struct bt_component *component);
 
 /**
- * Iterator creation function type.
+ * 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
+ */
+typedef struct bt_component *(*bt_component_source_init_cb)(
+               struct bt_component *component);
+
+/**
+ * Sink component initialization function type.
+ *
+ * A sink component's notification handling callback, private data and
+ * deinitialization callback must be set by this function.
  *
  * @param component    Component instance
  */
+typedef struct bt_component *(*bt_component_sink_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);
 
-typedef struct bt_component *(*bt_component_init_cb)(
-               struct bt_component *component);
+/**
+ * Get a component's private data.
+ *
+ * @param component    Component of which to get the private data
+ * @returns            Component's private data
+ */
+extern void *bt_component_get_private_data(struct bt_component *component);
 
-typedef struct bt_component *(*bt_component_fini_cb)(
-               struct bt_component *component);
+/**
+ * Set a component's private data.
+ *
+ * @param component    Component of which to set the private data
+ * @param data         Component private data
+ * @returns            One of #bt_component_status values
+ */
+extern enum bt_component_status bt_component_set_private_data(
+               struct bt_component *component, void *data);
+
+/**
+ * Set a component's private data cleanup function.
+ *
+ * @param component    Component of which to set the private data destruction
+ *                     function
+ * @param data         Component private data clean-up function
+ * @returns            One of #bt_component_status values
+ */
+extern enum bt_component_status bt_component_set_destroy_cb(
+               struct bt_component *component,
+               bt_component_destroy_cb destroy);
+
+/** bt_component_souce */
+/**
+ * Iterator initialization function type.
+ *
+ * A notification iterator's private data, deinitialization, next, and get
+ * callbacks must be set by this function.
+ *
+ * @param component    Component instance
+ * @param iterator     Notification iterator instance
+ */
+typedef enum bt_component_status (*bt_component_source_init_iterator_cb)(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator);
 
+/**
+ * Set a source component's iterator initialization function.
+ *
+ * @param component    Component instance
+ * @param init_iterator        Notification iterator initialization callback
+ */
+extern enum bt_component_status
+bt_component_source_set_iterator_init_cb(struct bt_component *component,
+               bt_component_source_init_iterator_cb init_iterator);
+
+/** bt_component_sink */
 /**
  * Notification handling function type.
  *
@@ -73,19 +145,43 @@ typedef struct bt_component *(*bt_component_fini_cb)(
 typedef enum bt_component_status (*bt_component_sink_handle_notification_cb)(
                struct bt_component *, struct bt_notification *);
 
+/**
+ * Set a sink component's notification handling callback.
+ *
+ * @param component            Component instance
+ * @param handle_notification  Notification handling callback
+ * @returns                    One of #bt_component_status values
+ */
+extern enum bt_component_status
+bt_component_sink_set_handle_notification_cb(struct bt_component *component,
+               bt_component_sink_handle_notification_cb handle_notification);
+
+/** bt_component_notification_iterator */
+/**
+ * Function returning an iterator's current notification.
+ *
+ * @param iterator     Notification iterator instance
+ * @returns            A notification instance
+ */
 typedef struct bt_notification *(*bt_notification_iterator_get_cb)(
-               struct bt_notification_iterator *);
+               struct bt_notification_iterator *iterator);
 
+/**
+ * Function advancing an iterator's position.
+ *
+ * @param iterator     Notification iterator instance
+ * @returns            One of #bt_notification_iterator_status values
+ */
 typedef enum bt_notification_iterator_status (*bt_notification_iterator_next_cb)(
-               struct bt_notification_iterator *);
+               struct bt_notification_iterator *iterator);
 
 /**
- * Get a component's private (implementation) data.
+ * Function cleaning-up an iterator's private data on destruction.
  *
- * @param component    Component of which to get the private data
- * @returns            Component's private data
+ * @param iterator     Notification iterator instance
  */
-extern void *bt_component_get_private_data(struct bt_component *component);
+typedef void (*bt_notification_iterator_destroy_cb)(
+               struct bt_notification_iterator *iterator);
 
 extern enum bt_notification_iterator_status
 bt_notification_iterator_set_get_cb(struct bt_notification_iterator *iterator,
@@ -95,6 +191,11 @@ extern enum bt_notification_iterator_status
 bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator,
                bt_notification_iterator_next_cb next);
 
+extern enum bt_notification_iterator_status
+bt_notification_iterator_set_destroy_cb(
+               struct bt_notification_iterator *iterator,
+               bt_notification_iterator_destroy_cb destroy);
+
 extern enum bt_notification_iterator_status
 bt_notification_iterator_set_private_data(
                struct bt_notification_iterator *iterator, void *data);
@@ -102,16 +203,6 @@ bt_notification_iterator_set_private_data(
 extern void *bt_notification_iterator_get_private_data(
                struct bt_notification_iterator *iterator);
 
-/**
- * Set a component's private (implementation) data.
- *
- * @param component    Component of which to set the private data
- * @param data         Component private data
- * @returns            One of #bt_component_status values
- */
-extern enum bt_component_status bt_component_set_private_data(
-               struct bt_component *component, void *data);
-
 #ifdef __cplusplus
 }
 #endif
index ae6dae865a0591aa1ecf0153f71e22aecea44ad7..a8e18499f87c88a4a3663f6ae08fe12871bc2307 100644 (file)
                struct bt_component_factory *factory)\
        {
 
-#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init, _fini, _it_cr) \
+#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_ENTRY(_name, _init) \
        bt_component_factory_register_source_component_class(factory, \
-               _name, _init, _fini, _it_cr);
+               _name, _init);
 
-#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init, _fini, _hd_notif) \
+#define BT_PLUGIN_SINK_COMPONENT_CLASS_ENTRY(_name, _init) \
        bt_component_factory_register_sink_component_class(factory, \
-               _name, _init, _fini, _hd_notif);
+               _name, _init);
 
 #define BT_PLUGIN_COMPONENT_CLASSES_END\
        \
index 30617789559a8d7a376f84c9143cda85c17809c3..b33333871ed5344c3b69597bd3528ed0b64c5341 100644 (file)
@@ -38,4 +38,13 @@ struct bt_component_sink {
        bt_component_sink_handle_notification_cb handle_notification;
 };
 
+/**
+ * Allocate a sink component.
+ *
+ * @param name                 Component instance name (will be copied)
+ * @returns                    A sink component instance
+ */
+BT_HIDDEN
+extern struct bt_component *bt_component_sink_create(const char *name);
+
 #endif /* BABELTRACE_PLUGIN_SINK_INTERNAL_H */
index 0388105309bec560497b53019315ea9e276d314c..1234339ac5da93c51d9256eaee9b41d670316a39 100644 (file)
@@ -35,7 +35,16 @@ struct bt_component_source {
        struct bt_component parent;
 
        /* Component implementation callbacks */
-       bt_component_source_iterator_init_cb init_iterator;
+       bt_component_source_init_iterator_cb init_iterator;
 };
 
+/**
+ * Allocate a source component.
+ *
+ * @param name                 Component instance name (will be copied)
+ * @returns                    A source component instance
+ */
+BT_HIDDEN
+extern struct bt_component *bt_component_source_create(const char *name);
+
 #endif /* BABELTRACE_PLUGIN_SOURCE_INTERNAL_H */
index f977c837e0c7afa5372774af0e4cd85e72abc811..7dbdaaae0c04e3467fa52c47e0412bb79c84e21e 100644 (file)
@@ -109,30 +109,24 @@ void bt_component_put(struct bt_component *component)
 
 BT_HIDDEN
 enum bt_component_status bt_component_init(struct bt_component *component,
-               const char *name, void *user_data,
-               bt_component_destroy_cb user_destroy_func,
-               enum bt_component_type component_type,
-               bt_component_destroy_cb component_destroy)
+               const char *name, enum bt_component_type component_type,
+               bt_component_destroy_cb destroy)
 {
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
 
-       if (!component || !name || name[0] == '\0' ||
-               !user_destroy_func || !user_data || !component_destroy) {
+       if (!component || !name || name[0] == '\0' || destroy) {
                ret = BT_COMPONENT_STATUS_INVAL;
                goto end;
        }
 
        bt_ctf_ref_init(&component->ref_count);
        component->type = component_type;
-       component->user_data = user_data;
-       component->user_data_destroy = user_destroy_func;
-       component->destroy = component_destroy;
-
        component->name = g_string_new(name);
        if (!component->name) {
                ret = BT_COMPONENT_STATUS_NOMEM;
                goto end;
        }
+       component->destroy = destroy;
 end:
        return ret;
 }
@@ -181,8 +175,8 @@ void bt_component_destroy(struct bt_ctf_ref *ref)
         * User data is destroyed first, followed by the concrete component
         * instance.
         */
-       assert(!component->user_data || component->user_data_destroy);
-       component->user_data_destroy(component->user_data);
+       assert(!component->user_data || component->user_destroy);
+       component->user_destroy(component->user_data);
 
        g_string_free(component->name, TRUE);
 
index 66f918c8dbe629a266fd14380c5e915943d970fa..094c2ff010e99922ca503ef76c651942a4f794d1 100644 (file)
 #include <babeltrace/plugin/notification/iterator-internal.h>
 
 static
-void bt_notification_iterator_destroy(struct bt_notification_iterator *iterator)
+void bt_notification_iterator_destroy(struct bt_ctf_ref *ref)
 {
-       
+       struct bt_notification_iterator *iterator;
+
+       if (!ref) {
+               return;
+       }
+
+       iterator = container_of(ref, struct bt_notification_iterator,
+               ref_count);
+       assert(iterator->user_destroy || !iterator->user_data);
+       iterator->user_destroy(iterator);
+       g_free(iterator);
 }
 
 BT_HIDDEN
@@ -44,7 +54,8 @@ struct bt_notification_iterator *bt_notification_iterator_create(
 {
        struct bt_notification_iterator *iterator = NULL;
 
-       if (!component || bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
+       if (!component ||
+               bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) {
                goto end;
        }
 
@@ -62,7 +73,8 @@ BT_HIDDEN
 enum bt_notification_iterator_status bt_notification_iterator_validate(
                struct bt_notification_iterator *iterator)
 {
-       enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
+       enum bt_notification_iterator_status ret =
+               BT_NOTIFICATION_ITERATOR_STATUS_OK;
 
        if (!iterator || !iterator->get || !iterator->next) {
                ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
@@ -89,3 +101,19 @@ void bt_notification_iterator_put(struct bt_notification_iterator *iterator)
 
        bt_ctf_ref_put(&iterator->ref_count, bt_notification_iterator_destroy);
 }
+
+enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
+               struct bt_notification_iterator *iterator,
+               bt_notification_iterator_get_cb get)
+{
+       enum bt_notification_iterator_status ret;
+
+       if (!iterator || !get) {
+               ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL;
+               goto end;
+       }
+
+       
+end:
+       return ret;
+}
index fcbc94857f215e57db05e6ff38a1e05f871f2e95..9647f2191bd3c5c28470d953f8e046b8473a4641 100644 (file)
@@ -43,32 +43,24 @@ void bt_component_sink_destroy(struct bt_component *component)
        g_free(sink);
 }
 
-struct bt_component *bt_component_sink_create(const char *name,
-               void *private_data, bt_component_destroy_cb destroy_func,
-               bt_component_sink_handle_notification_cb notification_cb)
+BT_HIDDEN
+struct bt_component *bt_component_sink_create(const char *name)
 {
        struct bt_component_sink *sink = NULL;
        enum bt_component_status ret;
 
-       if (!notification_cb) {
-               goto end;
-       }
-
        sink = g_new0(struct bt_component_sink, 1);
        if (!sink) {
                goto end;
        }
 
-       ret = bt_component_init(&sink->parent, name, private_data,
-                               destroy_func, BT_COMPONENT_TYPE_SINK,
-                               bt_component_sink_destroy);
+       ret = bt_component_init(&sink->parent, name, BT_COMPONENT_TYPE_SINK,
+               bt_component_sink_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
                g_free(sink);
                sink = NULL;
                goto end;
        }
-
-       sink->handle_notification = notification_cb;
 end:
        return sink ? &sink->parent : NULL;
 }
index b722059bd0823273cbee62b6c86fc1ebde804dc6..094cab24cb2c1ac39de06b3635ffd263190f9bcf 100644 (file)
@@ -45,32 +45,23 @@ void bt_component_source_destroy(struct bt_component *component)
        g_free(source);
 }
 
-struct bt_component *bt_component_source_create(const char *name,
-               void *private_data, bt_component_destroy_cb destroy_func,
-               bt_component_source_iterator_init_cb iterator_init_cb)
+BT_HIDDEN
+struct bt_component *bt_component_source_create(const char *name)
 {
        struct bt_component_source *source = NULL;
        enum bt_component_status ret;
-
-       if (!iterator_init_cb) {
-               goto end;
-       }
-
        source = g_new0(struct bt_component_source, 1);
        if (!source) {
                goto end;
        }
 
-       ret = bt_component_init(&source->parent, name, private_data,
-               destroy_func, BT_COMPONENT_TYPE_SOURCE,
-               bt_component_source_destroy);
+       ret = bt_component_init(&source->parent, name,
+               BT_COMPONENT_TYPE_SOURCE, bt_component_source_destroy);
        if (ret != BT_COMPONENT_STATUS_OK) {
                g_free(source);
                source = NULL;
                goto end;
        }
-
-       source->init_iterator = iterator_init_cb;
 end:
        return source ? &source->parent : NULL;
 }
This page took 0.03351 seconds and 4 git commands to generate.