From 6358c163b3144a6b76e316f3333aaab31c4c440a Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 26 Jan 2017 05:22:16 -0500 Subject: [PATCH] Add bt_component_create_with_init_method_data() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jérémie Galarneau --- include/babeltrace/component/component-class.h | 3 ++- include/babeltrace/component/component.h | 4 ++++ lib/component/component.c | 16 ++++++++++++---- plugins/ctf/fs/fs.c | 3 ++- plugins/ctf/fs/fs.h | 2 +- plugins/ctf/lttng-live/lttng-live-internal.h | 2 +- plugins/ctf/lttng-live/lttng-live.c | 2 +- plugins/muxer/muxer.c | 4 +++- plugins/text/text.c | 4 +++- plugins/trimmer/trimmer.c | 4 +++- plugins/writer/writer.c | 4 +++- 11 files changed, 35 insertions(+), 13 deletions(-) diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index ccb776f0..d6f76ca8 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -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); diff --git a/include/babeltrace/component/component.h b/include/babeltrace/component/component.h index 08de0d74..b6a4830c 100644 --- a/include/babeltrace/component/component.h +++ b/include/babeltrace/component/component.h @@ -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. * diff --git a/lib/component/component.c b/lib/component/component.c index c188261c..c3ccd95c 100644 --- a/lib/component/component.c +++ b/lib/component/component.c @@ -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; diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index d3fcf0f0..75be8f13 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -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; diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 2cef5fb5..7ade621f 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -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); diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index d26ec853..bb3c4e43 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -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 */ diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index d797cbd1..cac22503 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -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; } diff --git a/plugins/muxer/muxer.c b/plugins/muxer/muxer.c index ba4e2c4e..cbc65c4a 100644 --- a/plugins/muxer/muxer.c +++ b/plugins/muxer/muxer.c @@ -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; diff --git a/plugins/text/text.c b/plugins/text/text.c index 109ac4af..2652e6b2 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -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; diff --git a/plugins/trimmer/trimmer.c b/plugins/trimmer/trimmer.c index 1f9f48a3..2848c800 100644 --- a/plugins/trimmer/trimmer.c +++ b/plugins/trimmer/trimmer.c @@ -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; diff --git a/plugins/writer/writer.c b/plugins/writer/writer.c index 320642f9..4b36757f 100644 --- a/plugins/writer/writer.c +++ b/plugins/writer/writer.c @@ -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; -- 2.34.1