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