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