Remove the need to implement the notification iterator's "get" method
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 28 Mar 2017 23:57:34 +0000 (19:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:39 +0000 (12:57 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
21 files changed:
include/babeltrace/component/component-class-filter.h
include/babeltrace/component/component-class-internal.h
include/babeltrace/component/component-class-source.h
include/babeltrace/component/component-class.h
include/babeltrace/component/notification/iterator-internal.h
include/babeltrace/component/notification/iterator.h
include/babeltrace/plugin/plugin-dev.h
lib/component/component-class.c
lib/component/iterator.c
lib/plugin/plugin-so.c
plugins/ctf/fs/fs.c
plugins/ctf/fs/fs.h
plugins/ctf/lttng-live/lttng-live-internal.h
plugins/ctf/lttng-live/lttng-live.c
plugins/ctf/plugin.c
plugins/muxer/muxer.c
plugins/text/text.c
plugins/utils/plugin.c
plugins/utils/trimmer/iterator.c
plugins/utils/trimmer/iterator.h
tests/lib/test-plugin-plugins/sfs.c

index be44271e9b70f1e578bc695b000b42c2e5e6f2bf..60ed0f7c45dd9065c55cf238fde08f335ab523df 100644 (file)
@@ -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
index 6aed6f0b026c8fb8ae4ad9aada986267f6a3f433..1cafef640b27b2e5a23cb537bb1129864b063ea2 100644 (file)
@@ -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;
 };
index beaaa878f4f5b9463b823c8d3ad471a215f97f8d..a6de3ae5d7fc8d56f6349d138a9bd332146c0802 100644 (file)
@@ -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
index 29b66ecb17209866ad36092690e3695a0b8be5e9..ea95f4e068a8fe794281583b274ed2765683412e 100644 (file)
@@ -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
index 99e9617ca06505f68bdad4b75c245a446c92fb48..b1300f038e2d67b76375000ed847b66a98c352c2 100644 (file)
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/object-internal.h>
 #include <babeltrace/ref-internal.h>
+#include <babeltrace/component/notification/notification.h>
 #include <babeltrace/component/notification/iterator.h>
 #include <babeltrace/component/notification/private-iterator.h>
 
 struct bt_notification_iterator {
        struct bt_object base;
        struct bt_component *component;
+       struct bt_notification *current_notification;
        void *user_data;
 };
 
index bc226e131b63b58b84b9b6187338f90d635c0151..8cf2a0626c38484e481fcfd0aa81abacdda6b2d1 100644 (file)
@@ -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.
  *
index d8d0281509600896b0cf211501cc7a196ced115b..5221b974ce6711738701260ad1434cf0aedce410 100644 (file)
@@ -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
index 0f5337257c4810fada3ca18272db7182bb129b0e..f3cbb4222fdb8e4507877b1254278915e6f4d33b 100644 (file)
@@ -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:
index 7f3e2b037affd431b3716cc2d187778d5dda9361..e2ffd2f017c098bfe7bc378b0a5b127a728570ee 100644 (file)
@@ -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(
index e05077ed090194bf0fd3e2016211173f4df7c4a5..4fc939e5b13cfb182ed7960e01b2c8c58856c62c 100644 (file)
@@ -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:
index da7180b6f011d8fbd909ab3febaeebb06da76f4e..83e1a7e29487b52f1329295dd1db6cd5cb39f41a 100644 (file)
 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);
index 769ab70563c79492e5aeb21797ba772b3fdf1e87..9e03b013acc00a49dc3f1eb2ccec5ec6b15f5aa1 100644 (file)
@@ -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
index 61c3f19063a6e84a1283e5b0f37c3597a2933a0c..a99f170d3e8b741e96cb05c128042a88201adb1d 100644 (file)
@@ -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 */
index 6b11e434714cd4b55a796d02fc1fed61ba8979ce..0c8b3c2b63b8ac187d09443288992570a33a6437 100644 (file)
@@ -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
index dc62e85d2ef16e503aa42f18bbbf57b4f0c58e8b..6d483b1de7f08c4680f0aad99038394be22d4f48 100644 (file)
@@ -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,
index b0cdfe5922a1e53d0265b370e55dd29be6ab4f4e..6fa10f3844f5bd41acf4a38f242d2ace1eb3eae8 100644 (file)
@@ -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);
index a270fd4820ad046c62e2529a8a452ca457a7b3bf..045673686b6361846c662f40b28fc8121e1e553b 100644 (file)
@@ -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:
index 2934ad408eb5f1d0b3be27db812aac19ecd5b52f..f621cc3e1694d5558b2a0b221a8610d557f7bbb5 100644 (file)
@@ -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);
index 24cdced1c0d26b930de1a25d74e122e02de6302f..d0a51a6f9b46e4c30a9375b69c6ffdafe7b0f260 100644 (file)
@@ -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,
                                &notification_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;
                }
        }
index cca226db9b17fd79c518e04d66f1b651a76ebab7..63b34e808d10a7e65b5804dbbfb0649599f6413e 100644 (file)
@@ -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
index ba8dcba1a979785cb95b5224310e4f5793f55c8f..43acb8adfc71dbcc334dfee4b66aa6667945d9a2 100644 (file)
@@ -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);
This page took 0.039887 seconds and 4 git commands to generate.