| 1 | #ifndef BABELTRACE_CTF_IR_EVENT_FIELDS_H |
| 2 | #define BABELTRACE_CTF_IR_EVENT_FIELDS_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - CTF IR: Event Fields |
| 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 | |
| 45 | /* |
| 46 | * bt_ctf_field_create: create an instance of a field. |
| 47 | * |
| 48 | * Allocate a new field of the type described by the bt_ctf_field_type |
| 49 | * structure.The creation of a field sets its reference count to 1. |
| 50 | * |
| 51 | * @param type Field type to be instanciated. |
| 52 | * |
| 53 | * Returns an allocated field on success, NULL on error. |
| 54 | */ |
| 55 | extern struct bt_ctf_field *bt_ctf_field_create( |
| 56 | struct bt_ctf_field_type *type); |
| 57 | |
| 58 | /* |
| 59 | * bt_ctf_field_structure_get_field: get a structure's field. |
| 60 | * |
| 61 | * Get the structure's field corresponding to the provided field name. |
| 62 | * bt_ctf_field_put() must be called on the returned value. |
| 63 | * |
| 64 | * @param structure Structure field instance. |
| 65 | * @param name Name of the field in the provided structure. |
| 66 | * |
| 67 | * Returns a field instance on success, NULL on error. |
| 68 | */ |
| 69 | extern struct bt_ctf_field *bt_ctf_field_structure_get_field( |
| 70 | struct bt_ctf_field *structure, const char *name); |
| 71 | |
| 72 | /* |
| 73 | * bt_ctf_field_structure_get_field_by_index: get a structure's field by index. |
| 74 | * |
| 75 | * Get the structure's field corresponding to the provided field name. |
| 76 | * bt_ctf_field_put() must be called on the returned value. |
| 77 | * The indexes are the same as those provided for bt_ctf_field_type_structure. |
| 78 | * |
| 79 | * @param structure Structure field instance. |
| 80 | * @param index Index of the field in the provided structure. |
| 81 | * |
| 82 | * Returns a field instance on success, NULL on error. |
| 83 | */ |
| 84 | extern struct bt_ctf_field *bt_ctf_field_structure_get_field_by_index( |
| 85 | struct bt_ctf_field *structure, int index); |
| 86 | |
| 87 | /* |
| 88 | * bt_ctf_field_array_get_field: get an array's field at position "index". |
| 89 | * |
| 90 | * Return the array's field at position "index". bt_ctf_field_put() must be |
| 91 | * called on the returned value. |
| 92 | * |
| 93 | * @param array Array field instance. |
| 94 | * @param index Position of the array's desired element. |
| 95 | * |
| 96 | * Returns a field instance on success, NULL on error. |
| 97 | */ |
| 98 | extern struct bt_ctf_field *bt_ctf_field_array_get_field( |
| 99 | struct bt_ctf_field *array, uint64_t index); |
| 100 | |
| 101 | /* |
| 102 | * bt_ctf_field_sequence_get_length: get a sequence's length. |
| 103 | * |
| 104 | * Get the sequence's length field. |
| 105 | * |
| 106 | * @param sequence Sequence field instance. |
| 107 | * |
| 108 | * Returns a field instance on success, NULL if a length was never set. |
| 109 | */ |
| 110 | extern struct bt_ctf_field *bt_ctf_field_sequence_get_length( |
| 111 | struct bt_ctf_field *sequence); |
| 112 | |
| 113 | /* |
| 114 | * bt_ctf_field_sequence_set_length: set a sequence's length. |
| 115 | * |
| 116 | * Set the sequence's length field. |
| 117 | * |
| 118 | * @param sequence Sequence field instance. |
| 119 | * @param length_field Unsigned integer field instance indicating the |
| 120 | * sequence's length. |
| 121 | * |
| 122 | * Returns 0 on success, a negative value on error. |
| 123 | */ |
| 124 | extern int bt_ctf_field_sequence_set_length(struct bt_ctf_field *sequence, |
| 125 | struct bt_ctf_field *length_field); |
| 126 | |
| 127 | /* |
| 128 | * bt_ctf_field_sequence_get_field: get a sequence's field at position "index". |
| 129 | * |
| 130 | * Return the sequence's field at position "index". The sequence's length must |
| 131 | * have been set prior to calling this function using |
| 132 | * bt_ctf_field_sequence_set_length(). |
| 133 | * bt_ctf_field_put() must be called on the returned value. |
| 134 | * |
| 135 | * @param array Sequence field instance. |
| 136 | * @param index Position of the sequence's desired element. |
| 137 | * |
| 138 | * Returns a field instance on success, NULL on error. |
| 139 | */ |
| 140 | extern struct bt_ctf_field *bt_ctf_field_sequence_get_field( |
| 141 | struct bt_ctf_field *sequence, uint64_t index); |
| 142 | |
| 143 | /* |
| 144 | * bt_ctf_field_variant_get_field: get a variant's selected field. |
| 145 | * |
| 146 | * Return the variant's selected field. The "tag" field is the selector enum |
| 147 | * field. bt_ctf_field_put() must be called on the returned value. |
| 148 | * |
| 149 | * @param variant Variant field instance. |
| 150 | * @param tag Selector enumeration field. |
| 151 | * |
| 152 | * Returns a field instance on success, NULL on error. |
| 153 | */ |
| 154 | extern struct bt_ctf_field *bt_ctf_field_variant_get_field( |
| 155 | struct bt_ctf_field *variant, struct bt_ctf_field *tag); |
| 156 | |
| 157 | /* |
| 158 | * bt_ctf_field_enumeration_get_container: get an enumeration field's container. |
| 159 | * |
| 160 | * Return the enumeration's underlying container field (an integer). |
| 161 | * bt_ctf_field_put() must be called on the returned value. |
| 162 | * |
| 163 | * @param enumeration Enumeration field instance. |
| 164 | * |
| 165 | * Returns a field instance on success, NULL on error. |
| 166 | */ |
| 167 | extern struct bt_ctf_field *bt_ctf_field_enumeration_get_container( |
| 168 | struct bt_ctf_field *enumeration); |
| 169 | |
| 170 | /* |
| 171 | * bt_ctf_field_enumeration_get_mapping_name: get an enumeration field's mapping |
| 172 | * name. |
| 173 | * |
| 174 | * Return the enumeration's underlying container field (an integer). |
| 175 | * bt_ctf_field_put() must be called on the returned value. |
| 176 | * |
| 177 | * @param enumeration Enumeration field instance. |
| 178 | * |
| 179 | * Returns a field instance on success, NULL on error. |
| 180 | */ |
| 181 | extern const char *bt_ctf_field_enumeration_get_mapping_name( |
| 182 | struct bt_ctf_field *enumeration); |
| 183 | |
| 184 | /* |
| 185 | * bt_ctf_field_signed_integer_get_value: get a signed integer field's value |
| 186 | * |
| 187 | * Get a signed integer field's value. |
| 188 | * |
| 189 | * @param integer Signed integer field instance. |
| 190 | * @param value Pointer to a signed integer where the value will be stored. |
| 191 | * |
| 192 | * Returns 0 on success, a negative value on error. |
| 193 | */ |
| 194 | extern int bt_ctf_field_signed_integer_get_value(struct bt_ctf_field *integer, |
| 195 | int64_t *value); |
| 196 | |
| 197 | /* |
| 198 | * bt_ctf_field_signed_integer_set_value: set a signed integer field's value |
| 199 | * |
| 200 | * Set a signed integer field's value. The value is checked to make sure it |
| 201 | * can be stored in the underlying field. |
| 202 | * |
| 203 | * @param integer Signed integer field instance. |
| 204 | * @param value Signed integer field value. |
| 205 | * |
| 206 | * Returns 0 on success, a negative value on error. |
| 207 | */ |
| 208 | extern int bt_ctf_field_signed_integer_set_value(struct bt_ctf_field *integer, |
| 209 | int64_t value); |
| 210 | |
| 211 | /* |
| 212 | * bt_ctf_field_unsigned_integer_get_value: get unsigned integer field's value |
| 213 | * |
| 214 | * Get an unsigned integer field's value. |
| 215 | * |
| 216 | * @param integer Unsigned integer field instance. |
| 217 | * @param value Pointer to an unsigned integer where the value will be stored. |
| 218 | * |
| 219 | * Returns 0 on success, a negative value on error. |
| 220 | */ |
| 221 | extern int bt_ctf_field_unsigned_integer_get_value(struct bt_ctf_field *integer, |
| 222 | uint64_t *value); |
| 223 | |
| 224 | /* |
| 225 | * bt_ctf_field_unsigned_integer_set_value: set unsigned integer field's value |
| 226 | * |
| 227 | * Set an unsigned integer field's value. The value is checked to make sure it |
| 228 | * can be stored in the underlying field. |
| 229 | * |
| 230 | * @param integer Unsigned integer field instance. |
| 231 | * @param value Unsigned integer field value. |
| 232 | * |
| 233 | * Returns 0 on success, a negative value on error. |
| 234 | */ |
| 235 | extern int bt_ctf_field_unsigned_integer_set_value(struct bt_ctf_field *integer, |
| 236 | uint64_t value); |
| 237 | |
| 238 | /* |
| 239 | * bt_ctf_field_floating_point_get_value: get a floating point field's value |
| 240 | * |
| 241 | * Get a floating point field's value. |
| 242 | * |
| 243 | * @param floating_point Floating point field instance. |
| 244 | * @param value Pointer to a double where the value will be stored. |
| 245 | * |
| 246 | * Returns 0 on success, a negative value on error. |
| 247 | */ |
| 248 | extern int bt_ctf_field_floating_point_get_value( |
| 249 | struct bt_ctf_field *floating_point, double *value); |
| 250 | |
| 251 | /* |
| 252 | * bt_ctf_field_floating_point_set_value: set a floating point field's value |
| 253 | * |
| 254 | * Set a floating point field's value. The underlying type may not support the |
| 255 | * double's full precision. |
| 256 | * |
| 257 | * @param floating_point Floating point field instance. |
| 258 | * @param value Floating point field value. |
| 259 | * |
| 260 | * Returns 0 on success, a negative value on error. |
| 261 | */ |
| 262 | extern int bt_ctf_field_floating_point_set_value( |
| 263 | struct bt_ctf_field *floating_point, |
| 264 | double value); |
| 265 | |
| 266 | /* |
| 267 | * bt_ctf_field_string_get_value: get a string field's value |
| 268 | * |
| 269 | * Get a string field's value. |
| 270 | * |
| 271 | * @param string_field String field instance. |
| 272 | * |
| 273 | * Returns the string's value, NULL if unset. |
| 274 | */ |
| 275 | extern const char *bt_ctf_field_string_get_value( |
| 276 | struct bt_ctf_field *string_field); |
| 277 | |
| 278 | /* |
| 279 | * bt_ctf_field_string_set_value: set a string field's value |
| 280 | * |
| 281 | * Set a string field's value. |
| 282 | * |
| 283 | * @param string_field String field instance. |
| 284 | * @param value String field value (will be copied). |
| 285 | * |
| 286 | * Returns 0 on success, a negative value on error. |
| 287 | */ |
| 288 | extern int bt_ctf_field_string_set_value(struct bt_ctf_field *string_field, |
| 289 | const char *value); |
| 290 | |
| 291 | /* |
| 292 | * bt_ctf_field_string_append: append a string to a string field's |
| 293 | * current value. |
| 294 | * |
| 295 | * Append a string to the current value of a string field. If the string |
| 296 | * field was never set using bt_ctf_field_string_set_value(), it is |
| 297 | * first set to an empty string, and then the concatenation happens. |
| 298 | * |
| 299 | * @param string_field String field instance. |
| 300 | * @param value String to append to the current string field's value. |
| 301 | * |
| 302 | * Returns 0 on success, a negative value on error. |
| 303 | */ |
| 304 | extern int bt_ctf_field_string_append(struct bt_ctf_field *string_field, |
| 305 | const char *value); |
| 306 | |
| 307 | /* |
| 308 | * bt_ctf_field_get_type: get a field's type |
| 309 | * |
| 310 | * @param field Field intance. |
| 311 | * |
| 312 | * Returns a field type instance on success, NULL on error. |
| 313 | */ |
| 314 | extern struct bt_ctf_field_type *bt_ctf_field_get_type( |
| 315 | struct bt_ctf_field *field); |
| 316 | |
| 317 | /* |
| 318 | * bt_ctf_field_get and bt_ctf_field_put: increment and decrement the |
| 319 | * field's reference count. |
| 320 | * |
| 321 | * These functions ensure that the field won't be destroyed when it |
| 322 | * is in use. The same number of get and put (plus one extra put to |
| 323 | * release the initial reference done at creation) have to be done to |
| 324 | * destroy a field. |
| 325 | * |
| 326 | * When the field's reference count is decremented to 0 by a bt_ctf_field_put, |
| 327 | * the field is freed. |
| 328 | * |
| 329 | * @param field Field instance. |
| 330 | */ |
| 331 | extern void bt_ctf_field_get(struct bt_ctf_field *field); |
| 332 | extern void bt_ctf_field_put(struct bt_ctf_field *field); |
| 333 | |
| 334 | #ifdef __cplusplus |
| 335 | } |
| 336 | #endif |
| 337 | |
| 338 | #endif /* BABELTRACE_CTF_IR_EVENT_FIELDS_H */ |