Add bt_component_create_with_init_method_data()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 26 Jan 2017 10:22:16 +0000 (05:22 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:37 +0000 (12:57 -0400)
This function has one more parameter than bt_component_create():
custom user data (void *) which is passed directly to the
init. method (if any) of the used component class. Nothing else
is done by the lib with this data.

bt_component_create() is a specific version of
bt_component_create_with_init_method_data() which passes NULL
as the init. method data.

You can use this custom data to exchange specific data between
an application and a component class. It is not recommended to
rely on this function when you implement Babeltrace plugins.

A component initialization method now has an additional parameter,
init_method_data.

This initialization method data is not related at all to a
component's private data: you can set the init. method data as
the component's private data, but it's just a design choice.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/component/component-class.h
include/babeltrace/component/component.h
lib/component/component.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h
plugins/ctf/lttng-live/lttng-live-internal.h
plugins/ctf/lttng-live/lttng-live.c
plugins/muxer/muxer.c
plugins/text/text.c
plugins/trimmer/trimmer.c
plugins/writer/writer.c

index ccb776f02ad8f87a2e2b64575a756319b345af4b..d6f76ca831f00315a33592da6dd9cb5367681b16 100644 (file)
@@ -50,7 +50,8 @@ enum bt_component_class_type {
 };
 
 typedef enum bt_component_status (*bt_component_class_init_method)(
-               struct bt_component *component, struct bt_value *params);
+               struct bt_component *component, struct bt_value *params,
+               void *init_method_data);
 
 typedef void (*bt_component_class_destroy_method)(struct bt_component *component);
 
index 08de0d74c8b3ace711233f8bcc8a653f117233df..b6a4830c3007dd4b551316500028ff70e49cc4e5 100644 (file)
@@ -74,6 +74,10 @@ extern struct bt_component *bt_component_create(
                struct bt_component_class *component_class, const char *name,
                struct bt_value *params);
 
+extern struct bt_component *bt_component_create_with_init_method_data(
+               struct bt_component_class *component_class, const char *name,
+               struct bt_value *params, void *init_method_data);
+
 /**
  * Get a component's private data.
  *
index c188261c7554bcca85088e132359bf45d19c952f..c3ccd95c57edf569498c3b725c4be2d6e0de6e49 100644 (file)
@@ -177,9 +177,9 @@ error:
        return iterator;
 }
 
-struct bt_component *bt_component_create(
+struct bt_component *bt_component_create_with_init_method_data(
                struct bt_component_class *component_class, const char *name,
-               struct bt_value *params)
+               struct bt_value *params, void *init_method_data)
 {
        int ret;
        struct bt_component *component = NULL;
@@ -189,7 +189,6 @@ struct bt_component *bt_component_create(
                goto end;
        }
 
-
        type = bt_component_class_get_type(component_class);
        if (type <= BT_COMPONENT_CLASS_TYPE_UNKNOWN ||
                        type > BT_COMPONENT_CLASS_TYPE_FILTER) {
@@ -211,7 +210,8 @@ struct bt_component *bt_component_create(
        component->initializing = true;
 
        if (component_class->methods.init) {
-               ret = component_class->methods.init(component, params);
+               ret = component_class->methods.init(component, params,
+                       init_method_data);
                component->initializing = false;
                if (ret != BT_COMPONENT_STATUS_OK) {
                        BT_PUT(component);
@@ -231,6 +231,14 @@ end:
        return component;
 }
 
+struct bt_component *bt_component_create(
+               struct bt_component_class *component_class, const char *name,
+               struct bt_value *params)
+{
+       return bt_component_create_with_init_method_data(component_class, name,
+               params, NULL);
+}
+
 const char *bt_component_get_name(struct bt_component *component)
 {
        const char *ret = NULL;
index d3fcf0f0f735694ff273f44697970ddef3d8e79d..75be8f13a552b2b0ee164821e61e50612508baa8 100644 (file)
@@ -723,10 +723,11 @@ end:
 
 BT_HIDDEN
 enum bt_component_status ctf_fs_init(struct bt_component *source,
-               struct bt_value *params)
+               struct bt_value *params, void *init_method_data)
 {
        struct ctf_fs_component *ctf_fs;
        enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
+       (void) init_method_data;
 
        assert(source);
        ctf_fs_debug = g_strcmp0(getenv("CTF_FS_DEBUG"), "1") == 0;
index 2cef5fb5d06ea8fe6d3305d75b54d001fd21d4f9..7ade621f89f65ff626e008906053ad67629b9e07 100644 (file)
@@ -107,7 +107,7 @@ struct ctf_fs_component {
 
 BT_HIDDEN
 enum bt_component_status ctf_fs_init(struct bt_component *source,
-               struct bt_value *params);
+               struct bt_value *params, void *init_method_data);
 
 BT_HIDDEN
 void ctf_fs_destroy(struct bt_component *component);
index d26ec853b6adbdf97269ad536ef47f7df22fe97b..bb3c4e43cad020b8fd6888d8e4bed7ba1ba4f332 100644 (file)
@@ -38,6 +38,6 @@ enum bt_component_status lttng_live_iterator_init(struct bt_component *source,
 
 BT_HIDDEN
 enum bt_component_status lttng_live_init(struct bt_component *source,
-               struct bt_value *params);
+               struct bt_value *params, void *init_method_data);
 
 #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H */
index d797cbd18a5fb697f417b1f8f05028e26e895e0f..cac2250316fbdcbb66811783003e65e8fd0e4b27 100644 (file)
@@ -37,7 +37,7 @@ enum bt_component_status lttng_live_iterator_init(struct bt_component *source,
 
 BT_HIDDEN
 enum bt_component_status lttng_live_init(struct bt_component *component,
-               struct bt_value *params)
+               struct bt_value *params, void *init_method_data)
 {
        return BT_COMPONENT_STATUS_OK;
 }
index ba4e2c4e4e967ea91bceda81c2fecc2558d74403..cbc65c4a6b6a6329f0939e2f037699ea15f7da96 100644 (file)
@@ -62,10 +62,12 @@ void destroy_muxer(struct bt_component *component)
 }
 
 enum bt_component_status muxer_component_init(
-       struct bt_component *component, struct bt_value *params)
+       struct bt_component *component, struct bt_value *params,
+       void *init_method_data)
 {
        enum bt_component_status ret;
        struct muxer *muxer = create_muxer();
+       (void) init_method_data;
 
        if (!muxer) {
                ret = BT_COMPONENT_STATUS_NOMEM;
index 109ac4af64be07d97eef71d5cf81456e789d4224..2652e6b2f13ecef5b5ebf1b4467c69414015e5c4 100644 (file)
@@ -604,10 +604,12 @@ end:
 
 static
 enum bt_component_status text_component_init(
-               struct bt_component *component, struct bt_value *params)
+               struct bt_component *component, struct bt_value *params,
+               void *init_method_data)
 {
        enum bt_component_status ret;
        struct text_component *text = create_text();
+       (void) init_method_data;
 
        if (!text) {
                ret = BT_COMPONENT_STATUS_NOMEM;
index 1f9f48a3cc5cd37f88a34b2b0ca95b8aba24b4b0..2848c8006df976b33ed1ca9e13c1b199c0fec3a2 100644 (file)
@@ -349,10 +349,12 @@ end:
 }
 
 enum bt_component_status trimmer_component_init(
-       struct bt_component *component, struct bt_value *params)
+       struct bt_component *component, struct bt_value *params,
+       void *init_method_data)
 {
        enum bt_component_status ret;
        struct trimmer *trimmer = create_trimmer_data();
+       (void) init_method_data;
 
        if (!trimmer) {
                ret = BT_COMPONENT_STATUS_NOMEM;
index 320642f9a73d6058b368217940c74752138f5d58..4b36757fb628cba75b0647c2a380facdfd1ab6fc 100644 (file)
@@ -213,13 +213,15 @@ end:
 
 static
 enum bt_component_status writer_component_init(
-       struct bt_component *component, struct bt_value *params)
+       struct bt_component *component, struct bt_value *params,
+       void *init_method_data)
 {
        enum bt_component_status ret;
        enum bt_value_status value_ret;
        struct writer_component *writer_component = create_writer_component();
        struct bt_value *value = NULL;
        const char *path;
+       (void) init_method_data;
 
        if (!writer_component) {
                ret = BT_COMPONENT_STATUS_NOMEM;
This page took 0.039449 seconds and 4 git commands to generate.