#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
+#include <inttypes.h>
#include <babeltrace/babeltrace.h>
#include <babeltrace/format.h>
#include <babeltrace/ctf/types.h>
#include <babeltrace/ctf-text/types.h>
static
-int print_event(struct format *fmt_write, struct ctf_text_stream_pos *sout,
- struct format *fmt_read, struct ctf_file_stream *sin)
-{
- struct ctf_stream *stream_class = sin->stream;
- struct ctf_event *event_class;
- uint64_t id = 0;
- int len_index;
-
- /* Read and print event header */
- if (stream_class->event_header) {
- fmt_read->struct_read(&sin->pos.parent, stream_class->event_header);
-
- /* lookup event id */
- len_index = struct_declaration_lookup_field_index(td->packet_header->declaration,
- g_quark_from_static_string("id"));
- if (len_index >= 0) {
- struct definition_integer *defint;
- struct field *field;
-
- field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
- assert(field->definition->declaration->id == CTF_TYPE_INTEGER);
- defint = container_of(field->definition, struct definition_integer, p);
- assert(defint->declaration->signedness == FALSE);
- id = defint->value._unsigned; /* set id */
- }
-
- fmt_write->struct_write(&sout->parent, stream_class->event_header);
- }
-
- /* Read and print stream-declared event context */
- if (stream_class->event_context) {
- fmt_read->struct_read(&sin->pos.parent, stream_class->event_context);
- fmt_write->struct_write(&sout->parent, stream_class->event_context);
- }
-
- if (id >= stream_class->events_by_id->len) {
- fprintf(stdout, "[error] Event id %" PRIu64 " is outside range.\n", id);
- return -EINVAL;
- }
- 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);
- return -EINVAL;
- }
-
- /* Read and print event-declared event context */
- if (event_class->context) {
- fmt_read->struct_read(&sin->pos.parent, event_class->context);
- fmt_write->struct_write(&sout->parent, event_class->context);
- }
-
- /* Read and print event payload */
- if (event_class->fields) {
- fmt_read->struct_read(&sin->pos.parent, event_class->fields);
- fmt_write->struct_write(&sout->parent, event_class->fields);
- }
-
- return 0;
-}
-
-static
-int print_stream(struct format *fmt_write, struct ctf_text_stream_pos *sout,
- struct format *fmt_read, struct ctf_file_stream *sin)
+int convert_stream(struct ctf_text_stream_pos *sout,
+ struct ctf_file_stream *sin)
{
int ret;
/* For each event, print header, context, payload */
/* TODO: order events by timestamps across streams */
for (;;) {
- ret = print_event(fmt_write, sout, fmt_read, sin);
- if (ret == -EOF)
+ ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->stream);
+ if (ret == EOF)
break;
else if (ret) {
- fprintf(stdout, "[error] Printing event failed.\n");
+ fprintf(stdout, "[error] Reading event failed.\n");
+ goto error;
+ }
+ ret = sout->parent.event_cb(&sout->parent, &sin->stream);
+ if (ret) {
+ fprintf(stdout, "[error] Writing event failed.\n");
goto error;
}
}
return ret;
}
-int print_trace(struct format *fmt_write,
- struct trace_descriptor *td_write,
- struct format *fmt_read,
- struct trace_descriptor *td_read)
+int convert_trace(struct trace_descriptor *td_write,
+ struct trace_descriptor *td_read)
{
struct ctf_trace *tin = container_of(td_read, struct ctf_trace, parent);
- struct ctf_text_stream_pos *sout = container_of(td_write, struct ctf_text_stream_pos, parent);
+ struct ctf_text_stream_pos *sout =
+ container_of(td_write, struct ctf_text_stream_pos, trace_descriptor);
int stream_id, filenr;
int ret;
/* For each stream (TODO: order events by timestamp) */
for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
- struct ctf_stream *stream = g_ptr_array_index(tin->streams, stream_id);
+ struct ctf_stream_class *stream = g_ptr_array_index(tin->streams, stream_id);
if (!stream)
continue;
for (filenr = 0; filenr < stream->files->len; filenr++) {
struct ctf_file_stream *file_stream = g_ptr_array_index(stream->files, filenr);
- ret = print_stream(fmt_write, sout, fmt_read, file_stream);
+ ret = convert_stream(sout, file_stream);
if (ret) {
fprintf(stdout, "[error] Printing stream %d failed.\n", stream_id);
goto error;