| 1 | #ifndef BABELTRACE_CTF_IR_STREAM_CLASS_H |
| 2 | #define BABELTRACE_CTF_IR_STREAM_CLASS_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - CTF IR: Stream Class |
| 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 <stdint.h> |
| 34 | #include <babeltrace/ctf-ir/visitor.h> |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | struct bt_ctf_event_class; |
| 41 | struct bt_ctf_stream_class; |
| 42 | struct bt_ctf_clock; |
| 43 | |
| 44 | /* |
| 45 | * bt_ctf_stream_class_create: create a stream class. |
| 46 | * |
| 47 | * Allocate a new stream class of the given name. The creation of an event class |
| 48 | * sets its reference count to 1. |
| 49 | * |
| 50 | * A stream class' packet context is a structure initialized with the following |
| 51 | * fields: |
| 52 | * - uint64_t timestamp_begin |
| 53 | * - uint64_t timestamp_end |
| 54 | * - uint64_t content_size |
| 55 | * - uint64_t packet_size |
| 56 | * - uint64_t events_discarded |
| 57 | * |
| 58 | * A stream class's event header is a structure initialized the following |
| 59 | * fields: |
| 60 | * - uint32_t id |
| 61 | * - uint64_t timestamp |
| 62 | * |
| 63 | * @param name Stream name, NULL to create an unnamed stream class. |
| 64 | * |
| 65 | * Returns an allocated stream class on success, NULL on error. |
| 66 | */ |
| 67 | extern struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name); |
| 68 | |
| 69 | /* |
| 70 | * bt_ctf_stream_class_get_trace: Get a stream class' associated trace. |
| 71 | * |
| 72 | * @param stream_class Stream class. |
| 73 | * |
| 74 | * Returns the stream class' associated trace, NULL on error. |
| 75 | */ |
| 76 | extern struct bt_ctf_trace *bt_ctf_stream_class_get_trace( |
| 77 | struct bt_ctf_stream_class *stream_class); |
| 78 | |
| 79 | /* |
| 80 | * bt_ctf_stream_class_get_name: Get a stream class' name. |
| 81 | * |
| 82 | * @param stream_class Stream class. |
| 83 | * |
| 84 | * Returns the stream class' name, NULL on error. |
| 85 | */ |
| 86 | extern const char *bt_ctf_stream_class_get_name( |
| 87 | struct bt_ctf_stream_class *stream_class); |
| 88 | |
| 89 | /* |
| 90 | * bt_ctf_stream_class_set_name: Set a stream class' name. |
| 91 | * |
| 92 | * @param stream_class Stream class. |
| 93 | * |
| 94 | * Returns 0 on success, a negative value on error. |
| 95 | */ |
| 96 | extern int bt_ctf_stream_class_set_name( |
| 97 | struct bt_ctf_stream_class *stream_class, const char *name); |
| 98 | |
| 99 | /* |
| 100 | * bt_ctf_stream_class_get_clock: get the clock associated with a stream class. |
| 101 | * |
| 102 | * @param stream_class Stream class. |
| 103 | * |
| 104 | * Returns a clock instance, NULL on error. |
| 105 | */ |
| 106 | extern struct bt_ctf_clock *bt_ctf_stream_class_get_clock( |
| 107 | struct bt_ctf_stream_class *stream_class); |
| 108 | |
| 109 | /* |
| 110 | * bt_ctf_stream_class_get_id: Get a stream class' id. |
| 111 | * |
| 112 | * @param stream_class Stream class. |
| 113 | * |
| 114 | * Returns the stream class' id, a negative value on error. |
| 115 | */ |
| 116 | extern int64_t bt_ctf_stream_class_get_id( |
| 117 | struct bt_ctf_stream_class *stream_class); |
| 118 | |
| 119 | /* |
| 120 | * bt_ctf_stream_class_set_id: Set a stream class' id. |
| 121 | * |
| 122 | * Set a stream class' id. Must be unique trace-wise. |
| 123 | * Note that stream classes are assigned a unique id when a stream instance |
| 124 | * is created for the first time from a trace or writer. |
| 125 | * |
| 126 | * @param stream_class Stream class. |
| 127 | * @param id Stream class id. |
| 128 | * |
| 129 | * Returns 0 on success, a negative value on error. |
| 130 | */ |
| 131 | extern int bt_ctf_stream_class_set_id( |
| 132 | struct bt_ctf_stream_class *stream_class, uint32_t id); |
| 133 | |
| 134 | /* |
| 135 | * bt_ctf_stream_class_add_event_class: add an event class to a stream class. |
| 136 | * |
| 137 | * Add an event class to a stream class. New events can be added even after a |
| 138 | * stream has beem instanciated and events have been appended. However, a stream |
| 139 | * will not accept events of a class that has not been registered beforehand. |
| 140 | * The stream class will share the ownership of "event_class" by incrementing |
| 141 | * its reference count. |
| 142 | * |
| 143 | * Note that an event class may only be added to one stream class. It |
| 144 | * also becomes immutable. |
| 145 | * |
| 146 | * @param stream_class Stream class. |
| 147 | * @param event_class Event class to add to the provided stream class. |
| 148 | * |
| 149 | * Returns 0 on success, a negative value on error. |
| 150 | */ |
| 151 | extern int bt_ctf_stream_class_add_event_class( |
| 152 | struct bt_ctf_stream_class *stream_class, |
| 153 | struct bt_ctf_event_class *event_class); |
| 154 | |
| 155 | /* |
| 156 | * bt_ctf_stream_class_get_event_class_count: Get a stream class' event class |
| 157 | * count. |
| 158 | * |
| 159 | * @param stream_class Stream class. |
| 160 | * |
| 161 | * Returns the stream class' event count, a negative value on error. |
| 162 | */ |
| 163 | extern int bt_ctf_stream_class_get_event_class_count( |
| 164 | struct bt_ctf_stream_class *stream_class); |
| 165 | |
| 166 | /* |
| 167 | * bt_ctf_stream_class_get_event_class: Get stream class event class by index. |
| 168 | * |
| 169 | * @param stream_class Stream class. |
| 170 | * @param index Index of field. |
| 171 | * |
| 172 | * Returns event class, NULL on error. |
| 173 | */ |
| 174 | extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( |
| 175 | struct bt_ctf_stream_class *stream_class, int index); |
| 176 | |
| 177 | /* |
| 178 | * bt_ctf_stream_class_get_event_class_by_name: Get stream class event class by |
| 179 | * name. |
| 180 | * |
| 181 | * @param stream_class Stream class. |
| 182 | * @param name Event name. |
| 183 | * |
| 184 | * Returns event class, NULL on error. |
| 185 | */ |
| 186 | extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( |
| 187 | struct bt_ctf_stream_class *stream_class, const char *name); |
| 188 | |
| 189 | /* |
| 190 | * bt_ctf_stream_class_get_event_class_by_name: Get stream class event class by |
| 191 | * ID. |
| 192 | * |
| 193 | * @param stream_class Stream class. |
| 194 | * @param id Event class ID. |
| 195 | * |
| 196 | * Returns event class, NULL on error. |
| 197 | */ |
| 198 | extern struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( |
| 199 | struct bt_ctf_stream_class *stream_class, uint32_t id); |
| 200 | |
| 201 | /* |
| 202 | * bt_ctf_stream_class_get_packet_context_type: get the stream class' packet |
| 203 | * context type. |
| 204 | * |
| 205 | * @param stream_class Stream class. |
| 206 | * |
| 207 | * Returns the packet context's type (a structure), NULL on error. |
| 208 | */ |
| 209 | extern struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( |
| 210 | struct bt_ctf_stream_class *stream_class); |
| 211 | |
| 212 | /* |
| 213 | * bt_ctf_stream_class_set_packet_context_type: set the stream class' packet |
| 214 | * context type. |
| 215 | * |
| 216 | * @param stream_class Stream class. |
| 217 | * @param packet_context_type Packet context type (must be a structure). |
| 218 | * |
| 219 | * Returns 0 on success, a negative value on error. |
| 220 | */ |
| 221 | extern int bt_ctf_stream_class_set_packet_context_type( |
| 222 | struct bt_ctf_stream_class *stream_class, |
| 223 | struct bt_ctf_field_type *packet_context_type); |
| 224 | |
| 225 | /* |
| 226 | * bt_ctf_stream_class_get_event_header_type: get the stream class' |
| 227 | * event header type. |
| 228 | * |
| 229 | * @param stream_class Stream class. |
| 230 | * |
| 231 | * Returns the stream event header's type (a structure), NULL on error. |
| 232 | */ |
| 233 | extern struct bt_ctf_field_type * |
| 234 | bt_ctf_stream_class_get_event_header_type( |
| 235 | struct bt_ctf_stream_class *stream_class); |
| 236 | |
| 237 | /* |
| 238 | * bt_ctf_stream_class_set_event_header_type: set the stream class' |
| 239 | * event header type. |
| 240 | * |
| 241 | * @param stream_class Stream class. |
| 242 | * @param event_header_type Event header type (must be a structure). |
| 243 | * |
| 244 | * Returns 0 on success, a negative value on error. |
| 245 | */ |
| 246 | extern int bt_ctf_stream_class_set_event_header_type( |
| 247 | struct bt_ctf_stream_class *stream_class, |
| 248 | struct bt_ctf_field_type *event_header_type); |
| 249 | |
| 250 | /* |
| 251 | * bt_ctf_stream_class_get_event_context_type: get the stream class' |
| 252 | * event context type. |
| 253 | * |
| 254 | * @param stream_class Stream class. |
| 255 | * |
| 256 | * Returns the stream event context's type (a structure), NULL on error. |
| 257 | */ |
| 258 | extern struct bt_ctf_field_type * |
| 259 | bt_ctf_stream_class_get_event_context_type( |
| 260 | struct bt_ctf_stream_class *stream_class); |
| 261 | |
| 262 | /* |
| 263 | * bt_ctf_stream_class_set_event_context_type: set the stream class' |
| 264 | * event context type. |
| 265 | * |
| 266 | * @param stream_class Stream class. |
| 267 | * @param event_context_type Event context type (must be a structure). |
| 268 | * |
| 269 | * Returns 0 on success, a negative value on error. |
| 270 | */ |
| 271 | extern int bt_ctf_stream_class_set_event_context_type( |
| 272 | struct bt_ctf_stream_class *stream_class, |
| 273 | struct bt_ctf_field_type *event_context_type); |
| 274 | |
| 275 | /* |
| 276 | * bt_ctf_stream_class_visit: visit a stream class' event classes. |
| 277 | * |
| 278 | * Call visitor on each of a stream class' event classes. |
| 279 | * |
| 280 | * @param stream_class Stream class instance. |
| 281 | * @param visitor visitor function to invoke for each stream class. |
| 282 | * @param data user data passed to the visitor. |
| 283 | * |
| 284 | * Returns 0 on success, a negative value on error. |
| 285 | */ |
| 286 | extern int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class, |
| 287 | bt_ctf_ir_visitor visitor, void *data); |
| 288 | |
| 289 | #ifdef __cplusplus |
| 290 | } |
| 291 | #endif |
| 292 | |
| 293 | #endif /* BABELTRACE_CTF_IR_STREAM_CLASS_H */ |