Change "handler" terminology to the more specific listener
[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/field-types.h>
34 #include <babeltrace/ctf-ir/visitor.h>
35 #include <babeltrace/values.h>
36 #include <babeltrace/plugin/notification/notification.h>
37 #include <stdint.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 struct bt_ctf_trace;
44 struct bt_ctf_stream;
45 struct bt_ctf_stream_class;
46 struct bt_ctf_clock;
47
48 /**
49 * Trace modification handling function type.
50 *
51 * Callback invoked whenever an element is added to a trace's hierachy.
52 *
53 * @param element New element
54 * @param data Handler private data
55 */
56 typedef void (*bt_ctf_listener_cb)(
57 struct bt_ctf_ir_element *element, void *data);
58
59 /*
60 * bt_ctf_trace_create: create a trace instance.
61 *
62 * Allocate a new trace.
63 *
64 * A trace's default packet header is a structure initialized with the following
65 * fields:
66 * - uint32_t magic
67 * - uint8_t uuid[16]
68 * - uint32_t stream_id
69 *
70 * Returns a new trace on success, NULL on error.
71 */
72 extern struct bt_ctf_trace *bt_ctf_trace_create(void);
73
74 /*
75 * bt_ctf_trace_set_environment_field: sets an environment field to the
76 * trace.
77 *
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).
81 *
82 * If a value exists in the environment for the specified name, it is
83 * replaced by the new value.
84 *
85 * The value parameter _must_ be either an integer value object or a
86 * string value object. Other object types are not supported.
87 *
88 * @param trace Trace instance.
89 * @param name Name of the environment field (will be copied).
90 * @param value Value of the environment field.
91 *
92 * Returns 0 on success, a negative value on error.
93 */
94 extern int bt_ctf_trace_set_environment_field(
95 struct bt_ctf_trace *trace, const char *name,
96 struct bt_value *value);
97
98 /*
99 * bt_ctf_trace_set_environment_field_string: sets a string environment
100 * field to the trace.
101 *
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.
105 *
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).
109 *
110 * Returns 0 on success, a negative value on error.
111 */
112 extern int bt_ctf_trace_set_environment_field_string(
113 struct bt_ctf_trace *trace, const char *name,
114 const char *value);
115
116 /*
117 * bt_ctf_trace_set_environment_field_integer: sets an integer environment
118 * field to the trace.
119 *
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.
123 *
124 * @param trace Trace instance.
125 * @param name Name of the environment field (will be copied).
126 * @param value Value of the environment field.
127 *
128 * Returns 0 on success, a negative value on error.
129 */
130 extern int bt_ctf_trace_set_environment_field_integer(
131 struct bt_ctf_trace *trace, const char *name,
132 int64_t value);
133
134 /*
135 * bt_ctf_trace_get_environment_field_count: get environment field count.
136 *
137 * Get the trace's environment field count.
138 *
139 * @param trace Trace instance.
140 *
141 * Returns the environment field count, a negative value on error.
142 */
143 extern int bt_ctf_trace_get_environment_field_count(
144 struct bt_ctf_trace *trace);
145
146 /*
147 * bt_ctf_trace_get_environment_field_name: get environment field name.
148 *
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.
152 *
153 * @param trace Trace instance.
154 * @param index Index of the environment field.
155 *
156 * Returns the environment field's name, NULL on error.
157 */
158 extern const char *
159 bt_ctf_trace_get_environment_field_name(struct bt_ctf_trace *trace,
160 int index);
161
162 /*
163 * bt_ctf_trace_get_environment_field_value: get environment
164 * field value (an object).
165 *
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.
169 *
170 * @param trace Trace instance.
171 * @param index Index of the environment field.
172 *
173 * Returns the environment field's object value, NULL on error.
174 */
175 extern struct bt_value *
176 bt_ctf_trace_get_environment_field_value(struct bt_ctf_trace *trace,
177 int index);
178
179 /*
180 * bt_ctf_trace_get_environment_field_value_by_name: get environment
181 * field value (an object) by name.
182 *
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.
186 *
187 * @param trace Trace instance.
188 * @param name Environment field's name
189 *
190 * Returns the environment field's object value, NULL on error.
191 */
192 extern struct bt_value *
193 bt_ctf_trace_get_environment_field_value_by_name(struct bt_ctf_trace *trace,
194 const char *name);
195
196 /*
197 * bt_ctf_trace_add_clock: add a clock to the trace.
198 *
199 * Add a clock to the trace. Clocks assigned to stream classes must be
200 * added to the trace beforehand.
201 *
202 * @param trace Trace instance.
203 * @param clock Clock to add to the trace.
204 *
205 * Returns 0 on success, a negative value on error.
206 */
207 extern int bt_ctf_trace_add_clock(struct bt_ctf_trace *trace,
208 struct bt_ctf_clock *clock);
209
210 /*
211 * bt_ctf_trace_get_clock_count: get the number of clocks
212 * associated with the trace.
213 *
214 * @param trace Trace instance.
215 *
216 * Returns the clock count on success, a negative value on error.
217 */
218 extern int bt_ctf_trace_get_clock_count(struct bt_ctf_trace *trace);
219
220 /*
221 * bt_ctf_trace_get_clock: get a trace's clock at index.
222 *
223 * @param trace Trace instance.
224 * @param index Index of the clock in the given trace.
225 *
226 * Return a clock instance on success, NULL on error.
227 */
228 extern struct bt_ctf_clock *bt_ctf_trace_get_clock(
229 struct bt_ctf_trace *trace, int index);
230
231 /*
232 * bt_ctf_trace_add_stream_class: add a stream_class to the trace.
233 *
234 * Add a stream class to the trace.
235 *
236 * @param trace Trace instance.
237 * @param stream_class Stream class to add to the trace.
238 *
239 * Returns 0 on success, a negative value on error.
240 */
241 extern int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
242 struct bt_ctf_stream_class *stream_class);
243
244 /*
245 * bt_ctf_trace_get_stream_class_count: get the number of stream classes
246 * associated with the trace.
247 *
248 * @param trace Trace instance.
249 *
250 * Returns the stream class count on success, a negative value on error.
251 */
252 extern int bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace);
253
254 /*
255 * bt_ctf_trace_get_stream_class: get a trace's stream class at index.
256 *
257 * @param trace Trace instance.
258 * @param index Index of the stream class in the given trace.
259 *
260 * Return a stream class on success, NULL on error.
261 */
262 extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class(
263 struct bt_ctf_trace *trace, int index);
264
265 /*
266 * bt_ctf_trace_get_stream_class_by_id: get a trace's stream class by ID.
267 *
268 * @param trace Trace instance.
269 * @param index ID of the stream class in the given trace.
270 *
271 * Return a stream class on success, NULL on error.
272 */
273 extern struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id(
274 struct bt_ctf_trace *trace, uint32_t id);
275
276 /*
277 * bt_ctf_trace_get_clock_by_name: get a trace's clock by name
278 *
279 * @param trace Trace instance.
280 * @param name Name of the clock in the given trace.
281 *
282 * Return a clock instance on success, NULL on error.
283 */
284 extern struct bt_ctf_clock *bt_ctf_trace_get_clock_by_name(
285 struct bt_ctf_trace *trace, const char *name);
286
287 /*
288 * bt_ctf_trace_get_metadata_string: get metadata string.
289 *
290 * Get the trace's TSDL metadata. The caller assumes the ownership of the
291 * returned string.
292 *
293 * @param trace Trace instance.
294 *
295 * Returns the metadata string on success, NULL on error.
296 */
297 extern char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace);
298
299 /*
300 * bt_ctf_trace_get_byte_order: get a trace's byte order.
301 *
302 * Get the trace's byte order.
303 *
304 * @param trace Trace instance.
305 *
306 * Returns the trace's endianness, BT_CTF_BYTE_ORDER_UNKNOWN on error.
307 */
308 extern enum bt_ctf_byte_order bt_ctf_trace_get_byte_order(
309 struct bt_ctf_trace *trace);
310
311 /*
312 * bt_ctf_trace_set_byte_order: set a trace's byte order.
313 *
314 * Set the trace's byte order. Defaults to the current host's endianness.
315 *
316 * @param trace Trace instance.
317 * @param byte_order Trace's byte order.
318 *
319 * Returns 0 on success, a negative value on error.
320 *
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".
324 */
325 extern int bt_ctf_trace_set_byte_order(struct bt_ctf_trace *trace,
326 enum bt_ctf_byte_order byte_order);
327
328 /*
329 * bt_ctf_trace_get_packet_header_type: get a trace's packet header type.
330 *
331 * Get the trace's packet header type.
332 *
333 * @param trace Trace instance.
334 *
335 * Returns the trace's packet header type (a structure) on success, NULL on
336 * error.
337 */
338 extern struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_type(
339 struct bt_ctf_trace *trace);
340
341 /*
342 * bt_ctf_trace_set_packet_header_type: set a trace's packet header type.
343 *
344 * Set the trace's packet header type.
345 *
346 * @param trace Trace instance.
347 * @param packet_header_type Packet header field type (must be a structure).
348 *
349 * Returns 0 on success, a negative value on error.
350 */
351 extern int bt_ctf_trace_set_packet_header_type(struct bt_ctf_trace *trace,
352 struct bt_ctf_field_type *packet_header_type);
353
354 /*
355 * bt_ctf_trace_visit: visit a trace's hierarchy.
356 *
357 * Recursively walk a trace's hierarchy and call visitor on each of its
358 * elements.
359 *
360 * @param trace Trace instance.
361 * @param visitor visitor function to invoke for each element.
362 * @param data user data passed to the visitor.
363 *
364 * Returns 0 on success, a negative value on error.
365 */
366 extern int bt_ctf_trace_visit(struct bt_ctf_trace *trace,
367 bt_ctf_ir_visitor visitor, void *data);
368
369 /*
370 * bt_ctf_trace_add_listener: add a trace modification listener
371 * which will be invoked whenever a trace's schema is modified.
372 *
373 * Register a modification listener to a trace.
374 *
375 * @param trace Trace instance.
376 * @param listener Callback to invoke on trace modification.
377 * @param listener_data Private data passed to the listener.
378 *
379 * Returns 0 on success, a negative value on error.
380 *
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.
384 */
385 extern int bt_ctf_trace_add_listener(struct bt_ctf_trace *trace,
386 bt_ctf_listener_cb listener, void *listener_data);
387
388 #ifdef __cplusplus
389 }
390 #endif
391
392 #endif /* BABELTRACE_CTF_IR_TRACE_H */
This page took 0.037922 seconds and 5 git commands to generate.