Docs: event class must have a stream class before events may be created
[babeltrace.git] / include / babeltrace / ctf-ir / event.h
1 #ifndef BABELTRACE_CTF_IR_EVENT_H
2 #define BABELTRACE_CTF_IR_EVENT_H
3
4 /*
5 * BabelTrace - CTF IR: Event
6 *
7 * Copyright 2013, 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 <stdint.h>
34 #include <stddef.h>
35
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;
44 struct bt_ctf_stream_class;
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
50 * sets its reference count to 1. A unique event id is automatically assigned
51 * to the event class.
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
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
105 /*
106 * bt_ctf_event_class_add_field: add a field to an event class.
107 *
108 * Add a field of type "type" to the event class. The event class will share
109 * type's ownership by increasing its reference count. The "name" will be
110 * copied.
111 *
112 * @param event_class Event class.
113 * @param type Field type to add to the event class.
114 * @param name Name of the new field.
115 *
116 * Returns 0 on success, a negative value on error.
117 */
118 extern int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class,
119 struct bt_ctf_field_type *type,
120 const char *name);
121
122 /*
123 * bt_ctf_event_class_get_field_count: Get an event class' field count.
124 *
125 * @param event_class Event class.
126 *
127 * Returns the event class' field count, a negative value on error.
128 */
129 extern int bt_ctf_event_class_get_field_count(
130 struct bt_ctf_event_class *event_class);
131
132 /*
133 * bt_ctf_event_class_get_field: Get event class' field type and name by index.
134 *
135 * @param event_class Event class.
136 * @param field_name Pointer to a const char* where the field's name will
137 * be returned.
138 * @param field_type Pointer to a bt_ctf_field_type* where the field's type will
139 * be returned.
140 * @param index Index of field.
141 *
142 * Returns 0 on success, a negative error on value.
143 */
144 extern int bt_ctf_event_class_get_field(struct bt_ctf_event_class *event_class,
145 const char **field_name, struct bt_ctf_field_type **field_type,
146 int index);
147
148 /*
149 * bt_ctf_event_class_get_field_type_by_name: Get an event class's field by name
150 *
151 * @param event_class Event class.
152 * @param name Name of the field.
153 *
154 * Returns a field type on success, NULL on error.
155 */
156 extern struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name(
157 struct bt_ctf_event_class *event_class, const char *name);
158
159 /*
160 * bt_ctf_event_class_get_context_type: Get an event class's context type
161 *
162 * @param event_class Event class.
163 *
164 * Returns a field type (a structure) on success, NULL on error.
165 */
166 extern struct bt_ctf_field_type *bt_ctf_event_class_get_context_type(
167 struct bt_ctf_event_class *event_class);
168
169 /*
170 * bt_ctf_event_class_set_context_type: Set an event class's context type
171 *
172 * @param event_class Event class.
173 * @param context Event context field type (must be a structure).
174 *
175 * Returns 0 on success, a negative value on error.
176 */
177 extern int bt_ctf_event_class_set_context_type(
178 struct bt_ctf_event_class *event_class,
179 struct bt_ctf_field_type *context);
180
181 /*
182 * bt_ctf_event_class_get and bt_ctf_event_class_put: increment and decrement
183 * the event class' reference count.
184 *
185 * These functions ensure that the event class won't be destroyed while it
186 * is in use. The same number of get and put (plus one extra put to
187 * release the initial reference done at creation) have to be done to
188 * destroy an event class.
189 *
190 * When the event class' reference count is decremented to 0 by a
191 * bt_ctf_event_class_put, the event class is freed.
192 *
193 * @param event_class Event class.
194 */
195 extern void bt_ctf_event_class_get(struct bt_ctf_event_class *event_class);
196 extern void bt_ctf_event_class_put(struct bt_ctf_event_class *event_class);
197
198 /*
199 * bt_ctf_event_create: instanciate an event.
200 *
201 * Allocate a new event of the given event class. The creation of an event
202 * sets its reference count to 1. Each instance shares the ownership of the
203 * event class using its reference count.
204 *
205 * An event class must be associated with a stream class before events
206 * may be instanciated.
207 *
208 * @param event_class Event class.
209 *
210 * Returns an allocated field type on success, NULL on error.
211 */
212 extern struct bt_ctf_event *bt_ctf_event_create(
213 struct bt_ctf_event_class *event_class);
214
215 /*
216 * bt_ctf_event_get_class: get an event's class.
217 *
218 * @param event Event.
219 *
220 * Returns the event's class, NULL on error.
221 */
222 extern struct bt_ctf_event_class *bt_ctf_event_get_class(
223 struct bt_ctf_event *event);
224
225 /*
226 * bt_ctf_event_get_clock: get an event's associated clock.
227 *
228 * @param event Event.
229 *
230 * Returns the event's clock, NULL on error.
231 */
232 extern struct bt_ctf_clock *bt_ctf_event_get_clock(
233 struct bt_ctf_event *event);
234
235 /*
236 * bt_ctf_event_get_payload: get an event's field.
237 *
238 * Returns the field matching "name". bt_ctf_field_put() must be called on the
239 * returned value.
240 *
241 * @param event Event instance.
242 * @param name Event field name.
243 *
244 * Returns a field instance on success, NULL on error.
245 */
246 extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
247 const char *name);
248
249 /*
250 * bt_ctf_event_set_payload: set an event's field.
251 *
252 * Set a manually allocated field as an event's payload. The event will share
253 * the field's ownership by using its reference count.
254 * bt_ctf_field_put() must be called on the returned value.
255 *
256 * @param event Event instance.
257 * @param name Event field name.
258 * @param value Instance of a field whose type corresponds to the event's field.
259 *
260 * Returns 0 on success, a negative value on error.
261 */
262 extern int bt_ctf_event_set_payload(struct bt_ctf_event *event,
263 const char *name,
264 struct bt_ctf_field *value);
265
266 /*
267 * bt_ctf_event_get_payload_by_index: Get event's field by index.
268 *
269 * Returns the field associated with the provided index. bt_ctf_field_put()
270 * must be called on the returned value. The indexes to be provided are
271 * the same as can be retrieved from the event class.
272 *
273 * @param event Event.
274 * @param index Index of field.
275 *
276 * Returns the event's field, NULL on error.
277 */
278 extern struct bt_ctf_field *bt_ctf_event_get_payload_by_index(
279 struct bt_ctf_event *event, int index);
280
281 /*
282 * bt_ctf_event_get_header: get an event's header.
283 *
284 * @param event Event instance.
285 *
286 * Returns a field instance on success, NULL on error.
287 */
288 extern struct bt_ctf_field *bt_ctf_event_get_header(
289 struct bt_ctf_event *event);
290
291 /*
292 * bt_ctf_event_set_header: set an event's header.
293 *
294 * The event header's type must match the stream class' event
295 * header type.
296 *
297 * @param event Event instance.
298 * @param header Event header field instance.
299 *
300 * Returns a field instance on success, NULL on error.
301 */
302 extern int bt_ctf_event_set_header(
303 struct bt_ctf_event *event,
304 struct bt_ctf_field *header);
305
306 /*
307 * bt_ctf_event_get_event_context: Get an event's context
308 *
309 * @param event_class Event class.
310 *
311 * Returns a field on success (a structure), NULL on error.
312 *
313 * Note: This function is named this way instead of the expected
314 * "bt_ctf_event_get_context" in order to work around a name clash with
315 * an unrelated function bearing this name in context.h.
316 */
317 extern struct bt_ctf_field *bt_ctf_event_get_event_context(
318 struct bt_ctf_event *event);
319
320 /*
321 * bt_ctf_event_set_event_context: Set an event's context
322 *
323 * @param event Event.
324 * @param context Event context field (must match the event class'
325 * context type).
326 *
327 * Returns 0 on success, a negative value on error.
328 */
329 extern int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
330 struct bt_ctf_field *context);
331
332 /*
333 * bt_ctf_event_get and bt_ctf_event_put: increment and decrement
334 * the event's reference count.
335 *
336 * These functions ensure that the event won't be destroyed while it
337 * is in use. The same number of get and put (plus one extra put to
338 * release the initial reference done at creation) have to be done to
339 * destroy an event.
340 *
341 * When the event's reference count is decremented to 0 by a
342 * bt_ctf_event_put, the event is freed.
343 *
344 * @param event Event instance.
345 */
346 extern void bt_ctf_event_get(struct bt_ctf_event *event);
347 extern void bt_ctf_event_put(struct bt_ctf_event *event);
348
349 #ifdef __cplusplus
350 }
351 #endif
352
353 #endif /* BABELTRACE_CTF_IR_EVENT_H */
This page took 0.037446 seconds and 5 git commands to generate.