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