From d3eb6e8fd59ebff26cb99a70d375e542d49575a3 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 27 Jan 2017 03:34:18 -0500 Subject: [PATCH] Set notification iterator methods to the component class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This follows the spirit of the previous refactorings by assigning notification iterator methods to the component class instead of setting them during their initialization method. Conceptually here, a (source and filter) component class defines one, and only one notification iterator class. Therefore the concept of an iterator "class" is hidden to the user here, since there's no one-to-many relationship. In any OO language, an iterator class would be a class nested under a component class. Source and filter component classes are created with two mandatory iterator methods: get and next. The initialization, destroy, and seek time iterator methods are optional. New functions: * bt_component_class_source_set_notification_iterator_init_method() * bt_component_class_source_set_notification_iterator_destroy_method() * bt_component_class_source_set_notification_iterator_seek_time_method() * bt_component_class_filter_set_notification_iterator_init_method() * bt_component_class_filter_set_notification_iterator_destroy_method() * bt_component_class_filter_set_notification_iterator_seek_time_method() The plugin development interface (babeltrace/plugin/plugin-dev.h) is updated accordingly. Tests and existing plugins are updated accordingly. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- .../component/component-class-filter.h | 22 +- .../component/component-class-internal.h | 12 +- .../component/component-class-source.h | 21 +- .../babeltrace/component/component-class.h | 18 ++ .../notification/iterator-internal.h | 4 - .../component/notification/iterator.h | 85 ------- include/babeltrace/plugin/plugin-dev.h | 214 ++++++++++++++++-- lib/component/component-class.c | 156 ++++++++++++- lib/component/component.c | 22 +- lib/component/iterator.c | 180 ++++++++------- lib/plugin/plugin.c | 130 +++++++++-- plugins/ctf/fs/fs.c | 28 +-- plugins/ctf/fs/fs.h | 11 +- plugins/ctf/lttng-live/lttng-live-internal.h | 12 +- plugins/ctf/lttng-live/lttng-live.c | 13 +- plugins/ctf/plugin.c | 10 +- plugins/muxer/muxer.c | 18 +- plugins/trimmer/iterator.c | 38 +--- plugins/trimmer/iterator.h | 5 +- plugins/trimmer/trimmer.c | 9 +- tests/lib/test-plugin-plugins/sfs.c | 48 +++- 21 files changed, 739 insertions(+), 317 deletions(-) diff --git a/include/babeltrace/component/component-class-filter.h b/include/babeltrace/component/component-class-filter.h index 9eaf4a09..161d13ec 100644 --- a/include/babeltrace/component/component-class-filter.h +++ b/include/babeltrace/component/component-class-filter.h @@ -41,10 +41,30 @@ typedef enum bt_component_status (*bt_component_class_filter_add_iterator_method extern struct bt_component_class *bt_component_class_filter_create(const char *name, - bt_component_class_filter_init_iterator_method init_iterator_method); + bt_component_class_notification_iterator_get_method notification_iterator_get_method, + bt_component_class_notification_iterator_next_method notification_iterator_next_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); +extern +int bt_component_class_filter_set_notification_iterator_init_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_init_method notification_iterator_init_method); + +extern +int bt_component_class_filter_set_notification_iterator_destroy_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method); + +extern +int bt_component_class_filter_set_notification_iterator_seek_time_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method); + +#ifdef __cplusplus +} +#endif + #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 2dacc8f0..fcfe539f 100644 --- a/include/babeltrace/component/component-class-internal.h +++ b/include/babeltrace/component/component-class-internal.h @@ -62,10 +62,18 @@ struct bt_component_class { bool frozen; }; +struct bt_component_class_iterator_methods { + bt_component_class_notification_iterator_init_method init; + bt_component_class_notification_iterator_destroy_method destroy; + bt_component_class_notification_iterator_get_method get; + bt_component_class_notification_iterator_next_method next; + bt_component_class_notification_iterator_seek_time_method seek_time; +}; + struct bt_component_class_source { struct bt_component_class parent; struct { - bt_component_class_source_init_iterator_method init_iterator; + struct bt_component_class_iterator_methods iterator; } methods; }; @@ -80,7 +88,7 @@ struct bt_component_class_sink { struct bt_component_class_filter { struct bt_component_class parent; struct { - bt_component_class_filter_init_iterator_method init_iterator; + struct bt_component_class_iterator_methods iterator; bt_component_class_filter_add_iterator_method add_iterator; } methods; }; diff --git a/include/babeltrace/component/component-class-source.h b/include/babeltrace/component/component-class-source.h index d0b94872..5ca39b1b 100644 --- a/include/babeltrace/component/component-class-source.h +++ b/include/babeltrace/component/component-class-source.h @@ -33,12 +33,25 @@ extern "C" { 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); + bt_component_class_notification_iterator_get_method notification_iterator_get_method, + bt_component_class_notification_iterator_next_method notification_iterator_next_method); + +extern +int bt_component_class_source_set_notification_iterator_init_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_init_method notification_iterator_init_method); + +extern +int bt_component_class_source_set_notification_iterator_destroy_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method); + +extern +int bt_component_class_source_set_notification_iterator_seek_time_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method); #ifdef __cplusplus } diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index d6f76ca8..ac78ce34 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -55,6 +55,24 @@ typedef enum bt_component_status (*bt_component_class_init_method)( typedef void (*bt_component_class_destroy_method)(struct bt_component *component); +typedef enum bt_notification_iterator_status + (*bt_component_class_notification_iterator_init_method)( + struct bt_component *component, + struct bt_notification_iterator *iterator); + +typedef void (*bt_component_class_notification_iterator_destroy_method)( + struct bt_notification_iterator *iterator); + +typedef struct bt_notification *(*bt_component_class_notification_iterator_get_method)( + struct bt_notification_iterator *iterator); + +typedef enum bt_notification_iterator_status (*bt_component_class_notification_iterator_next_method)( + struct bt_notification_iterator *iterator); + +typedef enum bt_notification_iterator_status + (*bt_component_class_notification_iterator_seek_time_method)( + struct bt_notification_iterator *iterator, int64_t time); + extern int bt_component_class_set_init_method( struct bt_component_class *component_class, bt_component_class_init_method init_method); diff --git a/include/babeltrace/component/notification/iterator-internal.h b/include/babeltrace/component/notification/iterator-internal.h index 29a5ff0f..8bad9f93 100644 --- a/include/babeltrace/component/notification/iterator-internal.h +++ b/include/babeltrace/component/notification/iterator-internal.h @@ -34,11 +34,7 @@ struct bt_notification_iterator { struct bt_object base; struct bt_component *component; - bt_notification_iterator_get_cb get; - bt_notification_iterator_next_cb next; - bt_notification_iterator_seek_time_cb seek_time; void *user_data; - bt_notification_iterator_destroy_cb user_destroy; }; /** diff --git a/include/babeltrace/component/notification/iterator.h b/include/babeltrace/component/notification/iterator.h index 69c9b39a..26583c3a 100644 --- a/include/babeltrace/component/notification/iterator.h +++ b/include/babeltrace/component/notification/iterator.h @@ -126,90 +126,6 @@ extern enum bt_notification_iterator_status bt_notification_iterator_seek_time( extern struct bt_component *bt_notification_iterator_get_component( struct bt_notification_iterator *iterator); -/** bt_notification_iterator */ -/** - * Function returning an iterator's current notification. - * - * @param iterator Notification iterator instance - * @returns A notification instance - */ -typedef struct bt_notification *(*bt_notification_iterator_get_cb)( - struct bt_notification_iterator *iterator); - -/** - * Function advancing an iterator's position of one element. - * - * @param iterator Notification iterator instance - * @returns One of #bt_notification_iterator_status values - */ -typedef enum bt_notification_iterator_status (*bt_notification_iterator_next_cb)( - struct bt_notification_iterator *iterator); - -/** - * Function advancing an iterator's position to a given time (relative to Epoch). - * - * @param iterator Notification iterator instance - * @param time Time at which to seek, expressed in ns since Epoch - * @returns One of #bt_notification_iterator_status values - */ -typedef enum bt_notification_iterator_status - (*bt_notification_iterator_seek_time_cb)( - struct bt_notification_iterator *iterator, int64_t time); - -/** - * Function cleaning-up an iterator's private data on destruction. - * - * @param iterator Notification iterator instance - */ -typedef void (*bt_notification_iterator_destroy_cb)( - struct bt_notification_iterator *iterator); - -/** - * Set an iterator's "get" callback which return the current notification. - * - * @param iterator Notification iterator instance - * @param get Notification return callback - * @returns One of #bt_notification_iterator_status values - */ -extern enum bt_notification_iterator_status -bt_notification_iterator_set_get_cb(struct bt_notification_iterator *iterator, - bt_notification_iterator_get_cb get); - -/** - * Set an iterator's "next" callback which advances the iterator's position. - * - * @param iterator Notification iterator instance - * @param next Iterator "next" callback - * @returns One of #bt_notification_iterator_status values - */ -extern enum bt_notification_iterator_status -bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator, - bt_notification_iterator_next_cb next); - -/** - * Set an iterator's "seek_time" callback which sets the iterator's position to - * provided time (in ns since Epoch). - * - * @param iterator Notification iterator instance - * @param seek_timetime Iterator "seek_time" callback - * @returns One of #bt_notification_iterator_status values - */ -extern enum bt_notification_iterator_status -bt_notification_iterator_set_seek_time_cb(struct bt_notification_iterator *iterator, - bt_notification_iterator_seek_time_cb seek_time); - -/** - * Set an iterator's "destroy" callback. - * - * @param iterator Notification iterator instance - * @param next Iterator destruction callback - * @returns One of #bt_notification_iterator_status values - */ -extern enum bt_notification_iterator_status -bt_notification_iterator_set_destroy_cb( - struct bt_notification_iterator *iterator, - bt_notification_iterator_destroy_cb destroy); - /** * Set an iterator's private data. * @@ -230,7 +146,6 @@ bt_notification_iterator_set_private_data( extern void *bt_notification_iterator_get_private_data( struct bt_notification_iterator *iterator); - #ifdef __cplusplus } #endif diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 76e58e67..c8ea1c85 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -145,12 +145,14 @@ struct __bt_plugin_component_class_descriptor { union { /* BT_COMPONENT_CLASS_TYPE_SOURCE */ struct { - bt_component_class_source_init_iterator_method init_iterator; + bt_component_class_notification_iterator_get_method notif_iter_get; + bt_component_class_notification_iterator_next_method notif_iter_next; } source; /* BT_COMPONENT_CLASS_TYPE_FILTER */ struct { - bt_component_class_filter_init_iterator_method init_iterator; + bt_component_class_notification_iterator_get_method notif_iter_get; + bt_component_class_notification_iterator_next_method notif_iter_next; } filter; /* BT_COMPONENT_CLASS_TYPE_SINK */ @@ -167,6 +169,9 @@ enum __bt_plugin_component_class_descriptor_attribute_type { 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, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD = 5, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD = 6, + BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD = 7, }; /* Component class attribute (internal use) */ @@ -199,6 +204,15 @@ struct __bt_plugin_component_class_descriptor_attribute { /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_SINK_ADD_ITERATOR_METHOD */ bt_component_class_sink_add_iterator_method sink_add_iterator_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD */ + bt_component_class_notification_iterator_init_method notif_iter_init_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD */ + bt_component_class_notification_iterator_destroy_method notif_iter_destroy_method; + + /* BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD */ + bt_component_class_notification_iterator_seek_time_method notif_iter_seek_time_method; } value; } __attribute__((packed)); @@ -347,19 +361,22 @@ struct __bt_plugin_component_class_descriptor_attribute { /* * 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). - * _name: Component class name (C string). - * _init_iterator_method: Component class's iterator initialization method - * (bt_component_class_source_init_iterator_method). + * _id: ID (any valid C identifier except `auto`). + * _comp_class_id: Component class ID (C identifier). + * _name: Component class name (C string). + * _notif_iter_get_method: Component class's iterator get method + * (bt_component_class_notification_iterator_get_method). + * _notif_iter_next_method: Component class's iterator next method + * (bt_component_class_notification_iterator_next_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _notif_iter_get_method, _notif_iter_next_method) \ static struct __bt_plugin_component_class_descriptor __bt_plugin_source_component_class_descriptor_##_id##_##_comp_class_id = { \ .plugin_descriptor = &__bt_plugin_descriptor_##_id, \ .name = _name, \ .type = BT_COMPONENT_CLASS_TYPE_SOURCE, \ .methods.source = { \ - .init_iterator = _init_iterator_method, \ + .notif_iter_get = _notif_iter_get_method, \ + .notif_iter_next = _notif_iter_next_method, \ }, \ }; \ 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; \ @@ -371,16 +388,19 @@ struct __bt_plugin_component_class_descriptor_attribute { * _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). + * _notif_iter_get_method: Component class's iterator get method + * (bt_component_class_notification_iterator_get_method). + * _notif_iter_next_method: Component class's iterator next method + * (bt_component_class_notification_iterator_next_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _init_iterator_method) \ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _notif_iter_get_method, _notif_iter_next_method) \ static struct __bt_plugin_component_class_descriptor __bt_plugin_filter_component_class_descriptor_##_id##_##_comp_class_id = { \ .plugin_descriptor = &__bt_plugin_descriptor_##_id, \ .name = _name, \ .type = BT_COMPONENT_CLASS_TYPE_FILTER, \ .methods.filter = { \ - .init_iterator = _init_iterator_method, \ + .notif_iter_get = _notif_iter_get_method, \ + .notif_iter_next = _notif_iter_next_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; \ @@ -553,6 +573,78 @@ struct __bt_plugin_component_class_descriptor_attribute { #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 an iterator 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: Iterator initialization method + * (bt_component_class_notification_iterator_init_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines an iterator 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: Iterator destroy method + * (bt_component_class_notification_iterator_destroy_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines an iterator seek time 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: Iterator seek time method + * (bt_component_class_notification_iterator_seek_time_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_seek_time_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD, _id, _comp_class_id, source, _x) + +/* + * Defines an iterator 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: Iterator initialization method + * (bt_component_class_notification_iterator_init_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_init_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an iterator 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: Iterator destroy method + * (bt_component_class_notification_iterator_destroy_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_destroy_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD, _id, _comp_class_id, filter, _x) + +/* + * Defines an iterator seek time 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: Iterator seek time method + * (bt_component_class_notification_iterator_seek_time_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD_WITH_ID(_id, _comp_class_id, _x) \ + __BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE(notif_iter_seek_time_method, BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD, _id, _comp_class_id, filter, _x) + /* * Defines a plugin descriptor with an automatic ID. * @@ -616,24 +708,28 @@ struct __bt_plugin_component_class_descriptor_attribute { * 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). + * _name: Component class name (C identifier). + * _notif_iter_get_method: Component class's iterator get method + * (bt_component_class_notification_iterator_get_method). + * _notif_iter_next_method: Component class's iterator next method + * (bt_component_class_notification_iterator_next_method). */ -#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _init_iterator_method) \ - BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _notif_iter_get_method, _notif_iter_next_method) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_get_method, _notif_iter_next_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. * - * _name: Component class name (C identifier). - * _init_iterator_method: Component class's iterator initialization method - * (bt_component_class_filter_init_iterator_method). + * _name: Component class name (C identifier). + * _notif_iter_get_method: Component class's iterator get method + * (bt_component_class_notification_iterator_get_method). + * _notif_iter_next_method: Component class's iterator next method + * (bt_component_class_notification_iterator_next_method). */ -#define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _init_iterator_method) \ - BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _init_iterator_method) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _notif_iter_get_method, _notif_iter_next_method) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_get_method, _notif_iter_next_method) /* * Defines a sink component class attached to the automatic plugin @@ -764,6 +860,78 @@ struct __bt_plugin_component_class_descriptor_attribute { #define BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD(_name, _x) \ BT_PLUGIN_SINK_COMPONENT_CLASS_ADD_ITERATOR_METHOD_WITH_ID(auto, _name, _x) +/* + * Defines an iterator 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: Iterator initialization method + * (bt_component_class_notification_iterator_init_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an iterator 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: Iterator destroy method + * (bt_component_class_notification_iterator_destroy_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an iterator seek time method attribute attached to a source + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Iterator seek time method + * (bt_component_class_notification_iterator_seek_time_method). + */ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(_name, _x) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an iterator 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: Iterator initialization method + * (bt_component_class_notification_iterator_init_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an iterator 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: Iterator destroy method + * (bt_component_class_notification_iterator_destroy_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD_WITH_ID(auto, _name, _x) + +/* + * Defines an iterator seek time method attribute attached to a filter + * component class descriptor which is attached to the automatic plugin + * descriptor. + * + * _name: Component class name (C identifier). + * _x: Iterator seek time method + * (bt_component_class_notification_iterator_seek_time_method). + */ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(_name, _x) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD_WITH_ID(auto, _name, _x) + #ifdef __cplusplus } #endif diff --git a/lib/component/component-class.c b/lib/component/component-class.c index 55f020d2..1f6e680a 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -99,12 +99,14 @@ end: } struct bt_component_class *bt_component_class_source_create(const char *name, - bt_component_class_source_init_iterator_method init_iterator_method) + bt_component_class_notification_iterator_get_method notification_iterator_get_method, + bt_component_class_notification_iterator_next_method notification_iterator_next_method) { struct bt_component_class_source *source_class = NULL; int ret; - if (!name || !init_iterator_method) { + if (!name || !notification_iterator_get_method || + !notification_iterator_next_method) { goto end; } @@ -125,19 +127,22 @@ struct bt_component_class *bt_component_class_source_create(const char *name, goto end; } - source_class->methods.init_iterator = init_iterator_method; + source_class->methods.iterator.get = notification_iterator_get_method; + source_class->methods.iterator.next = notification_iterator_next_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) + bt_component_class_notification_iterator_get_method notification_iterator_get_method, + bt_component_class_notification_iterator_next_method notification_iterator_next_method) { struct bt_component_class_filter *filter_class = NULL; int ret; - if (!name || !init_iterator_method) { + if (!name || !notification_iterator_get_method || + !notification_iterator_next_method) { goto end; } @@ -158,7 +163,8 @@ struct bt_component_class *bt_component_class_filter_create(const char *name, goto end; } - filter_class->methods.init_iterator = init_iterator_method; + filter_class->methods.iterator.get = notification_iterator_get_method; + filter_class->methods.iterator.next = notification_iterator_next_method; end: return &filter_class->parent; @@ -231,7 +237,143 @@ end: return ret; } -extern int bt_component_class_set_description( +int bt_component_class_source_set_notification_iterator_init_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_init_method notification_iterator_init_method) +{ + struct bt_component_class_source *source_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_init_method || + component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { + ret = -1; + goto end; + } + + source_class = container_of(component_class, + struct bt_component_class_source, parent); + source_class->methods.iterator.init = notification_iterator_init_method; + +end: + return ret; +} + +int bt_component_class_source_set_notification_iterator_destroy_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method) +{ + struct bt_component_class_source *source_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_destroy_method || + component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { + ret = -1; + goto end; + } + + source_class = container_of(component_class, + struct bt_component_class_source, parent); + source_class->methods.iterator.destroy = + notification_iterator_destroy_method; + +end: + return ret; +} + +int bt_component_class_source_set_notification_iterator_seek_time_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method) +{ + struct bt_component_class_source *source_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_seek_time_method || + component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) { + ret = -1; + goto end; + } + + source_class = container_of(component_class, + struct bt_component_class_source, parent); + source_class->methods.iterator.seek_time = + notification_iterator_seek_time_method; + +end: + return ret; +} + +int bt_component_class_filter_set_notification_iterator_init_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_init_method notification_iterator_init_method) +{ + struct bt_component_class_filter *filter_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_init_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.iterator.init = notification_iterator_init_method; + +end: + return ret; +} + +int bt_component_class_filter_set_notification_iterator_destroy_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_destroy_method notification_iterator_destroy_method) +{ + struct bt_component_class_filter *filter_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_destroy_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.iterator.destroy = + notification_iterator_destroy_method; + +end: + return ret; +} + +int bt_component_class_filter_set_notification_iterator_seek_time_method( + struct bt_component_class *component_class, + bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method) +{ + struct bt_component_class_filter *filter_class; + int ret = 0; + + if (!component_class || component_class->frozen || + !notification_iterator_seek_time_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.iterator.seek_time = + notification_iterator_seek_time_method; + +end: + return ret; +} + +int bt_component_class_set_description( struct bt_component_class *component_class, const char *description) { diff --git a/lib/component/component.c b/lib/component/component.c index c3ccd95c..d6921a42 100644 --- a/lib/component/component.c +++ b/lib/component/component.c @@ -134,29 +134,27 @@ struct bt_notification_iterator *bt_component_create_iterator( case BT_COMPONENT_CLASS_TYPE_SOURCE: { struct bt_component_class_source *source_class; - enum bt_component_status ret_component; + enum bt_notification_iterator_status status; 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) { + assert(source_class->methods.iterator.init); + status = source_class->methods.iterator.init(component, + iterator); + if (status < 0) { goto error; } break; - - break; } case BT_COMPONENT_CLASS_TYPE_FILTER: { struct bt_component_class_filter *filter_class; - enum bt_component_status ret_component; + enum bt_notification_iterator_status status; 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) { + assert(filter_class->methods.iterator.init); + status = filter_class->methods.iterator.init(component, + iterator); + if (status < 0) { goto error; } break; diff --git a/lib/component/iterator.c b/lib/component/iterator.c index c8c41a0b..cffa0d91 100644 --- a/lib/component/iterator.c +++ b/lib/component/iterator.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -37,14 +38,43 @@ static void bt_notification_iterator_destroy(struct bt_object *obj) { struct bt_notification_iterator *iterator; + struct bt_component_class *comp_class; assert(obj); iterator = container_of(obj, struct bt_notification_iterator, base); - assert(iterator->user_destroy || !iterator->user_data); - if (iterator->user_destroy) { - iterator->user_destroy(iterator); + assert(iterator->component); + comp_class = iterator->component->class; + + /* Call user-defined destroy method */ + switch (comp_class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *source_class; + + source_class = container_of(comp_class, struct bt_component_class_source, parent); + + if (source_class->methods.iterator.destroy) { + source_class->methods.iterator.destroy(iterator); + } + break; } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *filter_class; + + filter_class = container_of(comp_class, struct bt_component_class_filter, parent); + + if (filter_class->methods.iterator.destroy) { + filter_class->methods.iterator.destroy(iterator); + } + break; + } + default: + /* Unreachable */ + assert(0); + } + BT_PUT(iterator->component); g_free(iterator); } @@ -87,80 +117,10 @@ enum bt_notification_iterator_status bt_notification_iterator_validate( enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; - if (!iterator || !iterator->get || !iterator->next) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } -end: - return ret; -} - -enum bt_notification_iterator_status bt_notification_iterator_set_get_cb( - struct bt_notification_iterator *iterator, - bt_notification_iterator_get_cb get) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !get) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } - - iterator->get = get; -end: - return ret; -} - -enum bt_notification_iterator_status -bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator, - bt_notification_iterator_next_cb next) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !next) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } - - iterator->next = next; -end: - return ret; -} - -enum bt_notification_iterator_status -bt_notification_iterator_set_seek_time_cb( - struct bt_notification_iterator *iterator, - bt_notification_iterator_seek_time_cb seek_time) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !seek_time) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } - - iterator->seek_time = seek_time; -end: - return ret; -} - -enum bt_notification_iterator_status -bt_notification_iterator_set_destroy_cb( - struct bt_notification_iterator *iterator, - bt_notification_iterator_destroy_cb destroy) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !destroy) { + if (!iterator) { ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; goto end; } - - iterator->user_destroy = destroy; end: return ret; } @@ -178,7 +138,7 @@ bt_notification_iterator_set_private_data( enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; - if (!iterator || !data) { + if (!iterator) { ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; goto end; } @@ -191,17 +151,79 @@ end: struct bt_notification *bt_notification_iterator_get_notification( struct bt_notification_iterator *iterator) { + bt_component_class_notification_iterator_get_method get_method = NULL; + assert(iterator); - assert(iterator->get); - return iterator->get(iterator); + assert(iterator->component); + assert(iterator->component->class); + + switch (iterator->component->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *source_class = + container_of(iterator->component->class, + struct bt_component_class_source, parent); + + assert(source_class->methods.iterator.get); + get_method = source_class->methods.iterator.get; + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *filter_class = + container_of(iterator->component->class, + struct bt_component_class_filter, parent); + + assert(filter_class->methods.iterator.get); + get_method = filter_class->methods.iterator.get; + break; + } + default: + assert(false); + break; + } + + assert(get_method); + return get_method(iterator); } enum bt_notification_iterator_status bt_notification_iterator_next(struct bt_notification_iterator *iterator) { + bt_component_class_notification_iterator_next_method next_method = NULL; + assert(iterator); - assert(iterator->next); - return iterator->next(iterator); + assert(iterator->component); + assert(iterator->component->class); + + switch (iterator->component->class->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + { + struct bt_component_class_source *source_class = + container_of(iterator->component->class, + struct bt_component_class_source, parent); + + assert(source_class->methods.iterator.next); + next_method = source_class->methods.iterator.next; + break; + } + case BT_COMPONENT_CLASS_TYPE_FILTER: + { + struct bt_component_class_filter *filter_class = + container_of(iterator->component->class, + struct bt_component_class_filter, parent); + + assert(filter_class->methods.iterator.next); + next_method = filter_class->methods.iterator.next; + break; + } + default: + assert(false); + break; + } + + assert(next_method); + return next_method(iterator); } struct bt_component *bt_notification_iterator_get_component( diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 707fe4e7..ce4e4349 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -286,6 +286,7 @@ enum bt_plugin_status bt_plugin_init( 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; + struct bt_component_class_iterator_methods iterator_methods; }; enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; @@ -408,6 +409,18 @@ enum bt_plugin_status bt_plugin_init( cc_full_descr->sink_add_iterator_method = cur_cc_descr_attr->value.sink_add_iterator_method; break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD: + cc_full_descr->iterator_methods.init = + cur_cc_descr_attr->value.notif_iter_init_method; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_DESTROY_METHOD: + cc_full_descr->iterator_methods.destroy = + cur_cc_descr_attr->value.notif_iter_destroy_method; + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD: + cc_full_descr->iterator_methods.seek_time = + cur_cc_descr_attr->value.notif_iter_seek_time_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, @@ -444,12 +457,14 @@ enum bt_plugin_status bt_plugin_init( 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); + cc_full_descr->descriptor->methods.source.notif_iter_get, + cc_full_descr->descriptor->methods.source.notif_iter_next); 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); + cc_full_descr->descriptor->methods.source.notif_iter_get, + cc_full_descr->descriptor->methods.source.notif_iter_next); break; case BT_COMPONENT_CLASS_TYPE_SINK: comp_class = bt_component_class_sink_create( @@ -499,28 +514,101 @@ enum bt_plugin_status bt_plugin_init( } } - 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; + switch (cc_full_descr->descriptor->type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + if (cc_full_descr->iterator_methods.init) { + ret = bt_component_class_source_set_notification_iterator_init_method( + comp_class, + cc_full_descr->iterator_methods.init); + 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; + if (cc_full_descr->iterator_methods.destroy) { + ret = bt_component_class_source_set_notification_iterator_destroy_method( + comp_class, + cc_full_descr->iterator_methods.destroy); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } } + + if (cc_full_descr->iterator_methods.seek_time) { + ret = bt_component_class_source_set_notification_iterator_seek_time_method( + comp_class, + cc_full_descr->iterator_methods.seek_time); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + if (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->iterator_methods.init) { + ret = bt_component_class_filter_set_notification_iterator_init_method( + comp_class, + cc_full_descr->iterator_methods.init); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->iterator_methods.destroy) { + ret = bt_component_class_filter_set_notification_iterator_destroy_method( + comp_class, + cc_full_descr->iterator_methods.destroy); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + + if (cc_full_descr->iterator_methods.seek_time) { + ret = bt_component_class_filter_set_notification_iterator_seek_time_method( + comp_class, + cc_full_descr->iterator_methods.seek_time); + if (ret) { + status = BT_PLUGIN_STATUS_ERROR; + BT_PUT(comp_class); + goto end; + } + } + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + if (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; + } + } + break; + default: + assert(false); + break; } /* Add component class to the plugin object */ diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index 450627d7..61cac172 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -49,11 +49,9 @@ BT_HIDDEN bool ctf_fs_debug; -static enum bt_notification_iterator_status ctf_fs_iterator_next( struct bt_notification_iterator *iterator); -static struct bt_notification *ctf_fs_iterator_get( struct bt_notification_iterator *iterator) { @@ -246,7 +244,6 @@ end: return ret; } -static enum bt_notification_iterator_status ctf_fs_iterator_next( struct bt_notification_iterator *iterator) { @@ -364,7 +361,6 @@ void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it) g_free(ctf_it); } -static void ctf_fs_iterator_destroy(struct bt_notification_iterator *it) { void *data = bt_notification_iterator_get_private_data(it); @@ -584,24 +580,24 @@ end: return ret; } -enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, +enum bt_notification_iterator_status ctf_fs_iterator_init(struct bt_component *source, struct bt_notification_iterator *it) { struct ctf_fs_iterator *ctf_it; struct ctf_fs_component *ctf_fs; - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_notification_iterator_status ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; assert(source && it); ctf_fs = bt_component_get_private_data(source); if (!ctf_fs) { - ret = BT_COMPONENT_STATUS_INVALID; + ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; goto end; } ctf_it = g_new0(struct ctf_fs_iterator, 1); if (!ctf_it) { - ret = BT_COMPONENT_STATUS_NOMEM; + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; goto end; } @@ -626,22 +622,6 @@ enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, goto error; } - ret = bt_notification_iterator_set_get_cb(it, ctf_fs_iterator_get); - if (ret) { - goto error; - } - - ret = bt_notification_iterator_set_next_cb(it, ctf_fs_iterator_next); - if (ret) { - goto error; - } - - ret = bt_notification_iterator_set_destroy_cb(it, - ctf_fs_iterator_destroy); - if (ret) { - goto error; - } - ret = bt_notification_iterator_set_private_data(it, ctf_it); if (ret) { goto error; diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 7ade621f..4c165676 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -113,7 +113,16 @@ BT_HIDDEN void ctf_fs_destroy(struct bt_component *component); BT_HIDDEN -enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, +enum bt_notification_iterator_status ctf_fs_iterator_init( + struct bt_component *source, struct bt_notification_iterator *it); +void ctf_fs_iterator_destroy(struct bt_notification_iterator *it); + +enum bt_notification_iterator_status ctf_fs_iterator_next( + struct bt_notification_iterator *iterator); + +struct bt_notification *ctf_fs_iterator_get( + struct bt_notification_iterator *iterator); + #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 bb3c4e43..17d8e87e 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -32,12 +32,16 @@ #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, void *init_method_data); +BT_HIDDEN +struct bt_notification *lttng_live_iterator_get( + struct bt_notification_iterator *iterator); + +BT_HIDDEN +enum bt_notification_iterator_status lttng_live_iterator_next( + struct bt_notification_iterator *iterator); + #endif /* BABELTRACE_PLUGIN_CTF_LTTNG_LIVE_INTERNAL_H */ diff --git a/plugins/ctf/lttng-live/lttng-live.c b/plugins/ctf/lttng-live/lttng-live.c index add91ccb..5f082fcc 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -31,10 +31,17 @@ #include BT_HIDDEN -enum bt_component_status lttng_live_iterator_init(struct bt_component *source, - struct bt_notification_iterator *it) +struct bt_notification *lttng_live_iterator_get( + struct bt_notification_iterator *iterator) { - return BT_COMPONENT_STATUS_OK; + return NULL; +} + +BT_HIDDEN +enum bt_notification_iterator_status lttng_live_iterator_next( + struct bt_notification_iterator *iterator) +{ + return BT_NOTIFICATION_ITERATOR_STATUS_OK; } BT_HIDDEN diff --git a/plugins/ctf/plugin.c b/plugins/ctf/plugin.c index 77f5057b..b79e5073 100644 --- a/plugins/ctf/plugin.c +++ b/plugins/ctf/plugin.c @@ -37,13 +37,17 @@ BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); /* Declare component classes implemented by this plug-in. */ -BT_PLUGIN_SOURCE_COMPONENT_CLASS(fs, ctf_fs_iterator_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(fs, ctf_fs_iterator_get, ctf_fs_iterator_next); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(fs, CTF_FS_COMPONENT_DESCRIPTION); 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_NOTIFICATION_ITERATOR_INIT_METHOD(fs, + ctf_fs_iterator_init); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(fs, + ctf_fs_iterator_destroy); BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, lttng_live, "lttng-live", - lttng_live_iterator_init); + lttng_live_iterator_get, lttng_live_iterator_next); 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, diff --git a/plugins/muxer/muxer.c b/plugins/muxer/muxer.c index f8eb7d30..745e0803 100644 --- a/plugins/muxer/muxer.c +++ b/plugins/muxer/muxer.c @@ -85,11 +85,18 @@ error: return ret; } -enum bt_component_status muxer_init_iterator( - struct bt_component *component, - struct bt_notification_iterator *iter) +static +struct bt_notification *muxer_iterator_get( + struct bt_notification_iterator *iterator) +{ + return NULL; +} + +static +enum bt_notification_iterator_status muxer_iterator_next( + struct bt_notification_iterator *iterator) { - return BT_COMPONENT_STATUS_OK; + return BT_NOTIFICATION_ITERATOR_STATUS_OK; } /* Initialize plug-in entry points. */ @@ -97,7 +104,8 @@ BT_PLUGIN(muxer); BT_PLUGIN_DESCRIPTION("Babeltrace Trace Muxer Plug-In."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_FILTER_COMPONENT_CLASS(muxer, muxer_init_iterator); +BT_PLUGIN_FILTER_COMPONENT_CLASS(muxer, muxer_iterator_get, + muxer_iterator_next); BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(muxer, "Time-correlate multiple traces."); BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(muxer, muxer_component_init); diff --git a/plugins/trimmer/iterator.c b/plugins/trimmer/iterator.c index d7633a9c..614748a2 100644 --- a/plugins/trimmer/iterator.c +++ b/plugins/trimmer/iterator.c @@ -43,7 +43,7 @@ #include #include -static +BT_HIDDEN void trimmer_iterator_destroy(struct bt_notification_iterator *it) { struct trimmer_iterator *it_data; @@ -59,15 +59,17 @@ void trimmer_iterator_destroy(struct bt_notification_iterator *it) } BT_HIDDEN -enum bt_component_status trimmer_iterator_init(struct bt_component *component, +enum bt_notification_iterator_status trimmer_iterator_init( + struct bt_component *component, struct bt_notification_iterator *iterator) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + enum bt_notification_iterator_status ret = + BT_NOTIFICATION_ITERATOR_STATUS_OK; enum bt_notification_iterator_status it_ret; struct trimmer_iterator *it_data = g_new0(struct trimmer_iterator, 1); if (!it_data) { - ret = BT_COMPONENT_STATUS_NOMEM; + ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; goto end; } @@ -76,34 +78,6 @@ enum bt_component_status trimmer_iterator_init(struct bt_component *component, if (it_ret) { goto end; } - - it_ret = bt_notification_iterator_set_destroy_cb(iterator, - trimmer_iterator_destroy); - if (it_ret) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - it_ret = bt_notification_iterator_set_next_cb(iterator, - trimmer_iterator_next); - if (it_ret) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - it_ret = bt_notification_iterator_set_get_cb(iterator, - trimmer_iterator_get); - if (it_ret) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } - - it_ret = bt_notification_iterator_set_seek_time_cb(iterator, - trimmer_iterator_seek_time); - if (it_ret) { - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - } end: return ret; } diff --git a/plugins/trimmer/iterator.h b/plugins/trimmer/iterator.h index 1ab0b6f5..9bebf459 100644 --- a/plugins/trimmer/iterator.h +++ b/plugins/trimmer/iterator.h @@ -38,10 +38,13 @@ struct trimmer_iterator { }; BT_HIDDEN -enum bt_component_status trimmer_iterator_init( +enum bt_notification_iterator_status trimmer_iterator_init( struct bt_component *component, struct bt_notification_iterator *iterator); +BT_HIDDEN +void trimmer_iterator_destroy(struct bt_notification_iterator *it); + BT_HIDDEN struct bt_notification *trimmer_iterator_get( struct bt_notification_iterator *iterator); diff --git a/plugins/trimmer/trimmer.c b/plugins/trimmer/trimmer.c index fd028d02..06814ef8 100644 --- a/plugins/trimmer/trimmer.c +++ b/plugins/trimmer/trimmer.c @@ -379,8 +379,15 @@ BT_PLUGIN(utils); BT_PLUGIN_DESCRIPTION("Babeltrace Trace Trimmer Plug-In."); BT_PLUGIN_AUTHOR("Jérémie Galarneau"); BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_get, + trimmer_iterator_next); 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); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(trimmer, + trimmer_iterator_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(trimmer, + trimmer_iterator_destroy); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(trimmer, + trimmer_iterator_seek_time); diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index a9d58ce6..52d3bf9f 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -23,10 +23,34 @@ static enum bt_component_status sink_consume(struct bt_component *component) return BT_COMPONENT_STATUS_OK; } -enum bt_component_status dummy_init_iterator_method( - struct bt_component *component, struct bt_notification_iterator *iter) +static enum bt_notification_iterator_status dummy_iterator_init_method( + struct bt_component *component, + struct bt_notification_iterator *iterator) { - return BT_COMPONENT_STATUS_OK; + return BT_NOTIFICATION_ITERATOR_STATUS_OK; +} + +static void dummy_iterator_destroy_method( + struct bt_notification_iterator *iterator) +{ +} + +static struct bt_notification *dummy_iterator_get_method( + struct bt_notification_iterator *iterator) +{ + return NULL; +} + +static enum bt_notification_iterator_status dummy_iterator_next_method( + struct bt_notification_iterator *iterator) +{ + return BT_NOTIFICATION_ITERATOR_STATUS_OK; +} + +static enum bt_notification_iterator_status dummy_iterator_seek_time_method( + struct bt_notification_iterator *iterator, int64_t time) +{ + return BT_NOTIFICATION_ITERATOR_STATUS_OK; } BT_PLUGIN(test_sfs); @@ -35,11 +59,25 @@ BT_PLUGIN_AUTHOR("Janine Sutto"); BT_PLUGIN_LICENSE("Beerware"); BT_PLUGIN_VERSION(1, 2, 3, "yes"); -BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_init_iterator_method); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_iterator_get_method, + dummy_iterator_next_method); BT_PLUGIN_SOURCE_COMPONENT_CLASS_DESCRIPTION(source, "A source."); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(source, + dummy_iterator_init_method); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(source, + dummy_iterator_destroy_method); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(source, + dummy_iterator_seek_time_method); BT_PLUGIN_SINK_COMPONENT_CLASS(sink, sink_consume); BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(sink, "A sink."); -BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_init_iterator_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_iterator_get_method, + dummy_iterator_next_method); BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(filter, "A filter."); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(filter, + dummy_iterator_init_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(filter, + dummy_iterator_destroy_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(filter, + dummy_iterator_seek_time_method); -- 2.34.1