1 #ifndef BABELTRACE_CTF_IR_TRACE_H
2 #define BABELTRACE_CTF_IR_TRACE_H
5 * BabelTrace - CTF IR: Trace
7 * Copyright 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
29 * The Common Trace Format (CTF) Specification is available at
30 * http://www.efficios.com/ctf
33 #include <babeltrace/ctf-ir/field-types.h>
34 #include <babeltrace/ctf-ir/visitor.h>
35 #include <babeltrace/values.h>
36 #include <babeltrace/plugin/notification/notification.h>
45 struct bt_ctf_stream_class
;
49 * Trace modification handling function type.
51 * Callback invoked whenever an element is added to a trace's hierachy.
53 * @param element New element
54 * @param data Handler private data
56 typedef void (*bt_ctf_listener_cb
)(
57 struct bt_ctf_ir_element
*element
, void *data
);
60 * bt_ctf_trace_create: create a trace instance.
62 * Allocate a new trace.
64 * A trace's default packet header is a structure initialized with the following
68 * - uint32_t stream_id
70 * Returns a new trace on success, NULL on error.
72 extern struct bt_ctf_trace
*bt_ctf_trace_create(void);
74 extern const char *bt_ctf_trace_get_name(struct bt_ctf_trace
*trace
);
76 extern int bt_ctf_trace_set_name(struct bt_ctf_trace
*trace
, const char *name
);
79 * bt_ctf_trace_set_environment_field: sets an environment field to the
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).
86 * If a value exists in the environment for the specified name, it is
87 * replaced by the new value.
89 * The value parameter _must_ be either an integer value object or a
90 * string value object. Other object types are not supported.
92 * @param trace Trace instance.
93 * @param name Name of the environment field (will be copied).
94 * @param value Value of the environment field.
96 * Returns 0 on success, a negative value on error.
98 extern int bt_ctf_trace_set_environment_field(
99 struct bt_ctf_trace
*trace
, const char *name
,
100 struct bt_value
*value
);
103 * bt_ctf_trace_set_environment_field_string: sets a string environment
104 * field to the trace.
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.
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).
114 * Returns 0 on success, a negative value on error.
116 extern int bt_ctf_trace_set_environment_field_string(
117 struct bt_ctf_trace
*trace
, const char *name
,
121 * bt_ctf_trace_set_environment_field_integer: sets an integer environment
122 * field to the trace.
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.
128 * @param trace Trace instance.
129 * @param name Name of the environment field (will be copied).
130 * @param value Value of the environment field.
132 * Returns 0 on success, a negative value on error.
134 extern int bt_ctf_trace_set_environment_field_integer(
135 struct bt_ctf_trace
*trace
, const char *name
,
139 * bt_ctf_trace_get_environment_field_count: get environment field count.
141 * Get the trace's environment field count.
143 * @param trace Trace instance.
145 * Returns the environment field count, a negative value on error.
147 extern int bt_ctf_trace_get_environment_field_count(
148 struct bt_ctf_trace
*trace
);
151 * bt_ctf_trace_get_environment_field_name: get environment field name.
153 * Get an environment field's name. The string's ownership is not
154 * transferred to the caller. The string data is valid as long as
155 * this trace's environment is not modified.
157 * @param trace Trace instance.
158 * @param index Index of the environment field.
160 * Returns the environment field's name, NULL on error.
163 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
167 * bt_ctf_trace_get_environment_field_value: get environment
168 * field value (an object).
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
172 * must call bt_value_put() on it.
174 * @param trace Trace instance.
175 * @param index Index of the environment field.
177 * Returns the environment field's object value, NULL on error.
179 extern struct bt_value
*
180 bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace
*trace
,
184 * bt_ctf_trace_get_environment_field_value_by_name: get environment
185 * field value (an object) by name.
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
189 * object, the caller must call bt_value_put() on it.
191 * @param trace Trace instance.
192 * @param name Environment field's name
194 * Returns the environment field's object value, NULL on error.
196 extern struct bt_value
*
197 bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace
*trace
,
201 * bt_ctf_trace_add_clock: add a clock to the trace.
203 * Add a clock to the trace. Clocks assigned to stream classes must be
204 * added to the trace beforehand.
206 * @param trace Trace instance.
207 * @param clock Clock to add to the trace.
209 * Returns 0 on success, a negative value on error.
211 extern int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
212 struct bt_ctf_clock
*clock
);
215 * bt_ctf_trace_get_clock_count: get the number of clocks
216 * associated with the trace.
218 * @param trace Trace instance.
220 * Returns the clock count on success, a negative value on error.
222 extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
);
225 * bt_ctf_trace_get_clock: get a trace's clock at index.
227 * @param trace Trace instance.
228 * @param index Index of the clock in the given trace.
230 * Return a clock instance on success, NULL on error.
232 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock(
233 struct bt_ctf_trace
*trace
, int index
);
236 * bt_ctf_trace_add_stream_class: add a stream_class to the trace.
238 * Add a stream class to the trace.
240 * @param trace Trace instance.
241 * @param stream_class Stream class to add to the trace.
243 * Returns 0 on success, a negative value on error.
245 extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
246 struct bt_ctf_stream_class
*stream_class
);
249 * bt_ctf_trace_get_stream_class_count: get the number of stream classes
250 * associated with the trace.
252 * @param trace Trace instance.
254 * Returns the stream class count on success, a negative value on error.
256 extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
);
259 * bt_ctf_trace_get_stream_class: get a trace's stream class at index.
261 * @param trace Trace instance.
262 * @param index Index of the stream class in the given trace.
264 * Return a stream class on success, NULL on error.
266 extern struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
267 struct bt_ctf_trace
*trace
, int index
);
270 * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID.
272 * @param trace Trace instance.
273 * @param index ID of the stream class in the given trace.
275 * Return a stream class on success, NULL on error.
277 extern struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
278 struct bt_ctf_trace
*trace
, uint32_t id
);
281 * bt_ctf_trace_get_clock_by_name: get a trace's clock by name
283 * @param trace Trace instance.
284 * @param name Name of the clock in the given trace.
286 * Return a clock instance on success, NULL on error.
288 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
289 struct bt_ctf_trace
*trace
, const char *name
);
292 * bt_ctf_trace_get_metadata_string: get metadata string.
294 * Get the trace's TSDL metadata. The caller assumes the ownership of the
297 * @param trace Trace instance.
299 * Returns the metadata string on success, NULL on error.
301 extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
);
304 * bt_ctf_trace_get_byte_order: get a trace's byte order.
306 * Get the trace's byte order.
308 * @param trace Trace instance.
310 * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error.
312 extern enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(
313 struct bt_ctf_trace
*trace
);
316 * bt_ctf_trace_set_byte_order: set a trace's byte order.
318 * Set the trace's byte order. Defaults to the current host's endianness.
320 * @param trace Trace instance.
321 * @param byte_order Trace's byte order.
323 * Returns 0 on success, a negative value on error.
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".
329 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
330 enum bt_ctf_byte_order byte_order
);
333 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
335 * Get the trace's packet header type.
337 * @param trace Trace instance.
339 * Returns the trace's packet header type (a structure) on success, NULL on
342 extern struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
343 struct bt_ctf_trace
*trace
);
346 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
348 * Set the trace's packet header type.
350 * @param trace Trace instance.
351 * @param packet_header_type Packet header field type (must be a structure).
353 * Returns 0 on success, a negative value on error.
355 extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
356 struct bt_ctf_field_type
*packet_header_type
);
359 * bt_ctf_trace_visit: visit a trace's hierarchy.
361 * Recursively walk a trace's hierarchy and call visitor on each of its
364 * @param trace Trace instance.
365 * @param visitor visitor function to invoke for each element.
366 * @param data user data passed to the visitor.
368 * Returns 0 on success, a negative value on error.
370 extern int bt_ctf_trace_visit(struct bt_ctf_trace
*trace
,
371 bt_ctf_ir_visitor visitor
, void *data
);
374 * bt_ctf_trace_add_listener: add a trace modification listener
375 * which will be invoked whenever a trace's schema is modified.
377 * Register a modification listener to a trace.
379 * @param trace Trace instance.
380 * @param listener Callback to invoke on trace modification.
381 * @param listener_data Private data passed to the listener.
383 * Returns 0 on success, a negative value on error.
385 * Note: the listener will be used to serialize the trace's current
386 * state on registration. It will then be invoked on any change occuring within
387 * the trace's hierarchy.
389 extern int bt_ctf_trace_add_listener(struct bt_ctf_trace
*trace
,
390 bt_ctf_listener_cb listener
, void *listener_data
);
396 #endif /* BABELTRACE_CTF_IR_TRACE_H */