API fix: packet_seek should take an index rather than offset
[babeltrace.git] / lib / callbacks.c
index ec6edba80ba76bf434e50964d1f51aba5c6f81aa..fa212c9191e95fc5f5371201bf7883d22d9df05e 100644 (file)
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/callbacks-internal.h>
+#include <babeltrace/context.h>
+#include <babeltrace/context-internal.h>
 #include <babeltrace/ctf-ir/metadata.h>
 #include <babeltrace/iterator-internal.h>
+#include <babeltrace/ctf/events.h>
 #include <inttypes.h>
 
 static
@@ -56,11 +59,11 @@ struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...)
 }
 
 /*
- * babeltrace_iter_add_callback: Add a callback to iterator.
+ * bt_iter_add_callback: Add a callback to iterator.
  */
-int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
-               bt_event_name event, void *private_data, int flags,
-               enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data,
+int bt_iter_add_callback(struct bt_iter *iter,
+               bt_intern_str event, void *private_data, int flags,
+               enum bt_cb_ret (*callback)(struct bt_ctf_event *ctf_data,
                                           void *private_data),
                struct bt_dependencies *depends,
                struct bt_dependencies *weak_depends,
@@ -69,7 +72,7 @@ int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
        int i, stream_id;
        gpointer *event_id_ptr;
        unsigned long event_id;
-       struct trace_collection *tc = iter->tc;
+       struct trace_collection *tc = iter->ctx->tc;
 
        for (i = 0; i < tc->array->len; i++) {
                struct ctf_trace *tin;
@@ -102,7 +105,7 @@ int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
                                                (gconstpointer) (unsigned long) event);
                                /* event not found in this stream class */
                                if (!event_id_ptr) {
-                                       printf("event not found\n");
+                                       fprintf(stderr, "event not found\n");
                                        continue;
                                }
                                event_id = (uint64_t)(unsigned long) *event_id_ptr;
@@ -150,24 +153,24 @@ struct ctf_stream_event *extract_ctf_stream_event(struct ctf_stream *stream)
        uint64_t id = stream->event_id;
 
        if (id >= stream_class->events_by_id->len) {
-               fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
+               fprintf(stderr, "[error] Event id %" PRIu64 " is outside range.\n", id);
                return NULL;
        }
        event = g_ptr_array_index(stream->events_by_id, id);
        if (!event) {
-               fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
                return NULL;
        }
        event_class = g_ptr_array_index(stream_class->events_by_id, id);
        if (!event_class) {
-               fprintf(stdout, "[error] Event id %" PRIu64 " is unknown.\n", id);
+               fprintf(stderr, "[error] Event id %" PRIu64 " is unknown.\n", id);
                return NULL;
        }
 
        return event;
 }
 
-void process_callbacks(struct babeltrace_iter *iter,
+void process_callbacks(struct bt_iter *iter,
                       struct ctf_stream *stream)
 {
        struct bt_stream_callbacks *bt_stream_cb;
@@ -175,7 +178,7 @@ void process_callbacks(struct babeltrace_iter *iter,
        struct bt_callback *cb;
        int i;
        enum bt_cb_ret ret;
-       struct bt_ctf_data ctf_data;
+       struct bt_ctf_event ctf_data;
 
        ctf_data.event = extract_ctf_stream_event(stream);
        ctf_data.stream = stream;
@@ -203,7 +206,7 @@ void process_callbacks(struct babeltrace_iter *iter,
        if (!bt_stream_cb || !bt_stream_cb->per_id_callbacks)
                goto end;
 
-       if (stream->event_id > bt_stream_cb->per_id_callbacks->len)
+       if (stream->event_id >= bt_stream_cb->per_id_callbacks->len)
                goto end;
        bt_chain = &g_array_index(bt_stream_cb->per_id_callbacks,
                        struct bt_callback_chain, stream->event_id);
This page took 0.024041 seconds and 4 git commands to generate.