From 41a2b7aeccec8153fc6845819a0ca98461f35cb1 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 28 Mar 2017 19:57:34 -0400 Subject: [PATCH] Remove the need to implement the notification iterator's "get" method MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The order of a notification iterator's "get" method is to return the "current notification", set by the last "next" method call. Since all source and filter plugins do the same in their "get" method, let's remove the need to implement it at all. The bt_notification_iterator_next() and bt_notification_iterator_get_notification() public functions are still available for the iterator's user, but the iterator object itself keeps the current notification returned by the last "next" method call. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- .../component/component-class-filter.h | 1 - .../component/component-class-internal.h | 1 - .../component/component-class-source.h | 1 - .../babeltrace/component/component-class.h | 5 +- .../notification/iterator-internal.h | 2 + .../component/notification/iterator.h | 5 ++ include/babeltrace/plugin/plugin-dev.h | 24 ++----- lib/component/component-class.c | 10 +-- lib/component/iterator.c | 62 ++++++++---------- lib/plugin/plugin-so.c | 2 - plugins/ctf/fs/fs.c | 65 ++++++++----------- plugins/ctf/fs/fs.h | 6 +- plugins/ctf/lttng-live/lttng-live-internal.h | 6 +- plugins/ctf/lttng-live/lttng-live.c | 8 ++- plugins/ctf/plugin.c | 4 +- plugins/muxer/muxer.c | 16 ++--- plugins/text/text.c | 30 ++++----- plugins/utils/plugin.c | 3 +- plugins/utils/trimmer/iterator.c | 52 ++++----------- plugins/utils/trimmer/iterator.h | 7 +- tests/lib/test-plugin-plugins/sfs.c | 19 +++--- 21 files changed, 122 insertions(+), 207 deletions(-) diff --git a/include/babeltrace/component/component-class-filter.h b/include/babeltrace/component/component-class-filter.h index be44271e..60ed0f7c 100644 --- a/include/babeltrace/component/component-class-filter.h +++ b/include/babeltrace/component/component-class-filter.h @@ -35,7 +35,6 @@ struct bt_component_class; extern struct bt_component_class *bt_component_class_filter_create(const char *name, - bt_component_class_notification_iterator_get_method notification_iterator_get_method, bt_component_class_notification_iterator_next_method notification_iterator_next_method); extern diff --git a/include/babeltrace/component/component-class-internal.h b/include/babeltrace/component/component-class-internal.h index 6aed6f0b..1cafef64 100644 --- a/include/babeltrace/component/component-class-internal.h +++ b/include/babeltrace/component/component-class-internal.h @@ -69,7 +69,6 @@ struct bt_component_class { struct bt_component_class_iterator_methods { bt_component_class_notification_iterator_init_method init; bt_component_class_notification_iterator_finalize_method finalize; - 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; }; diff --git a/include/babeltrace/component/component-class-source.h b/include/babeltrace/component/component-class-source.h index beaaa878..a6de3ae5 100644 --- a/include/babeltrace/component/component-class-source.h +++ b/include/babeltrace/component/component-class-source.h @@ -35,7 +35,6 @@ struct bt_component_class; extern struct bt_component_class *bt_component_class_source_create(const char *name, - bt_component_class_notification_iterator_get_method notification_iterator_get_method, bt_component_class_notification_iterator_next_method notification_iterator_next_method); extern diff --git a/include/babeltrace/component/component-class.h b/include/babeltrace/component/component-class.h index 29b66ecb..ea95f4e0 100644 --- a/include/babeltrace/component/component-class.h +++ b/include/babeltrace/component/component-class.h @@ -72,10 +72,7 @@ typedef enum bt_notification_iterator_status typedef void (*bt_component_class_notification_iterator_finalize_method)( struct bt_private_notification_iterator *private_notification_iterator); -typedef struct bt_notification *(*bt_component_class_notification_iterator_get_method)( - struct bt_private_notification_iterator *private_notification_iterator); - -typedef enum bt_notification_iterator_status (*bt_component_class_notification_iterator_next_method)( +typedef struct bt_notification_iterator_next_return (*bt_component_class_notification_iterator_next_method)( struct bt_private_notification_iterator *private_notification_iterator); typedef enum bt_notification_iterator_status diff --git a/include/babeltrace/component/notification/iterator-internal.h b/include/babeltrace/component/notification/iterator-internal.h index 99e9617c..b1300f03 100644 --- a/include/babeltrace/component/notification/iterator-internal.h +++ b/include/babeltrace/component/notification/iterator-internal.h @@ -30,12 +30,14 @@ #include #include #include +#include #include #include struct bt_notification_iterator { struct bt_object base; struct bt_component *component; + struct bt_notification *current_notification; void *user_data; }; diff --git a/include/babeltrace/component/notification/iterator.h b/include/babeltrace/component/notification/iterator.h index bc226e13..8cf2a062 100644 --- a/include/babeltrace/component/notification/iterator.h +++ b/include/babeltrace/component/notification/iterator.h @@ -72,6 +72,11 @@ enum bt_notification_iterator_seek_origin { BT_NOTIFICATION_ITERATOR_SEEK_ORIGIN_EPOCH = 3, }; +struct bt_notification_iterator_next_return { + struct bt_notification *notification; + enum bt_notification_iterator_status status; +}; + /** * Get current notification at iterator's position. * diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index d8d02815..5221b974 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -145,13 +145,11 @@ struct __bt_plugin_component_class_descriptor { union { /* BT_COMPONENT_CLASS_TYPE_SOURCE */ struct { - 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_notification_iterator_get_method notif_iter_get; bt_component_class_notification_iterator_next_method notif_iter_next; } filter; @@ -372,18 +370,15 @@ 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). - * _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, _notif_iter_get_method, _notif_iter_next_method) \ +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _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 = { \ - .notif_iter_get = _notif_iter_get_method, \ .notif_iter_next = _notif_iter_next_method, \ }, \ }; \ @@ -396,18 +391,15 @@ 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). - * _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, _notif_iter_get_method, _notif_iter_next_method) \ +#define BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(_id, _comp_class_id, _name, _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 = { \ - .notif_iter_get = _notif_iter_get_method, \ .notif_iter_next = _notif_iter_next_method, \ }, \ }; \ @@ -831,13 +823,11 @@ struct __bt_plugin_component_class_descriptor_attribute { * C identifier in this version. * * _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, _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) +#define BT_PLUGIN_SOURCE_COMPONENT_CLASS(_name, _notif_iter_next_method) \ + BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_next_method) /* * Defines a filter component class attached to the automatic plugin @@ -845,13 +835,11 @@ struct __bt_plugin_component_class_descriptor_attribute { * C identifier in this version. * * _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, _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) +#define BT_PLUGIN_FILTER_COMPONENT_CLASS(_name, _notif_iter_next_method) \ + BT_PLUGIN_FILTER_COMPONENT_CLASS_WITH_ID(auto, _name, #_name, _notif_iter_next_method) /* * Defines a sink component class attached to the automatic plugin diff --git a/lib/component/component-class.c b/lib/component/component-class.c index 0f533725..f3cbb422 100644 --- a/lib/component/component-class.c +++ b/lib/component/component-class.c @@ -107,14 +107,12 @@ end: } struct bt_component_class *bt_component_class_source_create(const char *name, - 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 || !notification_iterator_get_method || - !notification_iterator_next_method) { + if (!name || !notification_iterator_next_method) { goto end; } @@ -135,7 +133,6 @@ struct bt_component_class *bt_component_class_source_create(const char *name, goto end; } - source_class->methods.iterator.get = notification_iterator_get_method; source_class->methods.iterator.next = notification_iterator_next_method; end: @@ -143,14 +140,12 @@ end: } struct bt_component_class *bt_component_class_filter_create(const char *name, - 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 || !notification_iterator_get_method || - !notification_iterator_next_method) { + if (!name || !notification_iterator_next_method) { goto end; } @@ -171,7 +166,6 @@ struct bt_component_class *bt_component_class_filter_create(const char *name, goto end; } - filter_class->methods.iterator.get = notification_iterator_get_method; filter_class->methods.iterator.next = notification_iterator_next_method; end: diff --git a/lib/component/iterator.c b/lib/component/iterator.c index 7f3e2b03..e2ffd2f0 100644 --- a/lib/component/iterator.c +++ b/lib/component/iterator.c @@ -77,6 +77,7 @@ void bt_notification_iterator_destroy(struct bt_object *obj) assert(0); } + BT_PUT(iterator->current_notification); BT_PUT(iterator->component); g_free(iterator); } @@ -159,42 +160,16 @@ end: struct bt_notification *bt_notification_iterator_get_notification( struct bt_notification_iterator *iterator) { - struct bt_private_notification_iterator *priv_iterator = - bt_private_notification_iterator_from_notification_iterator(iterator); - bt_component_class_notification_iterator_get_method get_method = NULL; - - assert(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); + struct bt_notification *notification = NULL; - assert(source_class->methods.iterator.get); - get_method = source_class->methods.iterator.get; - break; + if (!iterator) { + goto end; } - 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; - } + notification = bt_get(iterator->current_notification); - assert(get_method); - return get_method(priv_iterator); +end: + return notification; } enum bt_notification_iterator_status @@ -203,8 +178,15 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator) struct bt_private_notification_iterator *priv_iterator = bt_private_notification_iterator_from_notification_iterator(iterator); bt_component_class_notification_iterator_next_method next_method = NULL; + struct bt_notification_iterator_next_return next_return; + enum bt_notification_iterator_status status = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + + if (!iterator) { + status = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; + goto end; + } - assert(iterator); assert(iterator->component); assert(iterator->component->class); @@ -235,7 +217,19 @@ bt_notification_iterator_next(struct bt_notification_iterator *iterator) } assert(next_method); - return next_method(priv_iterator); + next_return = next_method(priv_iterator); + if (next_return.status == BT_NOTIFICATION_ITERATOR_STATUS_OK) { + if (!next_return.notification) { + status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + goto end; + } + + BT_MOVE(iterator->current_notification, + next_return.notification); + } + +end: + return next_return.status; } struct bt_component *bt_notification_iterator_get_component( diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index e05077ed..4fc939e5 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -439,13 +439,11 @@ enum bt_plugin_status bt_plugin_so_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.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.source.notif_iter_get, cc_full_descr->descriptor->methods.source.notif_iter_next); break; case BT_COMPONENT_CLASS_TYPE_SINK: diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index da7180b6..83e1a7e2 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -53,23 +53,9 @@ BT_HIDDEN bool ctf_fs_debug; -enum bt_notification_iterator_status ctf_fs_iterator_next( +struct bt_notification_iterator_next_return ctf_fs_iterator_next( struct bt_private_notification_iterator *iterator); -struct bt_notification *ctf_fs_iterator_get( - struct bt_private_notification_iterator *iterator) -{ - struct ctf_fs_iterator *ctf_it = - bt_private_notification_iterator_get_user_data( - iterator); - - if (!ctf_it->current_notification) { - (void) ctf_fs_iterator_next(iterator); - } - - return bt_get(ctf_it->current_notification); -} - static enum bt_notification_iterator_status ctf_fs_iterator_get_next_notification( struct ctf_fs_iterator *it, @@ -249,47 +235,49 @@ end: return ret; } -enum bt_notification_iterator_status ctf_fs_iterator_next( +struct bt_notification_iterator_next_return ctf_fs_iterator_next( struct bt_private_notification_iterator *iterator) { int heap_ret; struct bt_ctf_stream *stream = NULL; struct ctf_fs_stream *fs_stream; - struct bt_notification *notification; struct bt_notification *next_stream_notification; - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; struct ctf_fs_iterator *ctf_it = bt_private_notification_iterator_get_user_data( iterator); + struct bt_notification_iterator_next_return ret = { + .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, + .notification = NULL, + }; - notification = bt_notification_heap_pop(ctf_it->pending_notifications); - if (!notification && !ctf_it->pending_streams) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_END; + ret.notification = + bt_notification_heap_pop(ctf_it->pending_notifications); + if (!ret.notification && !ctf_it->pending_streams) { + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_END; goto end; } - if (!notification && ctf_it->pending_streams) { + if (!ret.notification && ctf_it->pending_streams) { /* * Insert at one notification per stream in the heap and pop * one. */ - ret = populate_heap(ctf_it); - if (ret) { + ret.status = populate_heap(ctf_it); + if (ret.status) { goto end; } - notification = bt_notification_heap_pop( + ret.notification = bt_notification_heap_pop( ctf_it->pending_notifications); - if (!notification) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_END; + if (!ret.notification) { + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_END; goto end; } } /* notification is set from here. */ - stream = internal_bt_notification_get_stream(notification); + stream = internal_bt_notification_get_stream(ret.notification); if (!stream) { /* * The current notification is not associated to a particular @@ -305,11 +293,12 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( goto end; } - ret = ctf_fs_iterator_get_next_notification(ctf_it, fs_stream, + ret.status = ctf_fs_iterator_get_next_notification(ctf_it, fs_stream, &next_stream_notification); - if ((ret && ret != BT_NOTIFICATION_ITERATOR_STATUS_END)) { + if ((ret.status && ret.status != BT_NOTIFICATION_ITERATOR_STATUS_END)) { heap_ret = bt_notification_heap_insert( - ctf_it->pending_notifications, notification); + ctf_it->pending_notifications, + ret.notification); assert(!next_stream_notification); if (heap_ret) { @@ -317,19 +306,19 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( * We're dropping the most recent notification, but at * this point, something is seriously wrong... */ - ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; } - BT_PUT(notification); + BT_PUT(ret.notification); goto end; } - if (ret == BT_NOTIFICATION_ITERATOR_STATUS_END) { + if (ret.status == BT_NOTIFICATION_ITERATOR_STATUS_END) { gboolean success; /* Remove stream. */ success = g_hash_table_remove(ctf_it->stream_ht, stream); assert(success); - ret = BT_NOTIFICATION_ITERATOR_STATUS_OK; + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_OK; } else { heap_ret = bt_notification_heap_insert(ctf_it->pending_notifications, next_stream_notification); @@ -338,7 +327,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( /* * We're dropping the most recent notification... */ - ret = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_NOMEM; } } @@ -348,7 +337,6 @@ enum bt_notification_iterator_status ctf_fs_iterator_next( * notification. */ end: - BT_MOVE(ctf_it->current_notification, notification); bt_put(stream); return ret; } @@ -359,7 +347,6 @@ void ctf_fs_iterator_destroy_data(struct ctf_fs_iterator *ctf_it) if (!ctf_it) { return; } - bt_put(ctf_it->current_notification); bt_put(ctf_it->pending_notifications); if (ctf_it->pending_streams) { g_ptr_array_free(ctf_it->pending_streams, TRUE); diff --git a/plugins/ctf/fs/fs.h b/plugins/ctf/fs/fs.h index 769ab705..9e03b013 100644 --- a/plugins/ctf/fs/fs.h +++ b/plugins/ctf/fs/fs.h @@ -81,7 +81,6 @@ struct ctf_fs_stream { struct ctf_fs_iterator { struct bt_notification_heap *pending_notifications; - struct bt_notification *current_notification; /* * struct ctf_fs_data_stream* which have not yet been associated to a * bt_ctf_stream. The association is performed on the first packet @@ -120,10 +119,7 @@ enum bt_notification_iterator_status ctf_fs_iterator_init( void ctf_fs_iterator_finalize(struct bt_private_notification_iterator *it); -enum bt_notification_iterator_status ctf_fs_iterator_next( - struct bt_private_notification_iterator *iterator); - -struct bt_notification *ctf_fs_iterator_get( +struct bt_notification_iterator_next_return ctf_fs_iterator_next( struct bt_private_notification_iterator *iterator); BT_HIDDEN diff --git a/plugins/ctf/lttng-live/lttng-live-internal.h b/plugins/ctf/lttng-live/lttng-live-internal.h index 61c3f190..a99f170d 100644 --- a/plugins/ctf/lttng-live/lttng-live-internal.h +++ b/plugins/ctf/lttng-live/lttng-live-internal.h @@ -37,11 +37,7 @@ enum bt_component_status lttng_live_init(struct bt_private_component *source, struct bt_value *params, void *init_method_data); BT_HIDDEN -struct bt_notification *lttng_live_iterator_get( - struct bt_private_notification_iterator *iterator); - -BT_HIDDEN -enum bt_notification_iterator_status lttng_live_iterator_next( +struct bt_notification_iterator_next_return lttng_live_iterator_next( struct bt_private_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 6b11e434..0c8b3c2b 100644 --- a/plugins/ctf/lttng-live/lttng-live.c +++ b/plugins/ctf/lttng-live/lttng-live.c @@ -38,10 +38,14 @@ struct bt_notification *lttng_live_iterator_get( } BT_HIDDEN -enum bt_notification_iterator_status lttng_live_iterator_next( +struct bt_notification_iterator_next_return lttng_live_iterator_next( struct bt_private_notification_iterator *iterator) { - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct bt_notification_iterator_next_return ret = { + .status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR, + }; + + return ret; } BT_HIDDEN diff --git a/plugins/ctf/plugin.c b/plugins/ctf/plugin.c index dc62e85d..6d483b1d 100644 --- a/plugins/ctf/plugin.c +++ b/plugins/ctf/plugin.c @@ -37,7 +37,7 @@ 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_get, ctf_fs_iterator_next); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(fs, 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_QUERY_METHOD(fs, ctf_fs_query); @@ -48,7 +48,7 @@ BT_PLUGIN_SOURCE_COMPONENT_CLASS_NOTIFICATION_ITERATOR_FINALIZE_METHOD(fs, ctf_fs_iterator_finalize); BT_PLUGIN_SOURCE_COMPONENT_CLASS_WITH_ID(auto, lttng_live, "lttng-live", - lttng_live_iterator_get, lttng_live_iterator_next); + 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 b0cdfe59..6fa10f38 100644 --- a/plugins/muxer/muxer.c +++ b/plugins/muxer/muxer.c @@ -86,17 +86,14 @@ error: } static -struct bt_notification *muxer_iterator_get( +struct bt_notification_iterator_next_return muxer_iterator_next( struct bt_private_notification_iterator *iterator) { - return NULL; -} + struct bt_notification_iterator_next_return ret = { + .status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR, + }; -static -enum bt_notification_iterator_status muxer_iterator_next( - struct bt_private_notification_iterator *iterator) -{ - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return ret; } /* Initialize plug-in entry points. */ @@ -104,8 +101,7 @@ 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_iterator_get, - muxer_iterator_next); +BT_PLUGIN_FILTER_COMPONENT_CLASS(muxer, 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/text/text.c b/plugins/text/text.c index a270fd48..04567368 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -194,31 +194,25 @@ enum bt_component_status run(struct bt_private_component *component) struct bt_notification_iterator *it; struct text_component *text = bt_private_component_get_user_data(component); + enum bt_notification_iterator_status it_ret; it = text->input_iterator; - if (likely(text->processed_first_event)) { - enum bt_notification_iterator_status it_ret; - - it_ret = bt_notification_iterator_next(it); - switch (it_ret) { - case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: - ret = BT_COMPONENT_STATUS_ERROR; - goto end; - case BT_NOTIFICATION_ITERATOR_STATUS_END: - ret = BT_COMPONENT_STATUS_END; - BT_PUT(text->input_iterator); - goto end; - default: - break; - } - } - notification = bt_notification_iterator_get_notification(it); - if (!notification) { + it_ret = bt_notification_iterator_next(it); + switch (it_ret) { + case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: ret = BT_COMPONENT_STATUS_ERROR; goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_COMPONENT_STATUS_END; + BT_PUT(text->input_iterator); + goto end; + default: + break; } + notification = bt_notification_iterator_get_notification(it); + assert(notification); ret = handle_notification(text, notification); text->processed_first_event = true; end: diff --git a/plugins/utils/plugin.c b/plugins/utils/plugin.c index 2934ad40..f621cc3e 100644 --- a/plugins/utils/plugin.c +++ b/plugins/utils/plugin.c @@ -39,8 +39,7 @@ BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(dummy, "Dummy sink component class: does absolutely nothing!"); /* trimmer filter */ -BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_get, - trimmer_iterator_next); +BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, 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); diff --git a/plugins/utils/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c index 24cdced1..d0a51a6f 100644 --- a/plugins/utils/trimmer/iterator.c +++ b/plugins/utils/trimmer/iterator.c @@ -57,7 +57,6 @@ void trimmer_iterator_finalize(struct bt_private_notification_iterator *it) it_data = bt_private_notification_iterator_get_user_data(it); assert(it_data); - bt_put(it_data->current_notification); bt_put(it_data->input_iterator); g_free(it_data); } @@ -105,27 +104,6 @@ end: return ret; } -BT_HIDDEN -struct bt_notification *trimmer_iterator_get( - struct bt_private_notification_iterator *iterator) -{ - struct trimmer_iterator *trim_it; - - trim_it = bt_private_notification_iterator_get_user_data(iterator); - assert(trim_it); - - if (!trim_it->current_notification) { - enum bt_notification_iterator_status it_ret; - - it_ret = trimmer_iterator_next(iterator); - if (it_ret) { - goto end; - } - } -end: - return bt_get(trim_it->current_notification); -} - static int update_lazy_bound(struct trimmer_bound *bound, const char *name, int64_t ts, bool *lazy_update) @@ -415,15 +393,17 @@ enum bt_notification_iterator_status evaluate_notification( } BT_HIDDEN -enum bt_notification_iterator_status trimmer_iterator_next( +struct bt_notification_iterator_next_return trimmer_iterator_next( struct bt_private_notification_iterator *iterator) { struct trimmer_iterator *trim_it = NULL; struct bt_private_component *component = NULL; struct trimmer *trimmer = NULL; struct bt_notification_iterator *source_it = NULL; - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; + struct bt_notification_iterator_next_return ret = { + .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, + .notification = NULL, + }; bool notification_in_range = false; trim_it = bt_private_notification_iterator_get_user_data(iterator); @@ -439,30 +419,26 @@ enum bt_notification_iterator_status trimmer_iterator_next( assert(source_it); while (!notification_in_range) { - struct bt_notification *notification; - - ret = bt_notification_iterator_next(source_it); - if (ret != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + ret.status = bt_notification_iterator_next(source_it); + if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { goto end; } - notification = bt_notification_iterator_get_notification( + ret.notification = bt_notification_iterator_get_notification( source_it); - if (!notification) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; + if (!ret.notification) { + ret.status = BT_NOTIFICATION_ITERATOR_STATUS_ERROR; goto end; } - ret = evaluate_notification(notification, + ret.status = evaluate_notification(ret.notification, &trimmer->begin, &trimmer->end, ¬ification_in_range); - if (notification_in_range) { - BT_MOVE(trim_it->current_notification, notification); - } else { - bt_put(notification); + if (!notification_in_range) { + bt_put(ret.notification); } - if (ret != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + if (ret.status != BT_NOTIFICATION_ITERATOR_STATUS_OK) { break; } } diff --git a/plugins/utils/trimmer/iterator.h b/plugins/utils/trimmer/iterator.h index cca226db..63b34e80 100644 --- a/plugins/utils/trimmer/iterator.h +++ b/plugins/utils/trimmer/iterator.h @@ -36,7 +36,6 @@ struct trimmer_iterator { /* Input iterator associated with this output iterator. */ struct bt_notification_iterator *input_iterator; - struct bt_notification *current_notification; }; BT_HIDDEN @@ -49,11 +48,7 @@ BT_HIDDEN void trimmer_iterator_finalize(struct bt_private_notification_iterator *it); BT_HIDDEN -struct bt_notification *trimmer_iterator_get( - struct bt_private_notification_iterator *iterator); - -BT_HIDDEN -enum bt_notification_iterator_status trimmer_iterator_next( +struct bt_notification_iterator_next_return trimmer_iterator_next( struct bt_private_notification_iterator *iterator); BT_HIDDEN diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index ba8dcba1..43acb8ad 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -40,16 +40,15 @@ static void dummy_iterator_finalize_method( { } -static struct bt_notification *dummy_iterator_get_method( +static struct bt_notification_iterator_next_return dummy_iterator_next_method( struct bt_private_notification_iterator *private_iterator) { - return NULL; -} + struct bt_notification_iterator_next_return next_return = { + .notification = NULL, + .status = BT_NOTIFICATION_ITERATOR_STATUS_OK, + }; -static enum bt_notification_iterator_status dummy_iterator_next_method( - struct bt_private_notification_iterator *private_iterator) -{ - return BT_NOTIFICATION_ITERATOR_STATUS_OK; + return next_return; } static enum bt_notification_iterator_status dummy_iterator_seek_time_method( @@ -80,8 +79,7 @@ BT_PLUGIN_AUTHOR("Janine Sutto"); BT_PLUGIN_LICENSE("Beerware"); BT_PLUGIN_VERSION(1, 2, 3, "yes"); -BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, dummy_iterator_get_method, - dummy_iterator_next_method); +BT_PLUGIN_SOURCE_COMPONENT_CLASS(source, 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); @@ -99,8 +97,7 @@ BT_PLUGIN_SINK_COMPONENT_CLASS_HELP(sink, "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n" ); -BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, dummy_iterator_get_method, - dummy_iterator_next_method); +BT_PLUGIN_FILTER_COMPONENT_CLASS(filter, 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); -- 2.34.1