Document packet.h (API)
[babeltrace.git] / include / babeltrace / ctf-ir / trace.h
CommitLineData
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
40extern "C" {
41#endif
42
43struct bt_ctf_trace;
44struct bt_ctf_stream;
45struct bt_ctf_stream_class;
46struct 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
56typedef 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 */
72extern struct bt_ctf_trace *bt_ctf_trace_create(void);
73
e96045d4
JG
74extern const char *bt_ctf_trace_get_name(struct bt_ctf_trace *trace);
75
76extern int bt_ctf_trace_set_name(struct bt_ctf_trace *trace, const char *name);
77
bc37ae52 78/*
7f800dc7 79 * bt_ctf_trace_set_environment_field: sets an environment field to the
3487c9f3 80 * trace.
bc37ae52 81 *
7f800dc7
PP
82 * Sets an environment field to the trace. The name parameter is
83 * copied, whereas the value parameter's reference count is incremented
84 * (if the function succeeds).
85 *
86 * If a value exists in the environment for the specified name, it is
87 * replaced by the new value.
88 *
dac5c838
PP
89 * The value parameter _must_ be either an integer value object or a
90 * string value object. Other object types are not supported.
7f800dc7
PP
91 *
92 * @param trace Trace instance.
93 * @param name Name of the environment field (will be copied).
94 * @param value Value of the environment field.
95 *
96 * Returns 0 on success, a negative value on error.
97 */
98extern int bt_ctf_trace_set_environment_field(
99 struct bt_ctf_trace *trace, const char *name,
dac5c838 100 struct bt_value *value);
7f800dc7
PP
101
102/*
103 * bt_ctf_trace_set_environment_field_string: sets a string environment
104 * field to the trace.
105 *
106 * Sets a string environment field to the trace. This is a helper
107 * function which corresponds to calling
108 * bt_ctf_trace_set_environment_field() with a string object.
bc37ae52
JG
109 *
110 * @param trace Trace instance.
111 * @param name Name of the environment field (will be copied).
112 * @param value Value of the environment field (will be copied).
113 *
114 * Returns 0 on success, a negative value on error.
115 */
7f800dc7
PP
116extern int bt_ctf_trace_set_environment_field_string(
117 struct bt_ctf_trace *trace, const char *name,
bc37ae52
JG
118 const char *value);
119
3487c9f3 120/*
7f800dc7 121 * bt_ctf_trace_set_environment_field_integer: sets an integer environment
3487c9f3
JG
122 * field to the trace.
123 *
7f800dc7
PP
124 * Sets an integer environment field to the trace. This is a helper
125 * function which corresponds to calling
126 * bt_ctf_trace_set_environment_field() with an integer object.
3487c9f3
JG
127 *
128 * @param trace Trace instance.
129 * @param name Name of the environment field (will be copied).
130 * @param value Value of the environment field.
131 *
132 * Returns 0 on success, a negative value on error.
133 */
7f800dc7 134extern int bt_ctf_trace_set_environment_field_integer(
3487c9f3
JG
135 struct bt_ctf_trace *trace, const char *name,
136 int64_t value);
137
e6fa2160
JG
138/*
139 * bt_ctf_trace_get_environment_field_count: get environment field count.
140 *
141 * Get the trace's environment field count.
142 *
143 * @param trace Trace instance.
144 *
145 * Returns the environment field count, a negative value on error.
146 */
147extern int bt_ctf_trace_get_environment_field_count(
148 struct bt_ctf_trace *trace);
149
e6fa2160
JG
150/*
151 * bt_ctf_trace_get_environment_field_name: get environment field name.
152 *
153 * Get an environment field's name. The string's ownership is not
7f800dc7
PP
154 * transferred to the caller. The string data is valid as long as
155 * this trace's environment is not modified.
e6fa2160
JG
156 *
157 * @param trace Trace instance.
158 * @param index Index of the environment field.
159 *
160 * Returns the environment field's name, NULL on error.
161 */
162extern const char *
163bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace,
164 int index);
165
166/*
7f800dc7
PP
167 * bt_ctf_trace_get_environment_field_value: get environment
168 * field value (an object).
e6fa2160 169 *
7f800dc7
PP
170 * Get an environment field's value (an object). The returned object's
171 * reference count is incremented. When done with the object, the caller
dac5c838 172 * must call bt_value_put() on it.
e6fa2160
JG
173 *
174 * @param trace Trace instance.
175 * @param index Index of the environment field.
176 *
7f800dc7 177 * Returns the environment field's object value, NULL on error.
e6fa2160 178 */
dac5c838 179extern struct bt_value *
7f800dc7 180bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace *trace,
e6fa2160
JG
181 int index);
182
183/*
7f800dc7
PP
184 * bt_ctf_trace_get_environment_field_value_by_name: get environment
185 * field value (an object) by name.
e6fa2160 186 *
7f800dc7
PP
187 * Get an environment field's value (an object) by its field name. The
188 * returned object's reference count is incremented. When done with the
dac5c838 189 * object, the caller must call bt_value_put() on it.
e6fa2160
JG
190 *
191 * @param trace Trace instance.
7f800dc7 192 * @param name Environment field's name
e6fa2160 193 *
7f800dc7 194 * Returns the environment field's object value, NULL on error.
e6fa2160 195 */
dac5c838 196extern struct bt_value *
7f800dc7
PP
197bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace *trace,
198 const char *name);
e6fa2160 199
bc37ae52
JG
200/*
201 * bt_ctf_trace_add_clock: add a clock to the trace.
202 *
203 * Add a clock to the trace. Clocks assigned to stream classes must be
204 * added to the trace beforehand.
205 *
206 * @param trace Trace instance.
207 * @param clock Clock to add to the trace.
208 *
209 * Returns 0 on success, a negative value on error.
210 */
211extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace,
212 struct bt_ctf_clock *clock);
213
884cd6c3
JG
214/*
215 * bt_ctf_trace_get_clock_count: get the number of clocks
ef0c4a15 216 * associated with the trace.
884cd6c3
JG
217 *
218 * @param trace Trace instance.
219 *
220 * Returns the clock count on success, a negative value on error.
221 */
222extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace);
223
224/*
225 * bt_ctf_trace_get_clock: get a trace's clock at index.
226 *
227 * @param trace Trace instance.
228 * @param index Index of the clock in the given trace.
229 *
230 * Return a clock instance on success, NULL on error.
231 */
232extern struct bt_ctf_clock *bt_ctf_trace_get_clock(
233 struct bt_ctf_trace *trace, int index);
234
ef0c4a15
JG
235/*
236 * bt_ctf_trace_add_stream_class: add a stream_class to the trace.
237 *
238 * Add a stream class to the trace.
239 *
240 * @param trace Trace instance.
241 * @param stream_class Stream class to add to the trace.
242 *
243 * Returns 0 on success, a negative value on error.
244 */
245extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
246 struct bt_ctf_stream_class *stream_class);
247
248/*
249 * bt_ctf_trace_get_stream_class_count: get the number of stream classes
250 * associated with the trace.
251 *
252 * @param trace Trace instance.
253 *
254 * Returns the stream class count on success, a negative value on error.
255 */
256extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace);
257
258/*
259 * bt_ctf_trace_get_stream_class: get a trace's stream class at index.
260 *
261 * @param trace Trace instance.
262 * @param index Index of the stream class in the given trace.
263 *
264 * Return a stream class on success, NULL on error.
265 */
266extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class(
267 struct bt_ctf_trace *trace, int index);
268
4841ccc1
PP
269/*
270 * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID.
271 *
272 * @param trace Trace instance.
273 * @param index ID of the stream class in the given trace.
274 *
275 * Return a stream class on success, NULL on error.
276 */
277extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id(
278 struct bt_ctf_trace *trace, uint32_t id);
279
7e4347a3
PP
280/*
281 * bt_ctf_trace_get_clock_by_name: get a trace's clock by name
282 *
283 * @param trace Trace instance.
284 * @param name Name of the clock in the given trace.
285 *
286 * Return a clock instance on success, NULL on error.
287 */
288extern struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name(
289 struct bt_ctf_trace *trace, const char *name);
290
bc37ae52
JG
291/*
292 * bt_ctf_trace_get_metadata_string: get metadata string.
293 *
294 * Get the trace's TSDL metadata. The caller assumes the ownership of the
295 * returned string.
296 *
297 * @param trace Trace instance.
298 *
299 * Returns the metadata string on success, NULL on error.
300 */
301extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace);
302
303/*
4ed90fb3
JG
304 * bt_ctf_trace_get_byte_order: get a trace's byte order.
305 *
306 * Get the trace's byte order.
307 *
308 * @param trace Trace instance.
309 *
310 * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error.
311 */
312extern enum bt_ctf_byte_order bt_ctf_trace_get_byte_order(
313 struct bt_ctf_trace *trace);
314
315/*
316 * bt_ctf_trace_set_byte_order: set a trace's byte order.
bc37ae52 317 *
c35a1669 318 * Set the trace's byte order. Defaults to the current host's endianness.
bc37ae52
JG
319 *
320 * @param trace Trace instance.
321 * @param byte_order Trace's byte order.
322 *
323 * Returns 0 on success, a negative value on error.
c35a1669
JG
324 *
325 * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
326 * to the CTF specification, is defined as "the byte order described in the
327 * trace description".
bc37ae52
JG
328 */
329extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
330 enum bt_ctf_byte_order byte_order);
331
d246b111
JG
332/*
333 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
334 *
335 * Get the trace's packet header type.
336 *
337 * @param trace Trace instance.
338 *
339 * Returns the trace's packet header type (a structure) on success, NULL on
340 * error.
341 */
342extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type(
343 struct bt_ctf_trace *trace);
344
345/*
346 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
347 *
348 * Set the trace's packet header type.
349 *
350 * @param trace Trace instance.
351 * @param packet_header_type Packet header field type (must be a structure).
352 *
353 * Returns 0 on success, a negative value on error.
354 */
355extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace,
356 struct bt_ctf_field_type *packet_header_type);
357
8bf65fbd
JG
358/*
359 * bt_ctf_trace_visit: visit a trace's hierarchy.
360 *
361 * Recursively walk a trace's hierarchy and call visitor on each of its
362 * elements.
363 *
364 * @param trace Trace instance.
365 * @param visitor visitor function to invoke for each element.
366 * @param data user data passed to the visitor.
367 *
368 * Returns 0 on success, a negative value on error.
369 */
370extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace,
371 bt_ctf_ir_visitor visitor, void *data);
372
2204c381 373/*
50ad4244 374 * bt_ctf_trace_add_listener: add a trace modification listener
2204c381
JG
375 * which will be invoked whenever a trace's schema is modified.
376 *
50ad4244 377 * Register a modification listener to a trace.
2204c381
JG
378 *
379 * @param trace Trace instance.
50ad4244
JG
380 * @param listener Callback to invoke on trace modification.
381 * @param listener_data Private data passed to the listener.
2204c381
JG
382 *
383 * Returns 0 on success, a negative value on error.
384 *
50ad4244 385 * Note: the listener will be used to serialize the trace's current
2204c381
JG
386 * state on registration. It will then be invoked on any change occuring within
387 * the trace's hierarchy.
388 */
50ad4244
JG
389extern int bt_ctf_trace_add_listener(struct bt_ctf_trace *trace,
390 bt_ctf_listener_cb listener, void *listener_data);
2204c381 391
bc37ae52
JG
392#ifdef __cplusplus
393}
394#endif
395
396#endif /* BABELTRACE_CTF_IR_TRACE_H */
This page took 0.048697 seconds and 4 git commands to generate.