Commit | Line | Data |
---|---|---|
adc315b8 JG |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_H |
2 | #define BABELTRACE_CTF_IR_EVENT_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF IR: Event | |
6 | * | |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
adc315b8 JG |
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 | ||
2f100782 JG |
33 | #include <stdint.h> |
34 | #include <stddef.h> | |
35 | ||
adc315b8 JG |
36 | #ifdef __cplusplus |
37 | extern "C" { | |
38 | #endif | |
39 | ||
40 | struct bt_ctf_event_class; | |
41 | struct bt_ctf_event; | |
42 | struct bt_ctf_field; | |
43 | struct bt_ctf_field_type; | |
2f100782 | 44 | struct bt_ctf_stream_class; |
adc315b8 JG |
45 | |
46 | /* | |
47 | * bt_ctf_event_class_create: create an event class. | |
48 | * | |
49 | * Allocate a new event class of the given name. The creation of an event class | |
2f100782 JG |
50 | * sets its reference count to 1. A unique event id is automatically assigned |
51 | * to the event class. | |
adc315b8 JG |
52 | * |
53 | * @param name Event class name (will be copied). | |
54 | * | |
55 | * Returns an allocated event class on success, NULL on error. | |
56 | */ | |
57 | extern struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name); | |
58 | ||
2f100782 JG |
59 | /* |
60 | * bt_ctf_event_class_get_name: Get an event class' name. | |
61 | * | |
62 | * @param event_class Event class. | |
63 | * | |
64 | * Returns the event class' name, NULL on error. | |
65 | */ | |
66 | extern const char *bt_ctf_event_class_get_name( | |
67 | struct bt_ctf_event_class *event_class); | |
68 | ||
69 | /* | |
70 | * bt_ctf_event_class_get_id: Get an event class' id. | |
71 | * | |
72 | * @param event_class Event class. | |
73 | * | |
74 | * Returns the event class' id, a negative value on error. | |
75 | */ | |
76 | extern int64_t bt_ctf_event_class_get_id( | |
77 | struct bt_ctf_event_class *event_class); | |
78 | ||
79 | /* | |
80 | * bt_ctf_event_class_set_id: Set an event class' id. | |
81 | * | |
82 | * Set an event class' id. Must be unique stream-wise. | |
83 | * Note that event classes are already assigned a unique id when added to a | |
84 | * stream class if none was set explicitly. | |
85 | * | |
86 | * @param event_class Event class. | |
87 | * @param id Event class id. | |
88 | * | |
89 | * Returns 0 on success, a negative value on error. | |
90 | */ | |
91 | extern int bt_ctf_event_class_set_id( | |
92 | struct bt_ctf_event_class *event_class, uint32_t id); | |
93 | ||
94 | /* | |
95 | * bt_ctf_event_class_get_stream_class: Get an event class' stream class. | |
96 | * | |
97 | * @param event_class Event class. | |
98 | * | |
99 | * Returns the event class' stream class, NULL on error or if the event class | |
100 | * is not associated with a stream class. | |
101 | */ | |
102 | extern struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class( | |
103 | struct bt_ctf_event_class *event_class); | |
104 | ||
c5a9aa19 JG |
105 | /* |
106 | * bt_ctf_event_class_get_payload_type: get an event class' payload. | |
107 | * | |
108 | * Get an event class' payload type. | |
109 | * | |
110 | * @param event_class Event class. | |
111 | * | |
112 | * Returns the event class' payload, NULL on error. | |
113 | */ | |
114 | extern struct bt_ctf_field_type *bt_ctf_event_class_get_payload_type( | |
115 | struct bt_ctf_event_class *event_class); | |
116 | ||
117 | /* | |
118 | * bt_ctf_event_class_set_payload_type: set an event class' payload. | |
119 | * | |
120 | * Set an event class' payload type. | |
121 | * | |
122 | * @param event_class Event class. | |
d2127f80 | 123 | * @param payload The payload's type (must be a structure). |
c5a9aa19 JG |
124 | * |
125 | * Returns 0 on success, a negative value on error. | |
126 | */ | |
127 | extern int bt_ctf_event_class_set_payload_type( | |
128 | struct bt_ctf_event_class *event_class, | |
129 | struct bt_ctf_field_type *payload); | |
130 | ||
adc315b8 JG |
131 | /* |
132 | * bt_ctf_event_class_add_field: add a field to an event class. | |
133 | * | |
134 | * Add a field of type "type" to the event class. The event class will share | |
135 | * type's ownership by increasing its reference count. The "name" will be | |
136 | * copied. | |
137 | * | |
138 | * @param event_class Event class. | |
139 | * @param type Field type to add to the event class. | |
140 | * @param name Name of the new field. | |
141 | * | |
142 | * Returns 0 on success, a negative value on error. | |
c5a9aa19 JG |
143 | * |
144 | * Note: Returns an error if the payload is not a structure. | |
adc315b8 JG |
145 | */ |
146 | extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, | |
147 | struct bt_ctf_field_type *type, | |
148 | const char *name); | |
149 | ||
2f100782 JG |
150 | /* |
151 | * bt_ctf_event_class_get_field_count: Get an event class' field count. | |
152 | * | |
153 | * @param event_class Event class. | |
154 | * | |
155 | * Returns the event class' field count, a negative value on error. | |
c5a9aa19 JG |
156 | * |
157 | * Note: Returns an error if the payload is not a structure. | |
2f100782 | 158 | */ |
074ee56d | 159 | extern int bt_ctf_event_class_get_field_count( |
2f100782 JG |
160 | struct bt_ctf_event_class *event_class); |
161 | ||
162 | /* | |
163 | * bt_ctf_event_class_get_field: Get event class' field type and name by index. | |
164 | * | |
165 | * @param event_class Event class. | |
166 | * @param field_name Pointer to a const char* where the field's name will | |
167 | * be returned. | |
168 | * @param field_type Pointer to a bt_ctf_field_type* where the field's type will | |
169 | * be returned. | |
170 | * @param index Index of field. | |
171 | * | |
172 | * Returns 0 on success, a negative error on value. | |
c5a9aa19 JG |
173 | * |
174 | * Note: Returns an error if the payload is not a structure. | |
2f100782 JG |
175 | */ |
176 | extern int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class, | |
177 | const char **field_name, struct bt_ctf_field_type **field_type, | |
074ee56d | 178 | int index); |
2f100782 JG |
179 | |
180 | /* | |
181 | * bt_ctf_event_class_get_field_type_by_name: Get an event class's field by name | |
182 | * | |
183 | * @param event_class Event class. | |
184 | * @param name Name of the field. | |
185 | * | |
186 | * Returns a field type on success, NULL on error. | |
c5a9aa19 JG |
187 | * |
188 | * Note: Returns an error if the payload is not a structure. | |
2f100782 JG |
189 | */ |
190 | extern struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name( | |
191 | struct bt_ctf_event_class *event_class, const char *name); | |
192 | ||
f655a84d JG |
193 | /* |
194 | * bt_ctf_event_class_get_context_type: Get an event class's context type | |
195 | * | |
196 | * @param event_class Event class. | |
197 | * | |
198 | * Returns a field type (a structure) on success, NULL on error. | |
199 | */ | |
200 | extern struct bt_ctf_field_type *bt_ctf_event_class_get_context_type( | |
201 | struct bt_ctf_event_class *event_class); | |
202 | ||
203 | /* | |
204 | * bt_ctf_event_class_set_context_type: Set an event class's context type | |
205 | * | |
206 | * @param event_class Event class. | |
207 | * @param context Event context field type (must be a structure). | |
208 | * | |
209 | * Returns 0 on success, a negative value on error. | |
210 | */ | |
211 | extern int bt_ctf_event_class_set_context_type( | |
212 | struct bt_ctf_event_class *event_class, | |
213 | struct bt_ctf_field_type *context); | |
214 | ||
adc315b8 | 215 | /* |
25faeb22 | 216 | * bt_ctf_event_class_get and bt_ctf_event_class_put: increment and decrement |
adc315b8 JG |
217 | * the event class' reference count. |
218 | * | |
219 | * These functions ensure that the event class won't be destroyed while it | |
220 | * is in use. The same number of get and put (plus one extra put to | |
221 | * release the initial reference done at creation) have to be done to | |
222 | * destroy an event class. | |
223 | * | |
224 | * When the event class' reference count is decremented to 0 by a | |
225 | * bt_ctf_event_class_put, the event class is freed. | |
226 | * | |
227 | * @param event_class Event class. | |
228 | */ | |
229 | extern void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class); | |
230 | extern void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class); | |
231 | ||
232 | /* | |
233 | * bt_ctf_event_create: instanciate an event. | |
234 | * | |
235 | * Allocate a new event of the given event class. The creation of an event | |
236 | * sets its reference count to 1. Each instance shares the ownership of the | |
237 | * event class using its reference count. | |
238 | * | |
54fca895 JG |
239 | * An event class must be associated with a stream class before events |
240 | * may be instanciated. | |
241 | * | |
adc315b8 JG |
242 | * @param event_class Event class. |
243 | * | |
244 | * Returns an allocated field type on success, NULL on error. | |
245 | */ | |
246 | extern struct bt_ctf_event *bt_ctf_event_create( | |
247 | struct bt_ctf_event_class *event_class); | |
248 | ||
2f100782 JG |
249 | /* |
250 | * bt_ctf_event_get_class: get an event's class. | |
251 | * | |
252 | * @param event Event. | |
253 | * | |
254 | * Returns the event's class, NULL on error. | |
255 | */ | |
256 | extern struct bt_ctf_event_class *bt_ctf_event_get_class( | |
257 | struct bt_ctf_event *event); | |
258 | ||
259 | /* | |
260 | * bt_ctf_event_get_clock: get an event's associated clock. | |
261 | * | |
262 | * @param event Event. | |
263 | * | |
264 | * Returns the event's clock, NULL on error. | |
265 | */ | |
266 | extern struct bt_ctf_clock *bt_ctf_event_get_clock( | |
267 | struct bt_ctf_event *event); | |
268 | ||
269 | /* | |
270 | * bt_ctf_event_get_payload: get an event's field. | |
271 | * | |
272 | * Returns the field matching "name". bt_ctf_field_put() must be called on the | |
273 | * returned value. | |
274 | * | |
275 | * @param event Event instance. | |
c5a9aa19 | 276 | * @param name Event field name, see notes. |
2f100782 JG |
277 | * |
278 | * Returns a field instance on success, NULL on error. | |
c5a9aa19 JG |
279 | * |
280 | * Note: Passing a name will cause the function to perform a look-up by | |
281 | * name assuming the event's payload is a structure. This will return | |
282 | * the raw payload instance if name is NULL. | |
2f100782 JG |
283 | */ |
284 | extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, | |
285 | const char *name); | |
286 | ||
adc315b8 JG |
287 | /* |
288 | * bt_ctf_event_set_payload: set an event's field. | |
289 | * | |
290 | * Set a manually allocated field as an event's payload. The event will share | |
291 | * the field's ownership by using its reference count. | |
292 | * bt_ctf_field_put() must be called on the returned value. | |
293 | * | |
294 | * @param event Event instance. | |
c5a9aa19 | 295 | * @param name Event field name, see notes. |
adc315b8 JG |
296 | * @param value Instance of a field whose type corresponds to the event's field. |
297 | * | |
298 | * Returns 0 on success, a negative value on error. | |
c5a9aa19 JG |
299 | * |
300 | * Note: The function will return an error if a name is provided and the payload | |
301 | * type is not a structure. If name is NULL, the payload field will be set | |
302 | * directly and must match the event class' payload's type. | |
adc315b8 JG |
303 | */ |
304 | extern int bt_ctf_event_set_payload(struct bt_ctf_event *event, | |
305 | const char *name, | |
306 | struct bt_ctf_field *value); | |
307 | ||
308 | /* | |
2f100782 | 309 | * bt_ctf_event_get_payload_by_index: Get event's field by index. |
adc315b8 | 310 | * |
2f100782 JG |
311 | * Returns the field associated with the provided index. bt_ctf_field_put() |
312 | * must be called on the returned value. The indexes to be provided are | |
313 | * the same as can be retrieved from the event class. | |
adc315b8 | 314 | * |
2f100782 JG |
315 | * @param event Event. |
316 | * @param index Index of field. | |
adc315b8 | 317 | * |
2f100782 | 318 | * Returns the event's field, NULL on error. |
c5a9aa19 JG |
319 | * |
320 | * Note: Will return an error if the payload's type is not a structure. | |
adc315b8 | 321 | */ |
2f100782 | 322 | extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index( |
074ee56d | 323 | struct bt_ctf_event *event, int index); |
adc315b8 | 324 | |
662e778c JG |
325 | /* |
326 | * bt_ctf_event_get_header: get an event's header. | |
327 | * | |
328 | * @param event Event instance. | |
329 | * | |
330 | * Returns a field instance on success, NULL on error. | |
331 | */ | |
332 | extern struct bt_ctf_field *bt_ctf_event_get_header( | |
333 | struct bt_ctf_event *event); | |
334 | ||
335 | /* | |
336 | * bt_ctf_event_set_header: set an event's header. | |
337 | * | |
338 | * The event header's type must match the stream class' event | |
339 | * header type. | |
340 | * | |
341 | * @param event Event instance. | |
342 | * @param header Event header field instance. | |
343 | * | |
344 | * Returns a field instance on success, NULL on error. | |
345 | */ | |
346 | extern int bt_ctf_event_set_header( | |
347 | struct bt_ctf_event *event, | |
348 | struct bt_ctf_field *header); | |
349 | ||
f655a84d JG |
350 | /* |
351 | * bt_ctf_event_get_event_context: Get an event's context | |
352 | * | |
353 | * @param event_class Event class. | |
354 | * | |
355 | * Returns a field on success (a structure), NULL on error. | |
356 | * | |
357 | * Note: This function is named this way instead of the expected | |
358 | * "bt_ctf_event_get_context" in order to work around a name clash with | |
359 | * an unrelated function bearing this name in context.h. | |
360 | */ | |
361 | extern struct bt_ctf_field *bt_ctf_event_get_event_context( | |
362 | struct bt_ctf_event *event); | |
363 | ||
364 | /* | |
365 | * bt_ctf_event_set_event_context: Set an event's context | |
366 | * | |
367 | * @param event Event. | |
368 | * @param context Event context field (must match the event class' | |
369 | * context type). | |
370 | * | |
371 | * Returns 0 on success, a negative value on error. | |
372 | */ | |
373 | extern int bt_ctf_event_set_event_context(struct bt_ctf_event *event, | |
374 | struct bt_ctf_field *context); | |
375 | ||
adc315b8 JG |
376 | /* |
377 | * bt_ctf_event_get and bt_ctf_event_put: increment and decrement | |
378 | * the event's reference count. | |
379 | * | |
380 | * These functions ensure that the event won't be destroyed while it | |
381 | * is in use. The same number of get and put (plus one extra put to | |
382 | * release the initial reference done at creation) have to be done to | |
383 | * destroy an event. | |
384 | * | |
385 | * When the event's reference count is decremented to 0 by a | |
386 | * bt_ctf_event_put, the event is freed. | |
387 | * | |
388 | * @param event Event instance. | |
389 | */ | |
390 | extern void bt_ctf_event_get(struct bt_ctf_event *event); | |
391 | extern void bt_ctf_event_put(struct bt_ctf_event *event); | |
392 | ||
393 | #ifdef __cplusplus | |
394 | } | |
395 | #endif | |
396 | ||
397 | #endif /* BABELTRACE_CTF_IR_EVENT_H */ |