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