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);
75 * bt_ctf_trace_set_environment_field: sets an environment field to the
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).
82 * If a value exists in the environment for the specified name, it is
83 * replaced by the new value.
85 * The value parameter _must_ be either an integer value object or a
86 * string value object. Other object types are not supported.
88 * @param trace Trace instance.
89 * @param name Name of the environment field (will be copied).
90 * @param value Value of the environment field.
92 * Returns 0 on success, a negative value on error.
94 extern int bt_ctf_trace_set_environment_field(
95 struct bt_ctf_trace
*trace
, const char *name
,
96 struct bt_value
*value
);
99 * bt_ctf_trace_set_environment_field_string: sets a string environment
100 * field to the trace.
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.
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).
110 * Returns 0 on success, a negative value on error.
112 extern int bt_ctf_trace_set_environment_field_string(
113 struct bt_ctf_trace
*trace
, const char *name
,
117 * bt_ctf_trace_set_environment_field_integer: sets an integer environment
118 * field to the trace.
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.
124 * @param trace Trace instance.
125 * @param name Name of the environment field (will be copied).
126 * @param value Value of the environment field.
128 * Returns 0 on success, a negative value on error.
130 extern int bt_ctf_trace_set_environment_field_integer(
131 struct bt_ctf_trace
*trace
, const char *name
,
135 * bt_ctf_trace_get_environment_field_count: get environment field count.
137 * Get the trace's environment field count.
139 * @param trace Trace instance.
141 * Returns the environment field count, a negative value on error.
143 extern int bt_ctf_trace_get_environment_field_count(
144 struct bt_ctf_trace
*trace
);
147 * bt_ctf_trace_get_environment_field_name: get environment field name.
149 * Get an environment field's name. The string's ownership is not
150 * transferred to the caller. The string data is valid as long as
151 * this trace's environment is not modified.
153 * @param trace Trace instance.
154 * @param index Index of the environment field.
156 * Returns the environment field's name, NULL on error.
159 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace
*trace
,
163 * bt_ctf_trace_get_environment_field_value: get environment
164 * field value (an object).
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
168 * must call bt_value_put() on it.
170 * @param trace Trace instance.
171 * @param index Index of the environment field.
173 * Returns the environment field's object value, NULL on error.
175 extern struct bt_value
*
176 bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace
*trace
,
180 * bt_ctf_trace_get_environment_field_value_by_name: get environment
181 * field value (an object) by name.
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
185 * object, the caller must call bt_value_put() on it.
187 * @param trace Trace instance.
188 * @param name Environment field's name
190 * Returns the environment field's object value, NULL on error.
192 extern struct bt_value
*
193 bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace
*trace
,
197 * bt_ctf_trace_add_clock: add a clock to the trace.
199 * Add a clock to the trace. Clocks assigned to stream classes must be
200 * added to the trace beforehand.
202 * @param trace Trace instance.
203 * @param clock Clock to add to the trace.
205 * Returns 0 on success, a negative value on error.
207 extern int bt_ctf_trace_add_clock(struct bt_ctf_trace
*trace
,
208 struct bt_ctf_clock
*clock
);
211 * bt_ctf_trace_get_clock_count: get the number of clocks
212 * associated with the trace.
214 * @param trace Trace instance.
216 * Returns the clock count on success, a negative value on error.
218 extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace
*trace
);
221 * bt_ctf_trace_get_clock: get a trace's clock at index.
223 * @param trace Trace instance.
224 * @param index Index of the clock in the given trace.
226 * Return a clock instance on success, NULL on error.
228 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock(
229 struct bt_ctf_trace
*trace
, int index
);
232 * bt_ctf_trace_add_stream_class: add a stream_class to the trace.
234 * Add a stream class to the trace.
236 * @param trace Trace instance.
237 * @param stream_class Stream class to add to the trace.
239 * Returns 0 on success, a negative value on error.
241 extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace
*trace
,
242 struct bt_ctf_stream_class
*stream_class
);
245 * bt_ctf_trace_get_stream_class_count: get the number of stream classes
246 * associated with the trace.
248 * @param trace Trace instance.
250 * Returns the stream class count on success, a negative value on error.
252 extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace
*trace
);
255 * bt_ctf_trace_get_stream_class: get a trace's stream class at index.
257 * @param trace Trace instance.
258 * @param index Index of the stream class in the given trace.
260 * Return a stream class on success, NULL on error.
262 extern struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class(
263 struct bt_ctf_trace
*trace
, int index
);
266 * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID.
268 * @param trace Trace instance.
269 * @param index ID of the stream class in the given trace.
271 * Return a stream class on success, NULL on error.
273 extern struct bt_ctf_stream_class
*bt_ctf_trace_get_stream_class_by_id(
274 struct bt_ctf_trace
*trace
, uint32_t id
);
277 * bt_ctf_trace_get_clock_by_name: get a trace's clock by name
279 * @param trace Trace instance.
280 * @param name Name of the clock in the given trace.
282 * Return a clock instance on success, NULL on error.
284 extern struct bt_ctf_clock
*bt_ctf_trace_get_clock_by_name(
285 struct bt_ctf_trace
*trace
, const char *name
);
288 * bt_ctf_trace_get_metadata_string: get metadata string.
290 * Get the trace's TSDL metadata. The caller assumes the ownership of the
293 * @param trace Trace instance.
295 * Returns the metadata string on success, NULL on error.
297 extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace
*trace
);
300 * bt_ctf_trace_get_byte_order: get a trace's byte order.
302 * Get the trace's byte order.
304 * @param trace Trace instance.
306 * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error.
308 extern enum bt_ctf_byte_order
bt_ctf_trace_get_byte_order(
309 struct bt_ctf_trace
*trace
);
312 * bt_ctf_trace_set_byte_order: set a trace's byte order.
314 * Set the trace's byte order. Defaults to the current host's endianness.
316 * @param trace Trace instance.
317 * @param byte_order Trace's byte order.
319 * Returns 0 on success, a negative value on error.
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".
325 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace
*trace
,
326 enum bt_ctf_byte_order byte_order
);
329 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
331 * Get the trace's packet header type.
333 * @param trace Trace instance.
335 * Returns the trace's packet header type (a structure) on success, NULL on
338 extern struct bt_ctf_field_type
*bt_ctf_trace_get_packet_header_type(
339 struct bt_ctf_trace
*trace
);
342 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
344 * Set the trace's packet header type.
346 * @param trace Trace instance.
347 * @param packet_header_type Packet header field type (must be a structure).
349 * Returns 0 on success, a negative value on error.
351 extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace
*trace
,
352 struct bt_ctf_field_type
*packet_header_type
);
355 * bt_ctf_trace_visit: visit a trace's hierarchy.
357 * Recursively walk a trace's hierarchy and call visitor on each of its
360 * @param trace Trace instance.
361 * @param visitor visitor function to invoke for each element.
362 * @param data user data passed to the visitor.
364 * Returns 0 on success, a negative value on error.
366 extern int bt_ctf_trace_visit(struct bt_ctf_trace
*trace
,
367 bt_ctf_ir_visitor visitor
, void *data
);
370 * bt_ctf_trace_add_listener: add a trace modification listener
371 * which will be invoked whenever a trace's schema is modified.
373 * Register a modification listener to a trace.
375 * @param trace Trace instance.
376 * @param listener Callback to invoke on trace modification.
377 * @param listener_data Private data passed to the listener.
379 * Returns 0 on success, a negative value on error.
381 * Note: the listener will be used to serialize the trace's current
382 * state on registration. It will then be invoked on any change occuring within
383 * the trace's hierarchy.
385 extern int bt_ctf_trace_add_listener(struct bt_ctf_trace
*trace
,
386 bt_ctf_listener_cb listener
, void *listener_data
);
392 #endif /* BABELTRACE_CTF_IR_TRACE_H */