From f48bc732c2d473f25e9719d9ee72717593c12ae8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 11 Dec 2016 03:49:34 -0500 Subject: [PATCH] Component iterator points to first notification on creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- plugins/ctf/fs/fs.c | 9 +++++++++ plugins/text/text.c | 19 +++++++++++++------ plugins/text/text.h | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/plugins/ctf/fs/fs.c b/plugins/ctf/fs/fs.c index 9ddff2a3..3a60b0d5 100644 --- a/plugins/ctf/fs/fs.c +++ b/plugins/ctf/fs/fs.c @@ -49,6 +49,10 @@ 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) @@ -56,6 +60,10 @@ struct bt_notification *ctf_fs_iterator_get( struct ctf_fs_iterator *ctf_it = bt_notification_iterator_get_private_data(iterator); + if (!ctf_it->current_notification) { + (void) ctf_fs_iterator_next(iterator); + } + return bt_get(ctf_it->current_notification); } @@ -633,6 +641,7 @@ enum bt_component_status ctf_fs_iterator_init(struct bt_component *source, if (ret) { goto error; } + end: return ret; error: diff --git a/plugins/text/text.c b/plugins/text/text.c index 89fa5990..6781b1b6 100644 --- a/plugins/text/text.c +++ b/plugins/text/text.c @@ -164,15 +164,21 @@ enum bt_component_status run(struct bt_component *component) goto end; } - if (!text->processed_first_event) { - ret = bt_notification_iterator_next(it); - if (ret != BT_COMPONENT_STATUS_OK) { + 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; goto end; + default: + break; } - } else { - text->processed_first_event = true; } - notification = bt_notification_iterator_get_notification(it); if (!notification) { ret = BT_COMPONENT_STATUS_ERROR; @@ -180,6 +186,7 @@ enum bt_component_status run(struct bt_component *component) } ret = handle_notification(text, notification); + text->processed_first_event = true; end: bt_put(it); bt_put(notification); diff --git a/plugins/text/text.h b/plugins/text/text.h index 5697e2ee..ef80ce3e 100644 --- a/plugins/text/text.h +++ b/plugins/text/text.h @@ -69,7 +69,7 @@ struct text_options { struct text_component { struct text_options options; FILE *out, *err; - bool processed_first_event; + bool processed_first_event; /* Should be per-iterator. */ int depth; /* nesting, used for tabulation alignment. */ bool start_line; GString *string; -- 2.34.1