| 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_create: instanciate an event. |
| 48 | * |
| 49 | * Allocate a new event of the given event class. The creation of an event |
| 50 | * sets its reference count to 1. Each instance shares the ownership of the |
| 51 | * event class using its reference count. |
| 52 | * |
| 53 | * An event class must be associated with a stream class before events |
| 54 | * may be instanciated. |
| 55 | * |
| 56 | * @param event_class Event class. |
| 57 | * |
| 58 | * Returns an allocated field type on success, NULL on error. |
| 59 | */ |
| 60 | extern struct bt_ctf_event *bt_ctf_event_create( |
| 61 | struct bt_ctf_event_class *event_class); |
| 62 | |
| 63 | /* |
| 64 | * bt_ctf_event_get_payload: get an event's field. |
| 65 | * |
| 66 | * Returns the field matching "name". bt_ctf_field_put() must be called on the |
| 67 | * returned value. |
| 68 | * |
| 69 | * @param event Event instance. |
| 70 | * @param name Event field name, see notes. |
| 71 | * |
| 72 | * Returns a field instance on success, NULL on error. |
| 73 | * |
| 74 | * Note: Passing a name will cause the function to perform a look-up by |
| 75 | * name assuming the event's payload is a structure. This will return |
| 76 | * the raw payload instance if name is NULL. |
| 77 | */ |
| 78 | extern struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event, |
| 79 | const char *name); |
| 80 | |
| 81 | /* |
| 82 | * bt_ctf_event_set_payload: set an event's field. |
| 83 | * |
| 84 | * Set a manually allocated field as an event's payload. The event will share |
| 85 | * the field's ownership by using its reference count. |
| 86 | * bt_ctf_field_put() must be called on the returned value. |
| 87 | * |
| 88 | * @param event Event instance. |
| 89 | * @param name Event field name, see notes. |
| 90 | * @param value Instance of a field whose type corresponds to the event's field. |
| 91 | * |
| 92 | * Returns 0 on success, a negative value on error. |
| 93 | * |
| 94 | * Note: The function will return an error if a name is provided and the payload |
| 95 | * type is not a structure. If name is NULL, the payload field will be set |
| 96 | * directly and must match the event class' payload's type. |
| 97 | */ |
| 98 | extern int bt_ctf_event_set_payload(struct bt_ctf_event *event, |
| 99 | const char *name, |
| 100 | struct bt_ctf_field *value); |
| 101 | |
| 102 | #ifdef __cplusplus |
| 103 | } |
| 104 | #endif |
| 105 | |
| 106 | #endif /* BABELTRACE_CTF_IR_EVENT_H */ |