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