Fix parallel build for lib/
[babeltrace.git] / include / babeltrace / babeltrace.h
CommitLineData
34ac0e6c
MD
1#ifndef _BABELTRACE_H
2#define _BABELTRACE_H
3
70bd0a12
JD
4/*
5 * BabelTrace API
6 *
7 * Copyright 2010-2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 */
847bf71a 19
c34ccddd 20#include <glib.h>
fd2740e3 21#include <stdint.h>
0ec662bd 22#include <babeltrace/format.h>
c34ccddd
MD
23
24typedef GQuark bt_event_name;
25
70bd0a12
JD
26/* Forward declarations */
27struct babeltrace_iter;
70bd0a12
JD
28struct trace_collection;
29struct ctf_stream_event;
30struct ctf_stream;
063f7048 31struct babeltrace_saved_pos;
c34ccddd
MD
32struct bt_dependencies;
33
34enum bt_cb_ret {
35 BT_CB_OK = 0,
36 BT_CB_OK_STOP = 1,
37 BT_CB_ERROR_STOP = 2,
38 BT_CB_ERROR_CONTINUE = 3,
39};
063f7048
MD
40
41struct trace_collection_pos {
42 enum {
43 BT_SEEK_TIME, /* uses u.seek_time */
44 BT_SEEK_RESTORE, /* uses u.restore */
45 BT_SEEK_CUR,
46 BT_SEEK_BEGIN,
47 BT_SEEK_END,
48 } type;
49 union {
50 uint64_t seek_time;
51 struct babeltrace_saved_pos *restore;
52 } u;
53};
34ac0e6c 54
e73cc54c
JD
55struct bt_ctf_data {
56 struct ctf_stream_event *event;
f970ae1d 57 struct ctf_stream *stream;
e73cc54c
JD
58};
59
70bd0a12
JD
60/*
61 * babeltrace_iter_create - Allocate a trace collection iterator.
063f7048
MD
62 *
63 * begin_pos and end_pos are optional parameters to specify the position
64 * at which the trace collection should be seeked upon iterator
65 * creation, and the position at which iteration will start returning
66 * "EOF".
67 *
68 * By default, if begin_pos is NULL, a BT_SEEK_CUR is performed at
69 * creation. By default, if end_pos is NULL, a BT_SEEK_END (end of
70 * trace) is the EOF criterion.
70bd0a12 71 */
063f7048
MD
72struct babeltrace_iter *babeltrace_iter_create(struct trace_collection *tc,
73 struct trace_collection_pos *begin_pos,
74 struct trace_collection_pos *end_pos);
34ac0e6c 75
70bd0a12
JD
76/*
77 * babeltrace_iter_destroy - Free a trace collection iterator.
78 */
79void babeltrace_iter_destroy(struct babeltrace_iter *iter);
34ac0e6c 80
70bd0a12
JD
81/*
82 * babeltrace_iter_next: Move trace collection position to the next event.
83 *
84 * Returns 0 on success, a negative value on error
85 */
86int babeltrace_iter_next(struct babeltrace_iter *iter);
46322b33 87
70bd0a12 88/*
063f7048 89 * babeltrace_iter_save_pos - Save the current trace collection position.
70bd0a12
JD
90 *
91 * The position returned by this function needs to be freed by
92 * babeltrace_iter_free_pos after use.
93 */
063f7048
MD
94struct trace_collection_pos *
95 babeltrace_iter_save_pos(struct babeltrace_iter *iter);
46322b33 96
70bd0a12
JD
97/*
98 * babeltrace_iter_free_pos - Free the position.
99 */
063f7048 100void babeltrace_iter_free_pos(struct trace_collection_pos *pos);
70bd0a12
JD
101
102/*
063f7048 103 * babeltrace_iter_seek: seek iterator to given position.
70bd0a12 104 *
063f7048 105 * Return EOF if position is after the last event of the trace collection.
70bd0a12
JD
106 * Return other negative value for other errors.
107 * Return 0 for success.
108 */
063f7048
MD
109int babeltrace_iter_seek(struct babeltrace_iter *iter,
110 const struct trace_collection_pos *pos);
70bd0a12
JD
111
112/*
113 * babeltrace_iter_read_event: Read the iterator's current event data.
114 *
115 * @iter: trace collection iterator (input)
116 * @stream: stream containing event at current position (output)
117 * @event: current event (output)
118 * Return 0 on success, negative error value on error.
119 */
120int babeltrace_iter_read_event(struct babeltrace_iter *iter,
121 struct ctf_stream **stream,
122 struct ctf_stream_event **event);
123
c34ccddd
MD
124/*
125 * Receives a variable number of strings as parameter, ended with NULL.
126 */
127struct bt_dependencies *babeltrace_dependencies_create(const char *first, ...);
128
129/*
130 * struct bt_dependencies must be destroyed explicitly if not passed as
131 * parameter to a babeltrace_iter_add_callback().
132 */
133void babeltrace_dependencies_destroy(struct bt_dependencies *dep);
134
135/*
136 * babeltrace_iter_add_callback: Add a callback to iterator.
137 *
138 * @iter: trace collection iterator (input)
139 * @event: event to target. 0 for all events.
140 * @private_data: private data pointer to pass to the callback
141 * @flags: specific flags controlling the behavior of this callback
142 * (or'd).
143 *
144 * @callback: function pointer to call
145 * @depends: struct bt_dependency detailing the required computation results.
146 * Ends with 0.
147 * @weak_depends: struct bt_dependency detailing the optional computation
148 * results that can be optionally consumed by this
149 * callback.
150 * @provides: struct bt_dependency detailing the computation results
151 * provided by this callback.
152 * Ends with 0.
153 *
154 * "depends", "weak_depends" and "provides" memory is handled by the
155 * babeltrace library after this call succeeds or fails. These objects
156 * can still be used by the caller until the babeltrace iterator is
157 * destroyed, but they belong to the babeltrace library.
158 *
159 * (note to implementor: we need to keep a gptrarray of struct
160 * bt_dependencies to "garbage collect" in struct babeltrace_iter, and
161 * dependencies need to have a refcount to handle the case where they
162 * would be passed to more than one iterator. Upon iterator detroy, we
163 * iterate on all the gc ptrarray and decrement the refcounts, freeing
164 * if we reach 0.)
165 * (note to implementor: we calculate the dependency graph when
166 * babeltrace_iter_read_event() is executed after a
167 * babeltrace_iter_add_callback(). Beware that it is valid to create/add
168 * callbacks/read/add more callbacks/read some more.)
169 */
170int babeltrace_iter_add_callback(struct babeltrace_iter *iter,
171 bt_event_name event, void *private_data, int flags,
e73cc54c
JD
172 enum bt_cb_ret (*callback)(struct bt_ctf_data *ctf_data,
173 void *caller_data),
c34ccddd
MD
174 struct bt_dependencies *depends,
175 struct bt_dependencies *weak_depends,
176 struct bt_dependencies *provides);
177
178/*
179 * For flags parameter above.
180 */
181enum {
182 BT_FLAGS_FREE_PRIVATE_DATA = (1 << 0),
183};
184
70bd0a12 185#endif /* _BABELTRACE_H */
This page took 0.030601 seconds and 4 git commands to generate.