From d3e4dcd8e7a601e0aa063455147f29fbe051582b Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 26 Jan 2017 04:03:19 -0500 Subject: [PATCH] Refactor the component class and component API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch modifies the component class and component API so that the user sets methods to the component class objects, not to the component objects. This makes sense following the typical object-oriented paradigm. Changes: * bt_component_class_create() is removed. You need to use a component class-specific function to create one, amongst: * bt_component_class_source_create() * bt_component_class_filter_create() * bt_component_class_sink_create() All the parameters of those functions are mandatory: they are the name and the mandatory _methods_ of the class, depending on the type. * Component class-specific functions are declared in their own header: * babeltrace/component/component-class-source.h * babeltrace/component/component-class-filter.h * babeltrace/component/component-class-sink.h babeltrace/component/component-class.h only contains functions which you can use on any component class, whatever the type. * enum bt_component_type and BT_COMPONENT_TYPE_* are renamed to enum bt_component_class_type and BT_COMPONENT_CLASS_TYPE_* since the type is a property of the component class. * Once a component class is created, you can use functions to set optional methods: * bt_component_class_filter_set_add_iterator_method() * bt_component_class_sink_set_add_iterator_method() The component initialization and destroy methods are now both optional: * bt_component_class_set_init_method() * bt_component_class_set_destroy_method() You can also set the optional description with a function: * bt_component_class_set_description() * New public utility function: bt_component_get_class_type(): returns the type of a component's class. * Component functions which are specific to a class type are moved to their respective header in babeltrace/component (source.h, filter.h, sink.h). * Plugin development interface (babeltrace/plugin/plugin-dev.h) is updated to follow the API changes. Component class descriptor macros contain the component class type in their name, for example: BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION() BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD() BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD() * Existing plugins, tests, and the command-line converter are updated to follow the API changes. * Other very minor fixes. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- converter/babeltrace.c | 20 +- include/Makefile.am | 3 + .../component/component-class-filter.h | 50 +++ .../component/component-class-internal.h | 38 +- .../component/component-class-sink.h | 54 +++ .../component/component-class-source.h | 47 ++ .../babeltrace/component/component-class.h | 42 +- .../babeltrace/component/component-internal.h | 16 +- include/babeltrace/component/component.h | 229 +--------- .../babeltrace/component/filter-internal.h | 6 - include/babeltrace/component/filter.h | 19 + include/babeltrace/component/sink-internal.h | 6 - include/babeltrace/component/sink.h | 19 + .../babeltrace/component/source-internal.h | 5 - include/babeltrace/plugin/plugin-dev.h | 414 ++++++++++++++++-- include/babeltrace/plugin/plugin.h | 2 +- lib/component/component-class.c | 243 ++++++++-- lib/component/component.c | 95 ++-- lib/component/filter.c | 73 +-- lib/component/iterator.c | 8 +- lib/component/sink.c | 90 +--- lib/component/source.c | 27 +- lib/plugin/plugin.c | 142 +++++- plugins/ctf/fs/fs.c | 13 - plugins/ctf/fs/fs.h | 7 + plugins/ctf/lttng-live/lttng-live-internal.h | 4 + plugins/ctf/lttng-live/lttng-live.c | 6 + plugins/ctf/plugin.c | 18 +- plugins/muxer/muxer.c | 20 +- plugins/text/text.c | 20 +- plugins/trimmer/trimmer.c | 19 +- plugins/writer/writer.c | 20 +- tests/lib/test-plugin-plugins/sfs.c | 38 +- tests/lib/test_plugin.c | 8 +- 34 files changed, 1151 insertions(+), 670 deletions(-) create mode 100644 include/babeltrace/component/component-class-filter.h create mode 100644 include/babeltrace/component/component-class-sink.h create mode 100644 include/babeltrace/component/component-class-source.h diff --git a/converter/babeltrace.c b/converter/babeltrace.c index f884467e..ca94cb82 100644 --- a/converter/babeltrace.c +++ b/converter/babeltrace.c @@ -81,7 +81,7 @@ struct bt_plugin *find_plugin(const char *name) static struct bt_component_class *find_component_class(const char *plugin_name, const char *comp_class_name, - enum bt_component_type comp_class_type) + enum bt_component_class_type comp_class_type) { struct bt_component_class *comp_class = NULL; struct bt_plugin *plugin = find_plugin(plugin_name); @@ -98,16 +98,16 @@ end: } static -const char *component_type_str(enum bt_component_type type) +const char *component_type_str(enum bt_component_class_type type) { switch (type) { - case BT_COMPONENT_TYPE_SOURCE: + case BT_COMPONENT_CLASS_TYPE_SOURCE: return "source"; - case BT_COMPONENT_TYPE_SINK: + case BT_COMPONENT_CLASS_TYPE_SINK: return "sink"; - case BT_COMPONENT_TYPE_FILTER: + case BT_COMPONENT_CLASS_TYPE_FILTER: return "filter"; - case BT_COMPONENT_TYPE_UNKNOWN: + case BT_COMPONENT_CLASS_TYPE_UNKNOWN: default: return "unknown"; } @@ -157,7 +157,7 @@ void print_component_classes_found(void) bt_plugin_get_description(plugin); const char *comp_class_description = bt_component_class_get_description(comp_class); - enum bt_component_type type = + enum bt_component_class_type type = bt_component_class_get_type(comp_class); printf_verbose("[%s - %s (%s)]\n", plugin_name, @@ -356,7 +356,7 @@ struct bt_component *create_trimmer(struct bt_config_component *source_cfg) } trimmer_class = find_component_class("utils", "trimmer", - BT_COMPONENT_TYPE_FILTER); + BT_COMPONENT_CLASS_TYPE_FILTER); if (!trimmer_class) { fprintf(stderr, "Could not find trimmer component class. Aborting...\n"); goto end; @@ -575,7 +575,7 @@ int main(int argc, const char **argv) source_params = bt_get(source_cfg->params); source_class = find_component_class(source_cfg->plugin_name->str, source_cfg->component_name->str, - BT_COMPONENT_TYPE_SOURCE); + BT_COMPONENT_CLASS_TYPE_SOURCE); if (!source_class) { fprintf(stderr, "Could not find %s.%s source component class. Aborting...\n", source_cfg->plugin_name->str, @@ -588,7 +588,7 @@ int main(int argc, const char **argv) sink_params = bt_get(sink_cfg->params); sink_class = find_component_class(sink_cfg->plugin_name->str, sink_cfg->component_name->str, - BT_COMPONENT_TYPE_SINK); + BT_COMPONENT_CLASS_TYPE_SINK); if (!sink_class) { fprintf(stderr, "Could not find %s.%s output component class. Aborting...\n", sink_cfg->plugin_name->str, diff --git a/include/Makefile.am b/include/Makefile.am index bcd1994a..33ac2673 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -44,6 +44,9 @@ babeltraceplugininclude_HEADERS = \ babeltracecomponentinclude_HEADERS = \ babeltrace/component/component.h \ babeltrace/component/component-class.h \ + babeltrace/component/component-class-source.h \ + babeltrace/component/component-class-filter.h \ + babeltrace/component/component-class-sink.h \ babeltrace/component/component-connection.h \ babeltrace/component/component-graph.h \ babeltrace/component/source.h \ diff --git a/include/babeltrace/component/component-class-filter.h b/include/babeltrace/component/component-class-filter.h new file mode 100644 index 00000000..9eaf4a09 --- /dev/null +++ b/include/babeltrace/component/component-class-filter.h @@ -0,0 +1,50 @@ +#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H +#define BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H + +/* + * Babeltrace - Component Class Interface. + * + * Copyright 2016 Jérémie Galarneau + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class; + +typedef enum bt_component_status (*bt_component_class_filter_init_iterator_method)( + struct bt_component *, struct bt_notification_iterator *); + +typedef enum bt_component_status (*bt_component_class_filter_add_iterator_method)( + struct bt_component *, struct bt_notification_iterator *); + +extern +struct bt_component_class *bt_component_class_filter_create(const char *name, + bt_component_class_filter_init_iterator_method init_iterator_method); + +extern int bt_component_class_filter_set_add_iterator_method( + struct bt_component_class *component_class, + bt_component_class_filter_add_iterator_method add_iterator_method); + +#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_FILTER_H */ diff --git a/include/babeltrace/component/component-class-internal.h b/include/babeltrace/component/component-class-internal.h index 7ed0f163..320a7d93 100644 --- a/include/babeltrace/component/component-class-internal.h +++ b/include/babeltrace/component/component-class-internal.h @@ -30,6 +30,9 @@ #include #include +#include +#include +#include #include #include #include @@ -39,22 +42,47 @@ struct bt_component_class; typedef void (*bt_component_class_destroy_listener_func)( struct bt_component_class *class, void *data); -struct bt_component_class_destroyer_listener { +struct bt_component_class_destroy_listener { bt_component_class_destroy_listener_func func; void *data; }; struct bt_component_class { struct bt_object base; - enum bt_component_type type; + enum bt_component_class_type type; GString *name; GString *description; - bt_component_init_cb init; - - /* Array of struct bt_component_class_destroyer_listener */ + struct { + bt_component_class_init_method init; + bt_component_class_destroy_method destroy; + } methods; + /* Array of struct bt_component_class_destroy_listener */ GArray *destroy_listeners; }; +struct bt_component_class_source { + struct bt_component_class parent; + struct { + bt_component_class_source_init_iterator_method init_iterator; + } methods; +}; + +struct bt_component_class_sink { + struct bt_component_class parent; + struct { + bt_component_class_sink_consume_method consume; + bt_component_class_sink_add_iterator_method add_iterator; + } methods; +}; + +struct bt_component_class_filter { + struct bt_component_class parent; + struct { + bt_component_class_filter_init_iterator_method init_iterator; + bt_component_class_filter_add_iterator_method add_iterator; + } methods; +}; + BT_HIDDEN int bt_component_class_add_destroy_listener(struct bt_component_class *class, bt_component_class_destroy_listener_func func, void *data); diff --git a/include/babeltrace/component/component-class-sink.h b/include/babeltrace/component/component-class-sink.h new file mode 100644 index 00000000..5f89bc81 --- /dev/null +++ b/include/babeltrace/component/component-class-sink.h @@ -0,0 +1,54 @@ +#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H +#define BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H + +/* + * Babeltrace - Component Class Interface. + * + * Copyright 2016 Jérémie Galarneau + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class; + +typedef enum bt_component_status (*bt_component_class_sink_consume_method)( + struct bt_component *); + +typedef enum bt_component_status (*bt_component_class_sink_add_iterator_method)( + struct bt_component *, struct bt_notification_iterator *); + +extern +struct bt_component_class *bt_component_class_sink_create(const char *name, + bt_component_class_sink_consume_method consume_method); + +extern int bt_component_class_sink_set_add_iterator_method( + struct bt_component_class *component_class, + bt_component_class_sink_add_iterator_method add_iterator_method); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_SINK_H */ diff --git a/include/babeltrace/component/component-class-source.h b/include/babeltrace/component/component-class-source.h new file mode 100644 index 00000000..d0b94872 --- /dev/null +++ b/include/babeltrace/component/component-class-source.h @@ -0,0 +1,47 @@ +#ifndef BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H +#define BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H + +/* + * Babeltrace - Component Class Interface. + * + * Copyright 2016 Jérémie Galarneau + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_component_class; + +typedef enum bt_component_status (*bt_component_class_source_init_iterator_method)( + struct bt_component *, struct bt_notification_iterator *); + +extern +struct bt_component_class *bt_component_class_source_create(const char *name, + bt_component_class_source_init_iterator_method init_iterator_method); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_SOURCE_H */ diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index c3359fe2..ad259b29 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -31,12 +31,40 @@ extern "C" { #endif -struct bt_plugin; struct bt_component_class; -extern struct bt_component_class *bt_component_class_create( - enum bt_component_type type, const char *name, - const char *description, bt_component_init_cb init); +/** + * Component class type. + */ +enum bt_component_class_type { + BT_COMPONENT_CLASS_TYPE_UNKNOWN = -1, + + /** A source component is a notification generator. */ + BT_COMPONENT_CLASS_TYPE_SOURCE = 0, + + /** A sink component handles incoming notifications. */ + BT_COMPONENT_CLASS_TYPE_SINK = 1, + + /** A filter component implements both Source and Sink interfaces. */ + BT_COMPONENT_CLASS_TYPE_FILTER = 2, +}; + +typedef enum bt_component_status (*bt_component_class_init_method)( + struct bt_component *component, struct bt_value *params); + +typedef void (*bt_component_class_destroy_method)(struct bt_component *component); + +extern int bt_component_class_set_init_method( + struct bt_component_class *component_class, + bt_component_class_init_method init_method); + +extern int bt_component_class_set_destroy_method( + struct bt_component_class *component_class, + bt_component_class_destroy_method destroy_method); + +extern int bt_component_class_set_description( + struct bt_component_class *component_class, + const char *description); /** * Get a component class' name. @@ -65,7 +93,11 @@ extern const char *bt_component_class_get_description( * @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( +extern enum bt_component_class_type bt_component_class_get_type( struct bt_component_class *component_class); +#ifdef __cplusplus +} +#endif + #endif /* BABELTRACE_COMPONENT_COMPONENT_CLASS_H */ diff --git a/include/babeltrace/component/component-internal.h b/include/babeltrace/component/component-internal.h index 7c18f494..dadaa75b 100644 --- a/include/babeltrace/component/component-internal.h +++ b/include/babeltrace/component/component-internal.h @@ -38,12 +38,15 @@ struct bt_component { struct bt_object base; struct bt_component_class *class; GString *name; - /** Source, Sink or Filter destroy */ - bt_component_destroy_cb destroy; - /** User-defined data and its destruction callback */ + /** + * Internal destroy function specific to a source, filter, or + * sink component object. + */ + bt_component_class_destroy_method destroy; + + /** User-defined data */ void *user_data; - bt_component_destroy_cb user_destroy; /** * Used to protect operations which may only be used during @@ -54,10 +57,7 @@ struct bt_component { BT_HIDDEN enum bt_component_status bt_component_init(struct bt_component *component, - bt_component_destroy_cb destroy); - -BT_HIDDEN -enum bt_component_type bt_component_get_type(struct bt_component *component); + bt_component_class_destroy_method destroy); BT_HIDDEN struct bt_notification_iterator *bt_component_create_iterator( diff --git a/include/babeltrace/component/component.h b/include/babeltrace/component/component.h index 2645c13c..08de0d74 100644 --- a/include/babeltrace/component/component.h +++ b/include/babeltrace/component/component.h @@ -35,22 +35,6 @@ extern "C" { #endif -/** - * Component type. - */ -enum bt_component_type { - BT_COMPONENT_TYPE_UNKNOWN = -1, - - /** A source component is a notification generator. */ - BT_COMPONENT_TYPE_SOURCE = 0, - - /** A sink component handles incoming notifications. */ - BT_COMPONENT_TYPE_SINK = 1, - - /** A filter component implements both Source and Sink interfaces. */ - BT_COMPONENT_TYPE_FILTER = 2, -}; - /** * Status code. Errors are always negative. */ @@ -79,25 +63,16 @@ struct bt_component; struct bt_value; /** - * Component private data deallocation function type. - * - * @param component Component instance - */ -typedef void (*bt_component_destroy_cb)(struct bt_component *component); - -/** - * Component initialization function type. - * - * A component's private data and required callbacks must be set by this - * function. + * Create an instance of a component from a component class. * - * @param component Component instance - * @param params A dictionary of component parameters - * @returns One of #bt_component_status values + * @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 */ -typedef enum bt_component_status (*bt_component_init_cb)( - struct bt_component *component, struct bt_value *params); - +extern struct bt_component *bt_component_create( + struct bt_component_class *component_class, const char *name, + struct bt_value *params); /** * Get a component's private data. @@ -117,181 +92,6 @@ extern void *bt_component_get_private_data(struct bt_component *component); 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 source Source component instance - * @param iterator Notification iterator instance - */ -typedef enum bt_component_status (*bt_component_source_init_iterator_cb)( - struct bt_component *, struct bt_notification_iterator *); - -/** - * Set a source component's iterator initialization function. - * - * @param source Source component instance - * @param init_iterator Notification iterator initialization callback - */ -extern enum bt_component_status -bt_component_source_set_iterator_init_cb(struct bt_component *source, - bt_component_source_init_iterator_cb init_iterator); - -/** bt_component_sink */ -/** - * Notification consumption function type. - * - * @param sink Sink component instance - * @returns One of #bt_component_status values - */ -typedef enum bt_component_status (*bt_component_sink_consume_cb)( - struct bt_component *); - -/** - * Iterator addition function type. - * - * A sink component may choose to refuse the addition of an iterator - * by not returning BT_COMPONENT_STATUS_OK. - * - * @param sink Sink component instance - * @returns One of #bt_component_status values - */ -typedef enum bt_component_status (*bt_component_sink_add_iterator_cb)( - struct bt_component *, struct bt_notification_iterator *); - -/** - * Set a sink component's consumption callback. - * - * @param sink Sink component instance - * @param consume Consumption callback - * @returns One of #bt_component_status values - */ -extern enum bt_component_status -bt_component_sink_set_consume_cb(struct bt_component *sink, - bt_component_sink_consume_cb consume); - -/** - * Set a sink component's iterator addition callback. - * - * @param sink Sink component instance - * @param add_iterator Iterator addition callback - * @returns One of #bt_component_status values - */ -extern enum bt_component_status -bt_component_sink_set_add_iterator_cb(struct bt_component *sink, - bt_component_sink_add_iterator_cb add_iterator); - -/* Defaults to 1. */ -extern enum bt_component_status -bt_component_sink_set_minimum_input_count(struct bt_component *sink, - unsigned int minimum); - -/* Defaults to 1. */ -extern enum bt_component_status -bt_component_sink_set_maximum_input_count(struct bt_component *sink, - unsigned int maximum); - -extern enum bt_component_status -bt_component_sink_get_input_count(struct bt_component *sink, - unsigned int *count); - -/* May return NULL after an interator has reached its end. */ -extern enum bt_component_status -bt_component_sink_get_input_iterator(struct bt_component *sink, - unsigned int input, struct bt_notification_iterator **iterator); - -/** bt_component_filter */ -/** - * Iterator initialization function type. - * - * A notification iterator's private data, deinitialization, next, and get - * callbacks must be set by this function. - * - * @param filter Filter component instance - * @param iterator Notification iterator instance - */ -typedef enum bt_component_status (*bt_component_filter_init_iterator_cb)( - struct bt_component *, struct bt_notification_iterator *); - -/** - * Iterator addition function type. - * - * A filter component may choose to refuse the addition of an iterator - * by not returning BT_COMPONENT_STATUS_OK. - * - * @param filter Filter component instance - * @returns One of #bt_component_status values - */ -typedef enum bt_component_status (*bt_component_filter_add_iterator_cb)( - struct bt_component *, struct bt_notification_iterator *); - -/** - * Set a filter component's iterator initialization function. - * - * @param filter Filter component instance - * @param init_iterator Notification iterator initialization callback - */ -extern enum bt_component_status -bt_component_filter_set_iterator_init_cb(struct bt_component *filter, - bt_component_filter_init_iterator_cb init_iterator); - -/** - * Set a filter component's iterator addition callback. - * - * @param filter Filter component instance - * @param add_iterator Iterator addition callback - * @returns One of #bt_component_status values - */ -extern enum bt_component_status -bt_component_filter_set_add_iterator_cb(struct bt_component *filter, - bt_component_filter_add_iterator_cb add_iterator); - -/* Defaults to 1. */ -extern enum bt_component_status -bt_component_filter_set_minimum_input_count(struct bt_component *filter, - unsigned int minimum); - -/* Defaults to 1. */ -extern enum bt_component_status -bt_component_filter_set_maximum_input_count(struct bt_component *filter, - unsigned int maximum); - -extern enum bt_component_status -bt_component_filter_get_input_count(struct bt_component *filter, - unsigned int *count); - -/* May return NULL after an interator has reached its end. */ -extern enum bt_component_status -bt_component_filter_get_input_iterator(struct bt_component *filter, - unsigned int input, struct bt_notification_iterator **iterator); - -/** - * 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_value *params); - /** * Get component's name. * @@ -300,16 +100,6 @@ extern struct bt_component *bt_component_create( */ extern const char *bt_component_get_name(struct bt_component *component); -/** - * Set component's name. - * - * @param component Component instance of which to set the name - * @param name New component name (will be copied) - * @returns One of #bt_component_status values - */ -extern enum bt_component_status bt_component_set_name( - struct bt_component *component, const char *name); - /** * Get component's class. * @@ -319,6 +109,9 @@ extern enum bt_component_status bt_component_set_name( extern struct bt_component_class *bt_component_get_class( struct bt_component *component); +extern enum bt_component_class_type bt_component_get_class_type( + struct bt_component *component); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/filter-internal.h b/include/babeltrace/component/filter-internal.h index 3a17aa00..5ae007fa 100644 --- a/include/babeltrace/component/filter-internal.h +++ b/include/babeltrace/component/filter-internal.h @@ -34,14 +34,8 @@ struct bt_value; -struct bt_component_filter_class { - struct bt_component_class parent; -}; - struct bt_component_filter { struct bt_component parent; - bt_component_filter_init_iterator_cb init_iterator; - bt_component_sink_add_iterator_cb add_iterator; struct component_input input; }; diff --git a/include/babeltrace/component/filter.h b/include/babeltrace/component/filter.h index f33d49f7..64e6ef96 100644 --- a/include/babeltrace/component/filter.h +++ b/include/babeltrace/component/filter.h @@ -59,6 +59,25 @@ extern struct bt_notification_iterator *bt_component_filter_create_iterator( struct bt_component *component); +/* Defaults to 1. */ +extern enum bt_component_status +bt_component_filter_set_minimum_input_count(struct bt_component *filter, + unsigned int minimum); + +/* Defaults to 1. */ +extern enum bt_component_status +bt_component_filter_set_maximum_input_count(struct bt_component *filter, + unsigned int maximum); + +extern enum bt_component_status +bt_component_filter_get_input_count(struct bt_component *filter, + unsigned int *count); + +/* May return NULL after an interator has reached its end. */ +extern enum bt_component_status +bt_component_filter_get_input_iterator(struct bt_component *filter, + unsigned int input, struct bt_notification_iterator **iterator); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/sink-internal.h b/include/babeltrace/component/sink-internal.h index 41733c39..30b066c6 100644 --- a/include/babeltrace/component/sink-internal.h +++ b/include/babeltrace/component/sink-internal.h @@ -34,16 +34,10 @@ struct bt_value; -struct bt_component_sink_class { - struct bt_component_class parent; -}; - //typedef uint32_t notification_mask_t; struct bt_component_sink { struct bt_component parent; - bt_component_sink_consume_cb consume; - bt_component_sink_add_iterator_cb add_iterator; struct component_input input; /* notification_mask_t registered_notifications_mask;*/ }; diff --git a/include/babeltrace/component/sink.h b/include/babeltrace/component/sink.h index 31b5b67f..a37221d5 100644 --- a/include/babeltrace/component/sink.h +++ b/include/babeltrace/component/sink.h @@ -58,6 +58,25 @@ extern enum bt_component_status bt_component_sink_consume( struct bt_component *component); +/* Defaults to 1. */ +extern enum bt_component_status +bt_component_sink_set_minimum_input_count(struct bt_component *sink, + unsigned int minimum); + +/* Defaults to 1. */ +extern enum bt_component_status +bt_component_sink_set_maximum_input_count(struct bt_component *sink, + unsigned int maximum); + +extern enum bt_component_status +bt_component_sink_get_input_count(struct bt_component *sink, + unsigned int *count); + +/* May return NULL after an interator has reached its end. */ +extern enum bt_component_status +bt_component_sink_get_input_iterator(struct bt_component *sink, + unsigned int input, struct bt_notification_iterator **iterator); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace/component/source-internal.h b/include/babeltrace/component/source-internal.h index 0a926fc7..fcf646de 100644 --- a/include/babeltrace/component/source-internal.h +++ b/include/babeltrace/component/source-internal.h @@ -33,13 +33,8 @@ struct bt_value; -struct bt_component_source_class { - struct bt_component_class parent; -}; - struct bt_component_source { struct bt_component parent; - bt_component_source_init_iterator_cb init_iterator; }; /** diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 387cf89e..5224d466 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include #ifdef __cplusplus extern "C" { @@ -93,7 +96,7 @@ struct __bt_plugin_descriptor_attribute { /* Name of the attribute's type for debug purposes */ const char *type_name; - /* Attribute's value */ + /* Attribute's value (depends on attribute's type) */ union { /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT */ bt_plugin_init_func init; @@ -120,19 +123,38 @@ struct __bt_plugin_component_class_descriptor { */ const struct __bt_plugin_descriptor *plugin_descriptor; - /* Component type */ - enum bt_component_type type; + /* Component class type */ + enum bt_component_class_type type; /* Component class name */ const char *name; - /* Component initialization function */ - bt_component_init_cb init_cb; + /* Mandatory methods (depends on component class type) */ + union { + /* BT_COMPONENT_CLASS_TYPE_SOURCE */ + struct { + bt_component_class_source_init_iterator_method init_iterator; + } source; + + /* BT_COMPONENT_CLASS_TYPE_FILTER */ + struct { + bt_component_class_filter_init_iterator_method init_iterator; + } filter; + + /* BT_COMPONENT_CLASS_TYPE_SINK */ + struct { + bt_component_class_sink_consume_method consume; + } sink; + } methods; } __attribute__((packed)); /* Type of a component class attribute (internal use) */ enum __bt_plugin_component_class_descriptor_attribute_type { - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION = 0, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION = 0, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD = 1, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD = 2, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD = 3, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD = 4, }; /* Component class attribute (internal use) */ @@ -149,10 +171,22 @@ struct __bt_plugin_component_class_descriptor_attribute { /* Name of the attribute's type for debug purposes */ const char *type_name; - /* Attribute's value */ + /* Attribute's value (depends on attribute's type) */ union { - /* BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION */ + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION */ const char *description; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD */ + bt_component_class_init_method init_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD */ + bt_component_class_destroy_method destroy_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD */ + bt_component_class_filter_add_iterator_method filter_add_iterator_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD */ + bt_component_class_sink_add_iterator_method sink_add_iterator_method; } value; } __attribute__((packed)); @@ -276,25 +310,75 @@ struct __bt_plugin_component_class_descriptor_attribute { __BT_PLUGIN_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _x) /* - * Defines a component class descriptor with a custom ID. + * Declaration of start and stop symbols of component class descriptors + * section. + */ +#define __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP \ + extern struct __bt_plugin_component_class_descriptor const *__start___bt_plugin_component_class_descriptors; \ + extern struct __bt_plugin_component_class_descriptor const *__stop___bt_plugin_component_class_descriptors + +/* + * Defines a source component class descriptor with a custom ID. * - * _id: ID (any valid C identifier except `auto`). - * _comp_class_id: Component class ID (C identifier). - * _type: Component class type (enum bt_component_type). - * _name: Component class name (C string). - * _init_func: Component class's initialization function - * (bt_component_init_cb). + * _id: ID (any valid C identifier except `auto`). + * _comp_class_id: Component class ID (C identifier). + * _name: Component class name (C string). + * _init_iterator_method: Component class's iterator initialization method + * (bt_component_class_source_init_iterator_method). */ -#define BT_PLUGIN_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _type, _name, _init_cb) \ - static struct __bt_plugin_component_class_descriptor __bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type = { \ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \ + static struct __bt_plugin_component_class_descriptor __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id = { \ .plugin_descriptor = &__bt_plugin_descriptor_##_id, \ - .type = _type, \ + .type = BT_COMPONENT_CLASS_TYPE_SOURCE, \ .name = _name, \ - .init_cb = _init_cb, \ + .methods.source = { \ + .init_iterator = _init_iterator_method, \ + }, \ }; \ - static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type; \ - extern struct __bt_plugin_component_class_descriptor const *__start___bt_plugin_component_class_descriptors; \ - extern struct __bt_plugin_component_class_descriptor const *__stop___bt_plugin_component_class_descriptors + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id; \ + __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP + +/* + * Defines a filter component class descriptor with a custom ID. + * + * _id: ID (any valid C identifier except `auto`). + * _comp_class_id: Component class ID (C identifier). + * _name: Component class name (C string). + * _init_iterator_method: Component class's iterator initialization method + * (bt_component_class_filter_init_iterator_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \ + static struct __bt_plugin_component_class_descriptor __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id = { \ + .plugin_descriptor = &__bt_plugin_descriptor_##_id, \ + .type = BT_COMPONENT_CLASS_TYPE_FILTER, \ + .name = _name, \ + .methods.filter = { \ + .init_iterator = _init_iterator_method, \ + }, \ + }; \ + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id; \ + __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP + +/* + * Defines a sink component class descriptor with a custom ID. + * + * _id: ID (any valid C identifier except `auto`). + * _comp_class_id: Component class ID (C identifier). + * _name: Component class name (C string). + * _consume_method: Component class's iterator consume method + * (bt_component_class_sink_consume_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _consume_method) \ + static struct __bt_plugin_component_class_descriptor __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id = { \ + .plugin_descriptor = &__bt_plugin_descriptor_##_id, \ + .type = BT_COMPONENT_CLASS_TYPE_SINK, \ + .name = _name, \ + .methods.sink = { \ + .consume = _consume_method, \ + }, \ + }; \ + static struct __bt_plugin_component_class_descriptor const * const __bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRS = &__bt_plugin_sink_component_class_descriptor_##_id##_##_comp_class_id; \ + __BT_PLUGIN_DECL_COMPONENT_CLASS_DESCRIPTORS_SECTION_START_STOP /* * Defines a component class descriptor attribute (generic, internal @@ -302,34 +386,145 @@ struct __bt_plugin_component_class_descriptor_attribute { * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class ID (C identifier). - * _type: Component class type (enum bt_component_type). + * _type: Component class type (`source`, `filter`, or `sink`). * _attr_name: Name of the attribute (C identifier). * _attr_type: Type of the attribute * (enum __bt_plugin_descriptor_attribute_type). * _x: Value. */ #define __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(_attr_name, _attr_type, _id, _comp_class_id, _type, _x) \ - static struct __bt_plugin_component_class_descriptor_attribute __bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name = { \ - .comp_class_descriptor = &__bt_plugin_component_class_descriptor_##_id##_##_comp_class_id##_##_type, \ + static struct __bt_plugin_component_class_descriptor_attribute __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name = { \ + .comp_class_descriptor = &__bt_plugin_##_type##_component_class_descriptor_##_id##_##_comp_class_id, \ .type = _attr_type, \ .type_name = #_attr_name, \ - .value.description = _x, \ + .value._attr_name = _x, \ }; \ - static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_type##_##_attr_name; \ + static struct __bt_plugin_component_class_descriptor_attribute const * const __bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name##_ptr __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTES_ATTRS = &__bt_plugin_##_type##_component_class_descriptor_attribute_##_id##_##_comp_class_id##_##_attr_name; \ extern struct __bt_plugin_component_class_descriptor_attribute const *__start___bt_plugin_component_class_descriptor_attributes; \ extern struct __bt_plugin_component_class_descriptor_attribute const *__stop___bt_plugin_component_class_descriptor_attributes /* - * Defines a description attribute attached to a specific component - * class descriptor. + * Defines a description attribute attached to a specific source + * component class descriptor. * * _id: Plugin descriptor ID (C identifier). * _comp_class_id: Component class descriptor ID (C identifier). - * _type: Component class type (enum bt_component_type). * _x: Description (C string). */ -#define BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _type, _x) \ - __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, _type, _x) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, source, _x) + +/* + * Defines a description attribute attached to a specific filter + * component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Description (C string). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, filter, _x) + +/* + * Defines a description attribute attached to a specific sink + * component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Description (C string). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(description, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION, _id, _comp_class_id, sink, _x) + +/* + * Defines an initialization method attribute attached to a specific + * source component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines an initialization method attribute attached to a specific + * filter component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an initialization method attribute attached to a specific + * sink component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD, _id, _comp_class_id, sink, _x) + +/* + * Defines a destroy method attribute attached to a specific source + * component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Destroy method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines a destroy method attribute attached to a specific filter + * component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Destroy method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines a destroy method attribute attached to a specific sink + * component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Destroy method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD, _id, _comp_class_id, sink, _x) + +/* + * Defines an add iterator method attribute attached to a specific + * filter component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Add iterator method + * (bt_component_class_filter_add_iterator_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(filter_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an add iterator method attribute attached to a specific + * sink component class descriptor. + * + * _id: Plugin descriptor ID (C identifier). + * _comp_class_id: Component class descriptor ID (C identifier). + * _x: Add iterator method + * (bt_component_class_sink_add_iterator_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(sink_add_iterator_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD, _id, _comp_class_id, sink, _x) /* * Defines a plugin descriptor with an automatic ID. @@ -379,28 +574,157 @@ struct __bt_plugin_component_class_descriptor_attribute { #define BT_PLUGIN_DESCRIPTION(_x) BT_PLUGIN_DESCRIPTION_WITH_ID(auto, _x) /* - * Defines a component class attached to the automatic plugin + * Defines a source component class attached to the automatic plugin + * descriptor. Its ID is the same as its name, hence its name must be a + * C identifier in this version. + * + * _name: Component class name (C identifier). + * _init_iterator_method: Component class's iterator initialization method + * (bt_component_class_source_init_iterator_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _init_iterator_method) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method) + +/* + * Defines a filter component class attached to the automatic plugin * descriptor. Its ID is the same as its name, hence its name must be a * C identifier in this version. * - * _type: Component class type (enum bt_component_type). - * _name: Component class name (C identifier). - * _init_cb: Component class's initialization function - * (bt_component_init_cb). + * _name: Component class name (C identifier). + * _init_iterator_method: Component class's iterator initialization method + * (bt_component_class_filter_init_iterator_method). */ -#define BT_PLUGIN_COMPONENT_CLASS(_type, _name, _init_cb) \ - BT_PLUGIN_COMPONENT_CLASS_WITH_ID(auto, _name, _type, #_name, _init_cb) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _init_iterator_method) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method) /* - * Defines a description attribute attached to a component class + * Defines a sink component class attached to the automatic plugin + * descriptor. Its ID is the same as its name, hence its name must be a + * C identifier in this version. + * + * _name: Component class name (C identifier). + * _consume_method: Component class's consume method + * (bt_component_class_sink_consume_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS(_name, _consume_method) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _consume_method) + +/* + * Defines a description attribute attached to a source component class * descriptor which is attached to the automatic plugin descriptor. * - * _type: Component class type (enum bt_component_type). - * _name: Component class name (C identifier). - * _x: Description (C string). + * _name: Component class name (C identifier). + * _x: Description (C string). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x) + +/* + * Defines a description attribute attached to a filter component class + * descriptor which is attached to the automatic plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Description (C string). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x) + +/* + * Defines a description attribute attached to a sink component class + * descriptor which is attached to the automatic plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Description (C string). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _x) + +/* + * Defines an initialization method attribute attached to a source + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an initialization method attribute attached to a filter + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an initialization method attribute attached to a sink + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_init_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines a destroy method attribute attached to a source component + * class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines a destroy method attribute attached to a filter component + * class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines a destroy method attribute attached to a sink component class + * descriptor which is attached to the automatic plugin descriptor. + * + * _name: Component class name (C identifier). + * _x: Initialization method (bt_component_class_destroy_method). + */ +#define BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an add iterator method attribute attached to a filter + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Add iterator method (bt_component_class_filter_add_iterator_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an add iterator method attribute attached to a sink + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Add iterator method (bt_component_class_sink_add_iterator_method). */ -#define BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(_type, _name, _x) \ - BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, _name, _type, _x) +#define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \ + BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x) #ifdef __cplusplus } diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h index 66436dfb..1e5bf37b 100644 --- a/include/babeltrace/plugin/plugin.h +++ b/include/babeltrace/plugin/plugin.h @@ -106,7 +106,7 @@ extern struct bt_component_class *bt_plugin_get_component_class( extern struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( struct bt_plugin *plugin, const char *name, - enum bt_component_type type); + enum bt_component_class_type type); #ifdef __cplusplus } diff --git a/lib/component/component-class.c b/lib/component/component-class.c index 660964c2..22551f88 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -42,9 +42,9 @@ void bt_component_class_destroy(struct bt_object *obj) /* Call destroy listeners in reverse registration order */ for (i = class->destroy_listeners->len - 1; i >= 0; i--) { - struct bt_component_class_destroyer_listener *listener = + struct bt_component_class_destroy_listener *listener = &g_array_index(class->destroy_listeners, - struct bt_component_class_destroyer_listener, + struct bt_component_class_destroy_listener, i); listener->func(class, listener->data); @@ -63,46 +63,188 @@ void bt_component_class_destroy(struct bt_object *obj) g_free(class); } -struct bt_component_class *bt_component_class_create( - enum bt_component_type type, const char *name, - const char *description, bt_component_init_cb init) +static +int bt_component_class_init(struct bt_component_class *class, + enum bt_component_class_type type, const char *name) { - struct bt_component_class *class = NULL; + int ret = 0; + + bt_object_init(class, bt_component_class_destroy); + class->type = type; + class->name = g_string_new(name); + if (!class->name) { + goto error; + } + + class->description = g_string_new(NULL); + if (!class->description) { + goto error; + } + + class->destroy_listeners = g_array_new(FALSE, TRUE, + sizeof(struct bt_component_class_destroy_listener)); + if (!class->destroy_listeners) { + goto error; + } + + goto end; - if (!name) { +error: + BT_PUT(class); + ret = -1; + +end: + return ret; +} + +struct bt_component_class *bt_component_class_source_create(const char *name, + bt_component_class_source_init_iterator_method init_iterator_method) +{ + struct bt_component_class_source *source_class = NULL; + int ret; + + if (!name || !init_iterator_method) { goto end; } - class = g_new0(struct bt_component_class, 1); - if (!class) { + source_class = g_new0(struct bt_component_class_source, 1); + if (!source_class) { goto end; } - bt_object_init(class, bt_component_class_destroy); - class->type = type; - class->init = init; - class->name = g_string_new(name); - if (!class->name) { - BT_PUT(class); + ret = bt_component_class_init(&source_class->parent, + BT_COMPONENT_CLASS_TYPE_SOURCE, name); + if (ret) { + /* + * If bt_component_class_init() fails, the component + * class is put, therefore its memory is already + * freed. + */ + source_class = NULL; + goto end; + } + + source_class->methods.init_iterator = init_iterator_method; + +end: + return &source_class->parent; +} + +struct bt_component_class *bt_component_class_filter_create(const char *name, + bt_component_class_filter_init_iterator_method init_iterator_method) +{ + struct bt_component_class_filter *filter_class = NULL; + int ret; + + if (!name || !init_iterator_method) { goto end; } - if (description) { - class->description = g_string_new(description); - if (!class->description) { - BT_PUT(class); - goto end; - } + filter_class = g_new0(struct bt_component_class_filter, 1); + if (!filter_class) { + goto end; } - class->destroy_listeners = g_array_new(FALSE, TRUE, - sizeof(struct bt_component_class_destroyer_listener)); - if (!class->destroy_listeners) { - BT_PUT(class); + ret = bt_component_class_init(&filter_class->parent, + BT_COMPONENT_CLASS_TYPE_FILTER, name); + if (ret) { + /* + * If bt_component_class_init() fails, the component + * class is put, therefore its memory is already + * freed. + */ + filter_class = NULL; goto end; } + + filter_class->methods.init_iterator = init_iterator_method; + end: - return class; + return &filter_class->parent; +} + +struct bt_component_class *bt_component_class_sink_create(const char *name, + bt_component_class_sink_consume_method consume_method) +{ + struct bt_component_class_sink *sink_class = NULL; + int ret; + + if (!name || !consume_method) { + goto end; + } + + sink_class = g_new0(struct bt_component_class_sink, 1); + if (!sink_class) { + goto end; + } + + ret = bt_component_class_init(&sink_class->parent, + BT_COMPONENT_CLASS_TYPE_SINK, name); + if (ret) { + /* + * If bt_component_class_init() fails, the component + * class is put, therefore its memory is already + * freed. + */ + sink_class = NULL; + goto end; + } + + sink_class->methods.consume = consume_method; + +end: + return &sink_class->parent; +} + +int bt_component_class_set_init_method( + struct bt_component_class *component_class, + bt_component_class_init_method init_method) +{ + int ret = 0; + + if (!component_class || !init_method) { + ret = -1; + goto end; + } + + component_class->methods.init = init_method; + +end: + return ret; +} + +int bt_component_class_set_destroy_method( + struct bt_component_class *component_class, + bt_component_class_destroy_method destroy_method) +{ + int ret = 0; + + if (!component_class || !destroy_method) { + ret = -1; + goto end; + } + + component_class->methods.destroy = destroy_method; + +end: + return ret; +} + +extern int bt_component_class_set_description( + struct bt_component_class *component_class, + const char *description) +{ + int ret = 0; + + if (!component_class || !description) { + ret = -1; + goto end; + } + + g_string_assign(component_class->description, description); + +end: + return ret; } const char *bt_component_class_get_name( @@ -111,11 +253,11 @@ const char *bt_component_class_get_name( return component_class ? component_class->name->str : NULL; } -enum bt_component_type bt_component_class_get_type( +enum bt_component_class_type bt_component_class_get_type( struct bt_component_class *component_class) { return component_class ? component_class->type : - BT_COMPONENT_TYPE_UNKNOWN; + BT_COMPONENT_CLASS_TYPE_UNKNOWN; } const char *bt_component_class_get_description( @@ -130,7 +272,7 @@ int bt_component_class_add_destroy_listener(struct bt_component_class *class, bt_component_class_destroy_listener_func func, void *data) { int ret = 0; - struct bt_component_class_destroyer_listener listener; + struct bt_component_class_destroy_listener listener; if (!class || !func) { ret = -1; @@ -144,3 +286,46 @@ int bt_component_class_add_destroy_listener(struct bt_component_class *class, end: return ret; } + +extern int bt_component_class_sink_set_add_iterator_method( + struct bt_component_class *component_class, + bt_component_class_sink_add_iterator_method add_iterator_method) +{ + struct bt_component_class_sink *sink_class; + int ret = 0; + + if (!component_class || !add_iterator_method || + component_class->type != BT_COMPONENT_CLASS_TYPE_SINK) { + ret = -1; + goto end; + } + + sink_class = container_of(component_class, + struct bt_component_class_sink, parent); + sink_class->methods.add_iterator = add_iterator_method; + +end: + return ret; +} + +extern int bt_component_class_filter_set_add_iterator_method( + struct bt_component_class *component_class, + bt_component_class_filter_add_iterator_method add_iterator_method) +{ + struct bt_component_class_filter *filter_class; + int ret = 0; + + if (!component_class || !add_iterator_method || + component_class->type != + BT_COMPONENT_CLASS_TYPE_FILTER) { + ret = -1; + goto end; + } + + filter_class = container_of(component_class, + struct bt_component_class_filter, parent); + filter_class->methods.add_iterator = add_iterator_method; + +end: + return ret; +} diff --git a/lib/component/component.c b/lib/component/component.c index 4ad897c7..d82ee0d8 100644 --- a/lib/component/component.c +++ b/lib/component/component.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -39,17 +40,17 @@ 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, - [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_create, + [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create, + [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create, + [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_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, - [BT_COMPONENT_TYPE_FILTER] = bt_component_filter_validate, + [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_validate, + [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_validate, + [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_validate, }; static @@ -69,8 +70,8 @@ void bt_component_destroy(struct bt_object *obj) * User data is destroyed first, followed by the concrete component * instance. */ - if (component->user_destroy) { - component->user_destroy(component); + if (component->class->methods.destroy) { + component->class->methods.destroy(component); } if (component->destroy) { @@ -84,7 +85,7 @@ void bt_component_destroy(struct bt_object *obj) BT_HIDDEN enum bt_component_status bt_component_init(struct bt_component *component, - bt_component_destroy_cb destroy) + bt_component_class_destroy_method destroy) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; @@ -98,10 +99,10 @@ end: return ret; } -BT_HIDDEN -enum bt_component_type bt_component_get_type(struct bt_component *component) +enum bt_component_class_type bt_component_get_class_type( + struct bt_component *component) { - return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN; + return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN; } BT_HIDDEN @@ -109,16 +110,17 @@ struct bt_notification_iterator *bt_component_create_iterator( struct bt_component *component) { enum bt_notification_iterator_status ret_iterator; - enum bt_component_type component_type; + enum bt_component_class_type type; struct bt_notification_iterator *iterator = NULL; + struct bt_component_class *class = component->class; if (!component) { goto error; } - component_type = bt_component_get_type(component); - if (component_type != BT_COMPONENT_TYPE_SOURCE && - component_type != BT_COMPONENT_TYPE_FILTER) { + type = bt_component_get_class_type(component); + if (type != BT_COMPONENT_CLASS_TYPE_SOURCE && + type != BT_COMPONENT_CLASS_TYPE_FILTER) { /* Unsupported operation. */ goto error; } @@ -128,15 +130,16 @@ struct bt_notification_iterator *bt_component_create_iterator( goto error; } - switch (component_type) { - case BT_COMPONENT_TYPE_SOURCE: + switch (type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: { - struct bt_component_source *source; + struct bt_component_class_source *source_class; enum bt_component_status ret_component; - source = container_of(component, struct bt_component_source, parent); - assert(source->init_iterator); - ret_component = source->init_iterator(component, iterator); + source_class = container_of(class, struct bt_component_class_source, parent); + assert(source_class->methods.init_iterator); + ret_component = + source_class->methods.init_iterator(component, iterator); if (ret_component != BT_COMPONENT_STATUS_OK) { goto error; } @@ -144,14 +147,15 @@ struct bt_notification_iterator *bt_component_create_iterator( break; } - case BT_COMPONENT_TYPE_FILTER: + case BT_COMPONENT_CLASS_TYPE_FILTER: { - struct bt_component_filter *filter; + struct bt_component_class_filter *filter_class; enum bt_component_status ret_component; - filter = container_of(component, struct bt_component_filter, parent); - assert(filter->init_iterator); - ret_component = filter->init_iterator(component, iterator); + filter_class = container_of(class, struct bt_component_class_filter, parent); + assert(filter_class->methods.init_iterator); + ret_component = + filter_class->methods.init_iterator(component, iterator); if (ret_component != BT_COMPONENT_STATUS_OK) { goto error; } @@ -179,15 +183,16 @@ struct bt_component *bt_component_create( { int ret; struct bt_component *component = NULL; - enum bt_component_type type; + enum bt_component_class_type type; if (!component_class) { goto end; } + type = bt_component_class_get_type(component_class); - if (type <= BT_COMPONENT_TYPE_UNKNOWN || - type > BT_COMPONENT_TYPE_FILTER) { + if (type <= BT_COMPONENT_CLASS_TYPE_UNKNOWN || + type > BT_COMPONENT_CLASS_TYPE_FILTER) { goto end; } @@ -204,12 +209,17 @@ struct bt_component *bt_component_create( } component->initializing = true; - ret = component_class->init(component, params); - component->initializing = false; - if (ret != BT_COMPONENT_STATUS_OK) { - BT_PUT(component); - goto end; + + if (component_class->methods.init) { + ret = component_class->methods.init(component, params); + component->initializing = false; + if (ret != BT_COMPONENT_STATUS_OK) { + BT_PUT(component); + goto end; + } } + + component->initializing = false; ret = component_validation_funcs[type](component); if (ret != BT_COMPONENT_STATUS_OK) { BT_PUT(component); @@ -273,18 +283,3 @@ bt_component_set_private_data(struct bt_component *component, end: return ret; } - -enum bt_component_status bt_component_set_destroy_cb( - struct bt_component *component, bt_component_destroy_cb destroy) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component || !component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - component->user_destroy = destroy; -end: - return ret; -} diff --git a/lib/component/filter.c b/lib/component/filter.c index 2c9fb471..53c0091e 100644 --- a/lib/component/filter.c +++ b/lib/component/filter.c @@ -31,56 +31,10 @@ #include #include #include +#include #include #include -enum bt_component_status bt_component_filter_set_iterator_init_cb( - struct bt_component *component, - bt_component_filter_init_iterator_cb init_iterator) -{ - struct bt_component_filter *filter; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (component->class->type != BT_COMPONENT_TYPE_FILTER || - !component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - filter = container_of(component, struct bt_component_filter, parent); - filter->init_iterator = init_iterator; -end: - return ret; -} - -enum bt_component_status bt_component_filter_set_add_iterator_cb( - struct bt_component *component, - bt_component_filter_add_iterator_cb add_iterator) -{ - struct bt_component_filter *filter; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { - ret = BT_COMPONENT_STATUS_UNSUPPORTED; - goto end; - } - - if (!component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - filter = container_of(component, struct bt_component_filter, parent); - filter->add_iterator = add_iterator; -end: - return ret; -} - enum bt_component_status bt_component_filter_set_minimum_input_count( struct bt_component *component, unsigned int minimum) @@ -93,7 +47,7 @@ enum bt_component_status bt_component_filter_set_minimum_input_count( goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -121,7 +75,7 @@ enum bt_component_status bt_component_filter_set_maximum_input_count( goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -149,7 +103,7 @@ bt_component_filter_get_input_count(struct bt_component *component, goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -172,7 +126,7 @@ bt_component_filter_get_input_iterator(struct bt_component *component, goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -194,13 +148,14 @@ enum bt_component_status bt_component_filter_add_iterator( { struct bt_component_filter *filter; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct bt_component_class_filter *filter_class; if (!component || !iterator) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_FILTER) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -211,8 +166,10 @@ enum bt_component_status bt_component_filter_add_iterator( goto end; } - if (filter->add_iterator) { - ret = filter->add_iterator(component, iterator); + filter_class = container_of(component->class, struct bt_component_class_filter, parent); + + if (filter_class->methods.add_iterator) { + ret = filter_class->methods.add_iterator(component, iterator); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } @@ -283,18 +240,12 @@ enum bt_component_status bt_component_filter_validate( goto end; } - if (component->class->type != BT_COMPONENT_TYPE_FILTER) { + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } filter = container_of(component, struct bt_component_filter, parent); - if (!filter->init_iterator) { - printf_error("Invalid filter component; no iterator initialization callback defined."); - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - ret = component_input_validate(&filter->input); if (ret) { goto end; diff --git a/lib/component/iterator.c b/lib/component/iterator.c index 188095cf..98c4f355 100644 --- a/lib/component/iterator.c +++ b/lib/component/iterator.c @@ -53,17 +53,17 @@ BT_HIDDEN struct bt_notification_iterator *bt_notification_iterator_create( struct bt_component *component) { - enum bt_component_type type; + enum bt_component_class_type type; struct bt_notification_iterator *iterator = NULL; if (!component) { goto end; } - type = bt_component_get_type(component); + type = bt_component_get_class_type(component); switch (type) { - case BT_COMPONENT_TYPE_SOURCE: - case BT_COMPONENT_TYPE_FILTER: + case BT_COMPONENT_CLASS_TYPE_SOURCE: + case BT_COMPONENT_CLASS_TYPE_FILTER: break; default: goto end; diff --git a/lib/component/sink.c b/lib/component/sink.c index 509ea89c..22ca5c99 100644 --- a/lib/component/sink.c +++ b/lib/component/sink.c @@ -49,18 +49,12 @@ enum bt_component_status bt_component_sink_validate( goto end; } - if (component->class->type != BT_COMPONENT_TYPE_SINK) { + if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } sink = container_of(component, struct bt_component_sink, parent); - if (!sink->consume) { - printf_error("Invalid sink component; no notification consumption callback defined."); - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - ret = component_input_validate(&sink->input); if (ret) { goto end; @@ -131,13 +125,14 @@ enum bt_component_status bt_component_sink_consume( { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; struct bt_component_sink *sink = NULL; + struct bt_component_class_sink *sink_class = NULL; if (!component) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -151,8 +146,9 @@ enum bt_component_status bt_component_sink_consume( sink->input.validated = true; } - assert(sink->consume); - ret = sink->consume(component); + sink_class = container_of(component->class, struct bt_component_class_sink, parent); + assert(sink_class->methods.consume); + ret = sink_class->methods.consume(component); end: return ret; } @@ -169,7 +165,7 @@ enum bt_component_status bt_component_sink_register_notification_type( goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -190,61 +186,6 @@ end: return ret; } */ -enum bt_component_status bt_component_sink_set_consume_cb( - struct bt_component *component, - bt_component_sink_consume_cb consume) -{ - struct bt_component_sink *sink; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { - ret = BT_COMPONENT_STATUS_UNSUPPORTED; - goto end; - } - - if (!component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - sink = container_of(component, struct bt_component_sink, parent); - sink->consume = consume; -end: - return ret; -} - -enum bt_component_status bt_component_sink_set_add_iterator_cb( - struct bt_component *component, - bt_component_sink_add_iterator_cb add_iterator) -{ - struct bt_component_sink *sink; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { - ret = BT_COMPONENT_STATUS_UNSUPPORTED; - goto end; - } - - if (!component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - sink = container_of(component, struct bt_component_sink, parent); - sink->add_iterator = add_iterator; -end: - return ret; -} enum bt_component_status bt_component_sink_set_minimum_input_count( struct bt_component *component, @@ -258,7 +199,7 @@ enum bt_component_status bt_component_sink_set_minimum_input_count( goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -286,7 +227,7 @@ enum bt_component_status bt_component_sink_set_maximum_input_count( goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -314,7 +255,7 @@ bt_component_sink_get_input_count(struct bt_component *component, goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -337,7 +278,7 @@ bt_component_sink_get_input_iterator(struct bt_component *component, goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -359,13 +300,14 @@ bt_component_sink_add_iterator(struct bt_component *component, { struct bt_component_sink *sink; enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct bt_component_class_sink *sink_class; if (!component || !iterator) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + if (bt_component_get_class_type(component) != BT_COMPONENT_CLASS_TYPE_SINK) { ret = BT_COMPONENT_STATUS_UNSUPPORTED; goto end; } @@ -376,8 +318,10 @@ bt_component_sink_add_iterator(struct bt_component *component, goto end; } - if (sink->add_iterator) { - ret = sink->add_iterator(component, iterator); + sink_class = container_of(component->class, struct bt_component_class_sink, parent); + + if (sink_class->methods.add_iterator) { + ret = sink_class->methods.add_iterator(component, iterator); if (ret != BT_COMPONENT_STATUS_OK) { goto end; } diff --git a/lib/component/source.c b/lib/component/source.c index a0a21d1b..7b51590c 100644 --- a/lib/component/source.c +++ b/lib/component/source.c @@ -38,7 +38,6 @@ enum bt_component_status bt_component_source_validate( struct bt_component *component) { enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_component_source *source; if (!component) { ret = BT_COMPONENT_STATUS_INVALID; @@ -50,16 +49,11 @@ enum bt_component_status bt_component_source_validate( goto end; } - if (component->class->type != BT_COMPONENT_TYPE_SOURCE) { + if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { ret = BT_COMPONENT_STATUS_INVALID; goto end; } - source = container_of(component, struct bt_component_source, parent); - if (!source->init_iterator) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } end: return ret; } @@ -86,25 +80,6 @@ end: return source ? &source->parent : NULL; } -enum bt_component_status -bt_component_source_set_iterator_init_cb(struct bt_component *component, - bt_component_source_init_iterator_cb init_iterator) -{ - struct bt_component_source *source; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (component->class->type != BT_COMPONENT_TYPE_SOURCE || - !component->initializing) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - source = container_of(component, struct bt_component_source, parent); - source->init_iterator = init_iterator; -end: - return ret; -} - struct bt_notification_iterator *bt_component_source_create_iterator( struct bt_component *component) { diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 5a72b42e..e79db448 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -237,6 +237,33 @@ end: return plugin; } +/* + * This function does the following: + * + * 1. Iterate on the plugin descriptor attributes section and set the + * plugin's attributes depending on the attribute types. This + * includes the name of the plugin, its description, and its + * initialization function, for example. + * + * 2. Iterate on the component class descriptors section and create one + * "full descriptor" (temporary structure) for each one that is found + * and attached to our plugin descriptor. + * + * 3. Iterate on the component class descriptor attributes section and + * set the corresponding full descriptor's attributes depending on + * the attribute types. This includes the description of the + * component class, as well as its initialization and destroy + * methods. + * + * 4. Call the user's plugin initialization function, if any is + * defined. + * + * 5. For each full component class descriptor, create a component class + * object, set its optional attributes, and add it to the plugin + * object. + * + * 6. Freeze the plugin object. + */ static enum bt_plugin_status bt_plugin_init( struct bt_plugin *plugin, @@ -255,6 +282,10 @@ enum bt_plugin_status bt_plugin_init( struct comp_class_full_descriptor { const struct __bt_plugin_component_class_descriptor *descriptor; const char *description; + bt_component_class_init_method init_method; + bt_component_class_destroy_method destroy_method; + bt_component_class_filter_add_iterator_method filter_add_iterator_method; + bt_component_class_sink_add_iterator_method sink_add_iterator_method; }; enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; @@ -263,6 +294,7 @@ enum bt_plugin_status bt_plugin_init( struct __bt_plugin_component_class_descriptor_attribute const * const *cur_cc_descr_attr_ptr; GArray *comp_class_full_descriptors; size_t i; + int ret; comp_class_full_descriptors = g_array_new(FALSE, TRUE, sizeof(struct comp_class_full_descriptor)); @@ -319,14 +351,13 @@ enum bt_plugin_status bt_plugin_init( for (cur_cc_descr_ptr = cc_descriptors_begin; cur_cc_descr_ptr != cc_descriptors_end; cur_cc_descr_ptr++) { const struct __bt_plugin_component_class_descriptor *cur_cc_descr = *cur_cc_descr_ptr; - struct comp_class_full_descriptor full_descriptor; + struct comp_class_full_descriptor full_descriptor = {0}; if (cur_cc_descr->plugin_descriptor != descriptor) { continue; } full_descriptor.descriptor = cur_cc_descr; - full_descriptor.description = NULL; g_array_append_val(comp_class_full_descriptors, full_descriptor); } @@ -358,6 +389,22 @@ enum bt_plugin_status bt_plugin_init( cc_full_descr->description = cur_cc_descr_attr->value.description; break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD: + cc_full_descr->init_method = + cur_cc_descr_attr->value.init_method; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESTROY_METHOD: + cc_full_descr->destroy_method = + cur_cc_descr_attr->value.destroy_method; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FILTER_ADD_ITERATOR_METHOD: + cc_full_descr->filter_add_iterator_method = + cur_cc_descr_attr->value.filter_add_iterator_method; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD: + cc_full_descr->sink_add_iterator_method = + cur_cc_descr_attr->value.sink_add_iterator_method; + break; default: printf_verbose("WARNING: Unknown attribute \"%s\" (type %d) for component class %s (type %d) in plugin %s\n", cur_cc_descr_attr->type_name, @@ -383,22 +430,97 @@ enum bt_plugin_status bt_plugin_init( plugin->shared_lib_handle->init_called = true; + /* Add described component classes to plugin */ for (i = 0; i < comp_class_full_descriptors->len; i++) { struct comp_class_full_descriptor *cc_full_descr = &g_array_index(comp_class_full_descriptors, struct comp_class_full_descriptor, i); struct bt_component_class *comp_class; - comp_class = bt_component_class_create( - cc_full_descr->descriptor->type, - cc_full_descr->descriptor->name, - cc_full_descr->description, - cc_full_descr->descriptor->init_cb); + switch (cc_full_descr->descriptor->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + comp_class = bt_component_class_source_create( + cc_full_descr->descriptor->name, + cc_full_descr->descriptor->methods.source.init_iterator); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + comp_class = bt_component_class_filter_create( + cc_full_descr->descriptor->name, + cc_full_descr->descriptor->methods.filter.init_iterator); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + comp_class = bt_component_class_sink_create( + cc_full_descr->descriptor->name, + cc_full_descr->descriptor->methods.sink.consume); + break; + default: + printf_verbose("WARNING: Unknown component class type %d for component class %s in plugin %s\n", + cc_full_descr->descriptor->type, + cc_full_descr->descriptor->name, + descriptor->name); + continue; + } + if (!comp_class) { status = BT_PLUGIN_STATUS_ERROR; goto end; } + if (cc_full_descr->description) { + ret = bt_component_class_set_description(comp_class, + cc_full_descr->description); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->init_method) { + ret = bt_component_class_set_init_method(comp_class, + cc_full_descr->init_method); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->destroy_method) { + ret = bt_component_class_set_destroy_method(comp_class, + cc_full_descr->destroy_method); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->descriptor->type == + BT_COMPONENT_CLASS_TYPE_FILTER && + cc_full_descr->filter_add_iterator_method) { + ret = bt_component_class_filter_set_add_iterator_method(comp_class, + cc_full_descr->filter_add_iterator_method); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->descriptor->type == + BT_COMPONENT_CLASS_TYPE_SINK && + cc_full_descr->sink_add_iterator_method) { + ret = bt_component_class_sink_set_add_iterator_method(comp_class, + cc_full_descr->sink_add_iterator_method); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + /* Add component class to the plugin object */ status = bt_plugin_add_component_class(plugin, comp_class); BT_PUT(comp_class); @@ -454,7 +576,7 @@ struct bt_plugin **bt_plugin_create_all_from_sections( printf_verbose("Section: Plugin component class descriptors: [%p - %p], (%zu elements)\n", cc_descriptors_begin, cc_descriptors_end, cc_descriptors_count); printf_verbose("Section: Plugin component class descriptor attributes: [%p - %p], (%zu elements)\n", - cc_descr_attrs_begin, cc_descr_attrs_end, attrs_count); + cc_descr_attrs_begin, cc_descr_attrs_end, cc_descr_attrs_count); plugins = calloc(descriptor_count + 1, sizeof(*plugins)); if (!plugins) { goto error; @@ -878,7 +1000,7 @@ end: struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( struct bt_plugin *plugin, const char *name, - enum bt_component_type type) + enum bt_component_class_type type) { struct bt_component_class *comp_class = NULL; size_t i; @@ -892,7 +1014,7 @@ struct bt_component_class *bt_plugin_get_component_class_by_name_and_type( g_ptr_array_index(plugin->comp_classes, i); const char *comp_class_cand_name = bt_component_class_get_name(comp_class_candidate); - enum bt_component_type comp_class_cand_type = + enum bt_component_class_type comp_class_cand_type = bt_component_class_get_type(comp_class_candidate); assert(comp_class_cand_name); diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index f08f06a5..d3fcf0f0 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -583,7 +583,6 @@ end: return ret; } -static enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, struct bt_notification_iterator *it) { @@ -668,7 +667,6 @@ void ctf_fs_destroy_data(struct ctf_fs_component *ctf_fs) g_free(ctf_fs); } -static void ctf_fs_destroy(struct bt_component *component) { void *data = bt_component_get_private_data(component); @@ -738,21 +736,10 @@ enum bt_component_status ctf_fs_init(struct bt_component *source, goto end; } - ret = bt_component_set_destroy_cb(source, ctf_fs_destroy); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = bt_component_set_private_data(source, ctf_fs); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - - ret = bt_component_source_set_iterator_init_cb(source, - ctf_fs_iterator_init); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } end: return ret; error: diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 2c0972e6..2cef5fb5 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -109,4 +109,11 @@ BT_HIDDEN enum bt_component_status ctf_fs_init(struct bt_component *source, struct bt_value *params); +BT_HIDDEN +void ctf_fs_destroy(struct bt_component *component); + +BT_HIDDEN +enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, + struct bt_notification_iterator *it); + #endif /* BABELTRACE_PLUGIN_CTF_FS_H */ diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index 4891b0d2..d26ec853 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -32,6 +32,10 @@ #define LTTNG_LIVE_COMPONENT_DESCRIPTION "Component implementing an LTTng-live client." +BT_HIDDEN +enum bt_component_status lttng_live_iterator_init(struct bt_component *source, + struct bt_notification_iterator *it); + BT_HIDDEN enum bt_component_status lttng_live_init(struct bt_component *source, struct bt_value *params); diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index 5cef2aa9..9bbf4b17 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -29,6 +29,12 @@ #include "lttng-live-internal.h" #include +BT_HIDDEN +enum bt_component_status lttng_live_iterator_init(struct bt_component *source, + struct bt_notification_iterator *it) +{ +} + BT_HIDDEN enum bt_component_status lttng_live_init(struct bt_component *component, struct bt_value *params) diff --git a/plugins/ctf/plugin.c b/plugins/ctf/plugin.c index ff168d69..77f5057b 100644 --- a/plugins/ctf/plugin.c +++ b/plugins/ctf/plugin.c @@ -37,10 +37,14 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); /* Declare component classes implemented by this plug-in. */ -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SOURCE, fs, ctf_fs_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SOURCE, fs, - CTF_FS_COMPONENT_DESCRIPTION); -BT_PLUGIN_COMPONENT_CLASS_WITH_ID(auto, lttng_live, - BT_COMPONENT_TYPE_SOURCE, "lttng-live", lttng_live_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, lttng_live, - BT_COMPONENT_TYPE_SOURCE, LTTNG_LIVE_COMPONENT_DESCRIPTION); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(fs, ctf_fs_iterator_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD(fs, ctf_fs_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESTROY_METHOD(fs, ctf_fs_destroy); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(fs, CTF_FS_COMPONENT_DESCRIPTION); + +BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, lttng_live, "lttng-live", + lttng_live_iterator_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_INIT_METHOD_WITH_ID(auto, lttng_live, + lttng_live_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION_WITH_ID(auto, lttng_live, + LTTNG_LIVE_COMPONENT_DESCRIPTION); diff --git a/plugins/muxer/muxer.c b/plugins/muxer/muxer.c index 2700be6e..04171d75 100644 --- a/plugins/muxer/muxer.c +++ b/plugins/muxer/muxer.c @@ -72,12 +72,6 @@ enum bt_component_status muxer_component_init( goto end; } - ret = bt_component_set_destroy_cb(component, - destroy_muxer); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = bt_component_set_private_data(component, muxer); if (ret != BT_COMPONENT_STATUS_OK) { goto error; @@ -89,12 +83,20 @@ error: return ret; } +enum bt_component_status muxer_init_iterator( + struct bt_component *component, + struct bt_notification_iterator *iter) +{ + return BT_COMPONENT_STATUS_OK; +} + /* Initialize plug-in entry points. */ BT_PLUGIN(muxer); BT_PLUGIN_DESCRIPTION("Babeltrace Trace Muxer Plug-In."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, muxer, - muxer_component_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, muxer, +BT_PLUGIN_FILTER_COMPONENT_CLASS(muxer, muxer_init_iterator); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(muxer, "Time-correlate multiple traces."); +BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(muxer, muxer_component_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(muxer, destroy_muxer); diff --git a/plugins/text/text.c b/plugins/text/text.c index 370fb2d3..4ddca35c 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -628,22 +628,10 @@ enum bt_component_status text_component_init( goto error; } - ret = bt_component_set_destroy_cb(component, - destroy_text); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = bt_component_set_private_data(component, text); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - - ret = bt_component_sink_set_consume_cb(component, - run); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } end: return ret; error: @@ -656,7 +644,9 @@ BT_PLUGIN(text); BT_PLUGIN_DESCRIPTION("Babeltrace text output plug-in."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, text, - text_component_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, text, +BT_PLUGIN_SINK_COMPONENT_CLASS(text, run); +BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(text, text_component_init); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(text, destroy_text); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(text, "Formats CTF-IR to text. Formerly known as ctf-text."); + diff --git a/plugins/trimmer/trimmer.c b/plugins/trimmer/trimmer.c index 49be358b..6d94ddf2 100644 --- a/plugins/trimmer/trimmer.c +++ b/plugins/trimmer/trimmer.c @@ -359,23 +359,11 @@ enum bt_component_status trimmer_component_init( goto end; } - ret = bt_component_set_destroy_cb(component, - destroy_trimmer); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = bt_component_set_private_data(component, trimmer); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - ret = bt_component_filter_set_iterator_init_cb(component, - trimmer_iterator_init); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = init_from_params(trimmer, params); end: return ret; @@ -389,7 +377,8 @@ BT_PLUGIN(utils); BT_PLUGIN_DESCRIPTION("Babeltrace Trace Trimmer Plug-In."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, trimmer, - trimmer_component_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, trimmer, +BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(trimmer, "Ensure that trace notifications outside of a given range are filtered-out."); +BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(trimmer, trimmer_component_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(trimmer, destroy_trimmer); diff --git a/plugins/writer/writer.c b/plugins/writer/writer.c index 971e6bf8..089a3d59 100644 --- a/plugins/writer/writer.c +++ b/plugins/writer/writer.c @@ -246,23 +246,11 @@ enum bt_component_status writer_component_init( goto error; } - ret = bt_component_set_destroy_cb(component, - destroy_writer_component); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - ret = bt_component_set_private_data(component, writer_component); if (ret != BT_COMPONENT_STATUS_OK) { goto error; } - ret = bt_component_sink_set_consume_cb(component, - run); - if (ret != BT_COMPONENT_STATUS_OK) { - goto error; - } - end: return ret; error: @@ -276,7 +264,7 @@ BT_PLUGIN(writer); BT_PLUGIN_DESCRIPTION("Babeltrace CTF-Writer output plug-in."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, writer, - writer_component_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, writer, - "Formats CTF-IR to CTF."); +BT_PLUGIN_SINK_COMPONENT_CLASS(writer, run); +BT_PLUGIN_SINK_COMPONENT_CLASS_INIT_METHOD(writer, writer_component_init); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESTROY_METHOD(writer, destroy_writer_component); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(writer, "Formats CTF-IR to CTF."); diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index 943efbeb..037deced 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -18,33 +18,13 @@ #include #include -static int sink_value = 42; - -static enum bt_component_status sink_run(struct bt_component *component) -{ - return BT_COMPONENT_STATUS_OK; -} - -static enum bt_component_status comp_class_sink_init( - struct bt_component *component, struct bt_value *params) +static enum bt_component_status sink_consume(struct bt_component *component) { - enum bt_component_status ret; - - ret = bt_component_set_private_data(component, &sink_value); - if (ret != BT_COMPONENT_STATUS_OK) { - return BT_COMPONENT_STATUS_ERROR; - } - - ret = bt_component_sink_set_consume_cb(component, sink_run); - if (ret != BT_COMPONENT_STATUS_OK) { - return BT_COMPONENT_STATUS_ERROR; - } - return BT_COMPONENT_STATUS_OK; } -static enum bt_component_status comp_class_dummy_init( - struct bt_component *component, struct bt_value *params) +enum bt_component_status dummy_init_iterator_method( + struct bt_component *component, struct bt_notification_iterator *iter) { return BT_COMPONENT_STATUS_OK; } @@ -54,11 +34,11 @@ BT_PLUGIN_DESCRIPTION("Babeltrace plugin with source, sink, and filter component BT_PLUGIN_AUTHOR("Janine Sutto"); BT_PLUGIN_LICENSE("Beerware"); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SOURCE, source, comp_class_dummy_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SOURCE, source, "A source."); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_init_iterator_method); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(source, "A source."); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_SINK, sink, comp_class_sink_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_SINK, sink, "A sink."); +BT_PLUGIN_SINK_COMPONENT_CLASS(sink, sink_consume); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(sink, "A sink."); -BT_PLUGIN_COMPONENT_CLASS(BT_COMPONENT_TYPE_FILTER, filter, comp_class_dummy_init); -BT_PLUGIN_COMPONENT_CLASS_DESCRIPTION(BT_COMPONENT_TYPE_FILTER, filter, "A filter."); +BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_init_iterator_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(filter, "A filter."); diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 9b4ea84f..a2fc129a 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -144,22 +144,22 @@ static void test_sfs(const char *plugin_dir) "bt_plugin_get_component_class_count() returns the expected value"); source_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "source", BT_COMPONENT_TYPE_SOURCE); + plugin, "source", BT_COMPONENT_CLASS_TYPE_SOURCE); ok(source_comp_class, "bt_plugin_get_component_class_by_name_and_type() finds a source component class"); sink_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "sink", BT_COMPONENT_TYPE_SINK); + plugin, "sink", BT_COMPONENT_CLASS_TYPE_SINK); ok(sink_comp_class, "bt_plugin_get_component_class_by_name_and_type() finds a sink component class"); filter_comp_class = bt_plugin_get_component_class_by_name_and_type( - plugin, "filter", BT_COMPONENT_TYPE_FILTER); + plugin, "filter", BT_COMPONENT_CLASS_TYPE_FILTER); ok(filter_comp_class, "bt_plugin_get_component_class_by_name_and_type() finds a filter component class"); ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter", - BT_COMPONENT_TYPE_SOURCE), + BT_COMPONENT_CLASS_TYPE_SOURCE), "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type"); diag("> putting the plugin object here"); -- 2.34.1