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