Commit | Line | Data |
---|---|---|
bc37ae52 JG |
1 | #ifndef BABELTRACE_CTF_IR_TRACE_H |
2 | #define BABELTRACE_CTF_IR_TRACE_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Trace | |
6 | * | |
7 | * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
2e33ac5a | 33 | #include <babeltrace/ctf-ir/field-types.h> |
8bf65fbd | 34 | #include <babeltrace/ctf-ir/visitor.h> |
dac5c838 | 35 | #include <babeltrace/values.h> |
8bf65fbd | 36 | #include <babeltrace/plugin/notification/notification.h> |
410d0373 | 37 | #include <stdint.h> |
bc37ae52 JG |
38 | |
39 | #ifdef __cplusplus | |
40 | extern "C" { | |
41 | #endif | |
42 | ||
43 | struct bt_ctf_trace; | |
44 | struct bt_ctf_stream; | |
45 | struct bt_ctf_stream_class; | |
46 | struct bt_ctf_clock; | |
47 | ||
2204c381 | 48 | /** |
50ad4244 | 49 | * Trace modification handling function type. |
2204c381 | 50 | * |
50ad4244 | 51 | * Callback invoked whenever an element is added to a trace's hierachy. |
2204c381 | 52 | * |
50ad4244 | 53 | * @param element New element |
2204c381 JG |
54 | * @param data Handler private data |
55 | */ | |
50ad4244 JG |
56 | typedef void (*bt_ctf_listener_cb)( |
57 | struct bt_ctf_ir_element *element, void *data); | |
2204c381 | 58 | |
bc37ae52 JG |
59 | /* |
60 | * bt_ctf_trace_create: create a trace instance. | |
61 | * | |
d246b111 JG |
62 | * Allocate a new trace. |
63 | * | |
64 | * A trace's default packet header is a structure initialized with the following | |
65 | * fields: | |
66 | * - uint32_t magic | |
67 | * - uint8_t uuid[16] | |
68 | * - uint32_t stream_id | |
bc37ae52 JG |
69 | * |
70 | * Returns a new trace on success, NULL on error. | |
71 | */ | |
72 | extern struct bt_ctf_trace *bt_ctf_trace_create(void); | |
73 | ||
bc37ae52 | 74 | /* |
7f800dc7 | 75 | * bt_ctf_trace_set_environment_field: sets an environment field to the |
3487c9f3 | 76 | * trace. |
bc37ae52 | 77 | * |
7f800dc7 PP |
78 | * Sets an environment field to the trace. The name parameter is |
79 | * copied, whereas the value parameter's reference count is incremented | |
80 | * (if the function succeeds). | |
81 | * | |
82 | * If a value exists in the environment for the specified name, it is | |
83 | * replaced by the new value. | |
84 | * | |
dac5c838 PP |
85 | * The value parameter _must_ be either an integer value object or a |
86 | * string value object. Other object types are not supported. | |
7f800dc7 PP |
87 | * |
88 | * @param trace Trace instance. | |
89 | * @param name Name of the environment field (will be copied). | |
90 | * @param value Value of the environment field. | |
91 | * | |
92 | * Returns 0 on success, a negative value on error. | |
93 | */ | |
94 | extern int bt_ctf_trace_set_environment_field( | |
95 | struct bt_ctf_trace *trace, const char *name, | |
dac5c838 | 96 | struct bt_value *value); |
7f800dc7 PP |
97 | |
98 | /* | |
99 | * bt_ctf_trace_set_environment_field_string: sets a string environment | |
100 | * field to the trace. | |
101 | * | |
102 | * Sets a string environment field to the trace. This is a helper | |
103 | * function which corresponds to calling | |
104 | * bt_ctf_trace_set_environment_field() with a string object. | |
bc37ae52 JG |
105 | * |
106 | * @param trace Trace instance. | |
107 | * @param name Name of the environment field (will be copied). | |
108 | * @param value Value of the environment field (will be copied). | |
109 | * | |
110 | * Returns 0 on success, a negative value on error. | |
111 | */ | |
7f800dc7 PP |
112 | extern int bt_ctf_trace_set_environment_field_string( |
113 | struct bt_ctf_trace *trace, const char *name, | |
bc37ae52 JG |
114 | const char *value); |
115 | ||
3487c9f3 | 116 | /* |
7f800dc7 | 117 | * bt_ctf_trace_set_environment_field_integer: sets an integer environment |
3487c9f3 JG |
118 | * field to the trace. |
119 | * | |
7f800dc7 PP |
120 | * Sets an integer environment field to the trace. This is a helper |
121 | * function which corresponds to calling | |
122 | * bt_ctf_trace_set_environment_field() with an integer object. | |
3487c9f3 JG |
123 | * |
124 | * @param trace Trace instance. | |
125 | * @param name Name of the environment field (will be copied). | |
126 | * @param value Value of the environment field. | |
127 | * | |
128 | * Returns 0 on success, a negative value on error. | |
129 | */ | |
7f800dc7 | 130 | extern int bt_ctf_trace_set_environment_field_integer( |
3487c9f3 JG |
131 | struct bt_ctf_trace *trace, const char *name, |
132 | int64_t value); | |
133 | ||
e6fa2160 JG |
134 | /* |
135 | * bt_ctf_trace_get_environment_field_count: get environment field count. | |
136 | * | |
137 | * Get the trace's environment field count. | |
138 | * | |
139 | * @param trace Trace instance. | |
140 | * | |
141 | * Returns the environment field count, a negative value on error. | |
142 | */ | |
143 | extern int bt_ctf_trace_get_environment_field_count( | |
144 | struct bt_ctf_trace *trace); | |
145 | ||
e6fa2160 JG |
146 | /* |
147 | * bt_ctf_trace_get_environment_field_name: get environment field name. | |
148 | * | |
149 | * Get an environment field's name. The string's ownership is not | |
7f800dc7 PP |
150 | * transferred to the caller. The string data is valid as long as |
151 | * this trace's environment is not modified. | |
e6fa2160 JG |
152 | * |
153 | * @param trace Trace instance. | |
154 | * @param index Index of the environment field. | |
155 | * | |
156 | * Returns the environment field's name, NULL on error. | |
157 | */ | |
158 | extern const char * | |
159 | bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace, | |
160 | int index); | |
161 | ||
162 | /* | |
7f800dc7 PP |
163 | * bt_ctf_trace_get_environment_field_value: get environment |
164 | * field value (an object). | |
e6fa2160 | 165 | * |
7f800dc7 PP |
166 | * Get an environment field's value (an object). The returned object's |
167 | * reference count is incremented. When done with the object, the caller | |
dac5c838 | 168 | * must call bt_value_put() on it. |
e6fa2160 JG |
169 | * |
170 | * @param trace Trace instance. | |
171 | * @param index Index of the environment field. | |
172 | * | |
7f800dc7 | 173 | * Returns the environment field's object value, NULL on error. |
e6fa2160 | 174 | */ |
dac5c838 | 175 | extern struct bt_value * |
7f800dc7 | 176 | bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace *trace, |
e6fa2160 JG |
177 | int index); |
178 | ||
179 | /* | |
7f800dc7 PP |
180 | * bt_ctf_trace_get_environment_field_value_by_name: get environment |
181 | * field value (an object) by name. | |
e6fa2160 | 182 | * |
7f800dc7 PP |
183 | * Get an environment field's value (an object) by its field name. The |
184 | * returned object's reference count is incremented. When done with the | |
dac5c838 | 185 | * object, the caller must call bt_value_put() on it. |
e6fa2160 JG |
186 | * |
187 | * @param trace Trace instance. | |
7f800dc7 | 188 | * @param name Environment field's name |
e6fa2160 | 189 | * |
7f800dc7 | 190 | * Returns the environment field's object value, NULL on error. |
e6fa2160 | 191 | */ |
dac5c838 | 192 | extern struct bt_value * |
7f800dc7 PP |
193 | bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace *trace, |
194 | const char *name); | |
e6fa2160 | 195 | |
bc37ae52 JG |
196 | /* |
197 | * bt_ctf_trace_add_clock: add a clock to the trace. | |
198 | * | |
199 | * Add a clock to the trace. Clocks assigned to stream classes must be | |
200 | * added to the trace beforehand. | |
201 | * | |
202 | * @param trace Trace instance. | |
203 | * @param clock Clock to add to the trace. | |
204 | * | |
205 | * Returns 0 on success, a negative value on error. | |
206 | */ | |
207 | extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace, | |
208 | struct bt_ctf_clock *clock); | |
209 | ||
884cd6c3 JG |
210 | /* |
211 | * bt_ctf_trace_get_clock_count: get the number of clocks | |
ef0c4a15 | 212 | * associated with the trace. |
884cd6c3 JG |
213 | * |
214 | * @param trace Trace instance. | |
215 | * | |
216 | * Returns the clock count on success, a negative value on error. | |
217 | */ | |
218 | extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace); | |
219 | ||
220 | /* | |
221 | * bt_ctf_trace_get_clock: get a trace's clock at index. | |
222 | * | |
223 | * @param trace Trace instance. | |
224 | * @param index Index of the clock in the given trace. | |
225 | * | |
226 | * Return a clock instance on success, NULL on error. | |
227 | */ | |
228 | extern struct bt_ctf_clock *bt_ctf_trace_get_clock( | |
229 | struct bt_ctf_trace *trace, int index); | |
230 | ||
ef0c4a15 JG |
231 | /* |
232 | * bt_ctf_trace_add_stream_class: add a stream_class to the trace. | |
233 | * | |
234 | * Add a stream class to the trace. | |
235 | * | |
236 | * @param trace Trace instance. | |
237 | * @param stream_class Stream class to add to the trace. | |
238 | * | |
239 | * Returns 0 on success, a negative value on error. | |
240 | */ | |
241 | extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace, | |
242 | struct bt_ctf_stream_class *stream_class); | |
243 | ||
244 | /* | |
245 | * bt_ctf_trace_get_stream_class_count: get the number of stream classes | |
246 | * associated with the trace. | |
247 | * | |
248 | * @param trace Trace instance. | |
249 | * | |
250 | * Returns the stream class count on success, a negative value on error. | |
251 | */ | |
252 | extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace); | |
253 | ||
254 | /* | |
255 | * bt_ctf_trace_get_stream_class: get a trace's stream class at index. | |
256 | * | |
257 | * @param trace Trace instance. | |
258 | * @param index Index of the stream class in the given trace. | |
259 | * | |
260 | * Return a stream class on success, NULL on error. | |
261 | */ | |
262 | extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class( | |
263 | struct bt_ctf_trace *trace, int index); | |
264 | ||
4841ccc1 PP |
265 | /* |
266 | * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID. | |
267 | * | |
268 | * @param trace Trace instance. | |
269 | * @param index ID of the stream class in the given trace. | |
270 | * | |
271 | * Return a stream class on success, NULL on error. | |
272 | */ | |
273 | extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id( | |
274 | struct bt_ctf_trace *trace, uint32_t id); | |
275 | ||
7e4347a3 PP |
276 | /* |
277 | * bt_ctf_trace_get_clock_by_name: get a trace's clock by name | |
278 | * | |
279 | * @param trace Trace instance. | |
280 | * @param name Name of the clock in the given trace. | |
281 | * | |
282 | * Return a clock instance on success, NULL on error. | |
283 | */ | |
284 | extern struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name( | |
285 | struct bt_ctf_trace *trace, const char *name); | |
286 | ||
bc37ae52 JG |
287 | /* |
288 | * bt_ctf_trace_get_metadata_string: get metadata string. | |
289 | * | |
290 | * Get the trace's TSDL metadata. The caller assumes the ownership of the | |
291 | * returned string. | |
292 | * | |
293 | * @param trace Trace instance. | |
294 | * | |
295 | * Returns the metadata string on success, NULL on error. | |
296 | */ | |
297 | extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace); | |
298 | ||
299 | /* | |
4ed90fb3 JG |
300 | * bt_ctf_trace_get_byte_order: get a trace's byte order. |
301 | * | |
302 | * Get the trace's byte order. | |
303 | * | |
304 | * @param trace Trace instance. | |
305 | * | |
306 | * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error. | |
307 | */ | |
308 | extern enum bt_ctf_byte_order bt_ctf_trace_get_byte_order( | |
309 | struct bt_ctf_trace *trace); | |
310 | ||
311 | /* | |
312 | * bt_ctf_trace_set_byte_order: set a trace's byte order. | |
bc37ae52 | 313 | * |
c35a1669 | 314 | * Set the trace's byte order. Defaults to the current host's endianness. |
bc37ae52 JG |
315 | * |
316 | * @param trace Trace instance. | |
317 | * @param byte_order Trace's byte order. | |
318 | * | |
319 | * Returns 0 on success, a negative value on error. | |
c35a1669 JG |
320 | * |
321 | * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according | |
322 | * to the CTF specification, is defined as "the byte order described in the | |
323 | * trace description". | |
bc37ae52 JG |
324 | */ |
325 | extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace, | |
326 | enum bt_ctf_byte_order byte_order); | |
327 | ||
d246b111 JG |
328 | /* |
329 | * bt_ctf_trace_get_packet_header_type: get a trace's packet header type. | |
330 | * | |
331 | * Get the trace's packet header type. | |
332 | * | |
333 | * @param trace Trace instance. | |
334 | * | |
335 | * Returns the trace's packet header type (a structure) on success, NULL on | |
336 | * error. | |
337 | */ | |
338 | extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type( | |
339 | struct bt_ctf_trace *trace); | |
340 | ||
341 | /* | |
342 | * bt_ctf_trace_set_packet_header_type: set a trace's packet header type. | |
343 | * | |
344 | * Set the trace's packet header type. | |
345 | * | |
346 | * @param trace Trace instance. | |
347 | * @param packet_header_type Packet header field type (must be a structure). | |
348 | * | |
349 | * Returns 0 on success, a negative value on error. | |
350 | */ | |
351 | extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace, | |
352 | struct bt_ctf_field_type *packet_header_type); | |
353 | ||
8bf65fbd JG |
354 | /* |
355 | * bt_ctf_trace_visit: visit a trace's hierarchy. | |
356 | * | |
357 | * Recursively walk a trace's hierarchy and call visitor on each of its | |
358 | * elements. | |
359 | * | |
360 | * @param trace Trace instance. | |
361 | * @param visitor visitor function to invoke for each element. | |
362 | * @param data user data passed to the visitor. | |
363 | * | |
364 | * Returns 0 on success, a negative value on error. | |
365 | */ | |
366 | extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace, | |
367 | bt_ctf_ir_visitor visitor, void *data); | |
368 | ||
2204c381 | 369 | /* |
50ad4244 | 370 | * bt_ctf_trace_add_listener: add a trace modification listener |
2204c381 JG |
371 | * which will be invoked whenever a trace's schema is modified. |
372 | * | |
50ad4244 | 373 | * Register a modification listener to a trace. |
2204c381 JG |
374 | * |
375 | * @param trace Trace instance. | |
50ad4244 JG |
376 | * @param listener Callback to invoke on trace modification. |
377 | * @param listener_data Private data passed to the listener. | |
2204c381 JG |
378 | * |
379 | * Returns 0 on success, a negative value on error. | |
380 | * | |
50ad4244 | 381 | * Note: the listener will be used to serialize the trace's current |
2204c381 JG |
382 | * state on registration. It will then be invoked on any change occuring within |
383 | * the trace's hierarchy. | |
384 | */ | |
50ad4244 JG |
385 | extern int bt_ctf_trace_add_listener(struct bt_ctf_trace *trace, |
386 | bt_ctf_listener_cb listener, void *listener_data); | |
2204c381 | 387 | |
bc37ae52 JG |
388 | #ifdef __cplusplus |
389 | } | |
390 | #endif | |
391 | ||
392 | #endif /* BABELTRACE_CTF_IR_TRACE_H */ |