[ltt-dev] [BABELTRACE PATCH] Set the position when creating the iterator
Julien Desfossez
julien.desfossez at polymtl.ca
Sun Aug 28 13:02:39 EDT 2011
Allow the user to seek in the file stream when the iterator is created.
For now we only support to stay on the current position or seek at the
beginning.
Signed-off-by: Julien Desfossez <julien.desfossez at polymtl.ca>
---
converter/babeltrace-lib.c | 18 ++++++++++++++++--
include/babeltrace/babeltrace.h | 3 ++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/converter/babeltrace-lib.c b/converter/babeltrace-lib.c
index ee34d28..bd8033f 100644
--- a/converter/babeltrace-lib.c
+++ b/converter/babeltrace-lib.c
@@ -79,7 +79,8 @@ int stream_compare(void *a, void *b)
return 0;
}
-struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc)
+struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc,
+ int whence, size_t offset)
{
int i, stream_id;
int ret = 0;
@@ -118,6 +119,19 @@ struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc)
file_stream = g_ptr_array_index(stream->streams,
filenr);
+ switch (whence) {
+ case SEEK_CUR:
+ break;
+ case SEEK_SET:
+ assert(offset == 0); /* only seek supported for now */
+ file_stream->pos.cur_index = 0;
+ file_stream->pos.offset = 0;
+ file_stream->pos.content_size = 0;
+ break;
+ default:
+ assert(0);
+ }
+
ret = stream_read_event(file_stream);
if (ret == EOF) {
ret = 0;
@@ -211,7 +225,7 @@ int convert_trace(struct trace_descriptor *td_write,
sout = container_of(td_write, struct ctf_text_stream_pos,
trace_descriptor);
- iter = babeltrace_iter_create(trace_collection_read);
+ iter = babeltrace_iter_create(trace_collection_read, SEEK_CUR, 0);
while (babeltrace_iter_read_event(iter, &stream, &event) == 0) {
ret = sout->parent.event_cb(&sout->parent, stream);
if (ret) {
diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h
index c8b0581..9a69fd0 100644
--- a/include/babeltrace/babeltrace.h
+++ b/include/babeltrace/babeltrace.h
@@ -28,7 +28,8 @@ struct ctf_stream;
/*
* babeltrace_iter_create - Allocate a trace collection iterator.
*/
-struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc);
+struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc,
+ int whence, size_t offset);
/*
* babeltrace_iter_destroy - Free a trace collection iterator.
--
1.7.4.1
More information about the lttng-dev
mailing list