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