From 12b0fa5148594fecfeb84e1ec10b6740ed9c09a6 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 19 Feb 2019 11:59:26 -0500 Subject: [PATCH] src.text.dmesg: implement "seek beginning" and "can seek beginning" methods It is possible to make a `src.text.dmesg` message iterator seek its beginning when it's reading a file, not the standard input. Its "can seek beginning" method indicates this. Signed-off-by: Philippe Proulx --- plugins/text/dmesg/dmesg.c | 28 ++++++++++++++++++++++++++++ plugins/text/dmesg/dmesg.h | 8 ++++++++ plugins/text/plugin.c | 4 ++++ 3 files changed, 40 insertions(+) diff --git a/plugins/text/dmesg/dmesg.c b/plugins/text/dmesg/dmesg.c index 90d1d634..29cef2f5 100644 --- a/plugins/text/dmesg/dmesg.c +++ b/plugins/text/dmesg/dmesg.c @@ -647,6 +647,8 @@ void destroy_dmesg_msg_iter(struct dmesg_msg_iter *dmesg_msg_iter) g_free(dmesg_msg_iter); } + + BT_HIDDEN bt_self_message_iterator_status dmesg_msg_iter_init( bt_self_message_iterator *self_msg_iter, @@ -897,3 +899,29 @@ bt_self_message_iterator_status dmesg_msg_iter_next( return status; } + +BT_HIDDEN +bt_bool dmesg_msg_iter_can_seek_beginning( + bt_self_message_iterator *self_msg_iter) +{ + struct dmesg_msg_iter *dmesg_msg_iter = + bt_self_message_iterator_get_data(self_msg_iter); + + /* Can't seek the beginning of the standard input stream */ + return !dmesg_msg_iter->dmesg_comp->params.read_from_stdin; +} + +BT_HIDDEN +bt_self_message_iterator_status dmesg_msg_iter_seek_beginning( + bt_self_message_iterator *self_msg_iter) +{ + struct dmesg_msg_iter *dmesg_msg_iter = + bt_self_message_iterator_get_data(self_msg_iter); + + BT_ASSERT(!dmesg_msg_iter->dmesg_comp->params.read_from_stdin); + + BT_MESSAGE_PUT_REF_AND_RESET(dmesg_msg_iter->tmp_event_msg); + dmesg_msg_iter->last_clock_value = 0; + dmesg_msg_iter->state = STATE_EMIT_STREAM_BEGINNING; + return BT_SELF_MESSAGE_ITERATOR_STATUS_OK; +} diff --git a/plugins/text/dmesg/dmesg.h b/plugins/text/dmesg/dmesg.h index 73d26d2f..f93eeaf3 100644 --- a/plugins/text/dmesg/dmesg.h +++ b/plugins/text/dmesg/dmesg.h @@ -51,4 +51,12 @@ bt_self_message_iterator_status dmesg_msg_iter_next( bt_message_array_const msgs, uint64_t capacity, uint64_t *count); +BT_HIDDEN +bt_bool dmesg_msg_iter_can_seek_beginning( + bt_self_message_iterator *message_iterator); + +BT_HIDDEN +bt_self_message_iterator_status dmesg_msg_iter_seek_beginning( + bt_self_message_iterator *message_iterator); + #endif /* BABELTRACE_PLUGIN_TEXT_DMESG_DMESG_H */ diff --git a/plugins/text/plugin.c b/plugins/text/plugin.c index 41da4395..55507de5 100644 --- a/plugins/text/plugin.c +++ b/plugins/text/plugin.c @@ -52,3 +52,7 @@ BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD(dmesg, dmesg_msg_iter_init); BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_FINALIZE_METHOD(dmesg, dmesg_msg_iter_finalize); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD(dmesg, + dmesg_msg_iter_seek_beginning); +BT_PLUGIN_SOURCE_COMPONENT_CLASS_MESSAGE_ITERATOR_CAN_SEEK_BEGINNING_METHOD(dmesg, + dmesg_msg_iter_can_seek_beginning); -- 2.34.1