Add MIT-licensed priority heap, based on CLRS, chap. 6
[babeltrace.git] / converter / babeltrace-lib.c
CommitLineData
46322b33
MD
1/*
2 * babeltrace-lib.c
3 *
4 * Babeltrace Trace Converter Library
5 *
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19#include <stdlib.h>
20#include <errno.h>
21#include <stdio.h>
847bf71a 22#include <inttypes.h>
46322b33
MD
23#include <babeltrace/babeltrace.h>
24#include <babeltrace/format.h>
25#include <babeltrace/ctf/types.h>
26#include <babeltrace/ctf/metadata.h>
27#include <babeltrace/ctf-text/types.h>
28
46322b33 29static
847bf71a
MD
30int convert_stream(struct ctf_text_stream_pos *sout,
31 struct ctf_file_stream *sin)
46322b33
MD
32{
33 int ret;
34
35 /* For each event, print header, context, payload */
36 /* TODO: order events by timestamps across streams */
37 for (;;) {
764af3f4 38 ret = sin->pos.parent.event_cb(&sin->pos.parent, &sin->stream);
670977d3 39 if (ret == EOF)
46322b33
MD
40 break;
41 else if (ret) {
31262354
MD
42 fprintf(stdout, "[error] Reading event failed.\n");
43 goto error;
44 }
764af3f4 45 ret = sout->parent.event_cb(&sout->parent, &sin->stream);
31262354
MD
46 if (ret) {
47 fprintf(stdout, "[error] Writing event failed.\n");
46322b33
MD
48 goto error;
49 }
50 }
51
52 return 0;
53
54error:
55 return ret;
56}
57
847bf71a
MD
58int convert_trace(struct trace_descriptor *td_write,
59 struct trace_descriptor *td_read)
46322b33
MD
60{
61 struct ctf_trace *tin = container_of(td_read, struct ctf_trace, parent);
847bf71a
MD
62 struct ctf_text_stream_pos *sout =
63 container_of(td_write, struct ctf_text_stream_pos, trace_descriptor);
46322b33
MD
64 int stream_id, filenr;
65 int ret;
66
67 /* For each stream (TODO: order events by timestamp) */
68 for (stream_id = 0; stream_id < tin->streams->len; stream_id++) {
aa6bffae 69 struct ctf_stream_class *stream = g_ptr_array_index(tin->streams, stream_id);
46322b33
MD
70
71 if (!stream)
72 continue;
73 for (filenr = 0; filenr < stream->files->len; filenr++) {
74 struct ctf_file_stream *file_stream = g_ptr_array_index(stream->files, filenr);
847bf71a 75 ret = convert_stream(sout, file_stream);
46322b33
MD
76 if (ret) {
77 fprintf(stdout, "[error] Printing stream %d failed.\n", stream_id);
78 goto error;
79 }
80 }
81 }
82
83 return 0;
84
85error:
86 return ret;
87}
This page took 0.026522 seconds and 4 git commands to generate.