| 1 | #ifndef BABELTRACE_CTF_WRITER_EVENT_TYPES_INTERNAL_H |
| 2 | #define BABELTRACE_CTF_WRITER_EVENT_TYPES_INTERNAL_H |
| 3 | |
| 4 | /* |
| 5 | * BabelTrace - CTF Writer: Event types internal |
| 6 | * |
| 7 | * Copyright 2013 EfficiOS Inc. |
| 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 | |
| 30 | #include <babeltrace/ctf-writer/event-types.h> |
| 31 | #include <babeltrace/ctf-writer/ref-internal.h> |
| 32 | #include <babeltrace/ctf-writer/event-fields.h> |
| 33 | #include <babeltrace/ctf-writer/writer.h> |
| 34 | #include <babeltrace/ctf-writer/writer-internal.h> |
| 35 | #include <babeltrace/babeltrace-internal.h> |
| 36 | #include <babeltrace/types.h> |
| 37 | #include <babeltrace/ctf/events.h> |
| 38 | #include <glib.h> |
| 39 | |
| 40 | typedef void(*type_freeze_func)(struct bt_ctf_field_type *); |
| 41 | typedef int(*type_serialize_func)(struct bt_ctf_field_type *, |
| 42 | struct metadata_context *); |
| 43 | |
| 44 | struct bt_ctf_field_type { |
| 45 | struct bt_ctf_ref ref_count; |
| 46 | struct bt_declaration *declaration; |
| 47 | type_freeze_func freeze; |
| 48 | type_serialize_func serialize; |
| 49 | /* |
| 50 | * A type can't be modified once it is added to an event or after a |
| 51 | * a field has been instanciated from it. |
| 52 | */ |
| 53 | int frozen; |
| 54 | }; |
| 55 | |
| 56 | struct bt_ctf_field_type_integer { |
| 57 | struct bt_ctf_field_type parent; |
| 58 | struct declaration_integer declaration; |
| 59 | }; |
| 60 | |
| 61 | struct enumeration_mapping { |
| 62 | int64_t range_start; |
| 63 | int64_t range_end; |
| 64 | GQuark string; |
| 65 | }; |
| 66 | |
| 67 | struct bt_ctf_field_type_enumeration { |
| 68 | struct bt_ctf_field_type parent; |
| 69 | struct bt_ctf_field_type *container; |
| 70 | GPtrArray *entries; /* Array of pointers to struct enum_mapping */ |
| 71 | struct declaration_enum declaration; |
| 72 | }; |
| 73 | |
| 74 | struct bt_ctf_field_type_floating_point { |
| 75 | struct bt_ctf_field_type parent; |
| 76 | struct declaration_float declaration; |
| 77 | struct declaration_integer sign; |
| 78 | struct declaration_integer mantissa; |
| 79 | struct declaration_integer exp; |
| 80 | }; |
| 81 | |
| 82 | struct structure_field { |
| 83 | GQuark name; |
| 84 | struct bt_ctf_field_type *type; |
| 85 | }; |
| 86 | |
| 87 | struct bt_ctf_field_type_structure { |
| 88 | struct bt_ctf_field_type parent; |
| 89 | GHashTable *field_name_to_index; |
| 90 | GPtrArray *fields; /* Array of pointers to struct structure_field */ |
| 91 | struct declaration_enum declaration; |
| 92 | }; |
| 93 | |
| 94 | struct bt_ctf_field_type_variant { |
| 95 | struct bt_ctf_field_type parent; |
| 96 | GString *tag_name; |
| 97 | struct bt_ctf_field_type_enumeration *tag; |
| 98 | GHashTable *field_name_to_index; |
| 99 | GPtrArray *fields; /* Array of pointers to struct structure_field */ |
| 100 | struct declaration_variant declaration; |
| 101 | }; |
| 102 | |
| 103 | struct bt_ctf_field_type_array { |
| 104 | struct bt_ctf_field_type parent; |
| 105 | struct bt_ctf_field_type *element_type; |
| 106 | unsigned int length; /* Number of elements */ |
| 107 | struct declaration_array declaration; |
| 108 | }; |
| 109 | |
| 110 | struct bt_ctf_field_type_sequence { |
| 111 | struct bt_ctf_field_type parent; |
| 112 | struct bt_ctf_field_type *element_type; |
| 113 | GString *length_field_name; |
| 114 | struct declaration_sequence declaration; |
| 115 | }; |
| 116 | |
| 117 | struct bt_ctf_field_type_string { |
| 118 | struct bt_ctf_field_type parent; |
| 119 | struct declaration_string declaration; |
| 120 | }; |
| 121 | |
| 122 | BT_HIDDEN |
| 123 | void bt_ctf_field_type_freeze(struct bt_ctf_field_type *type); |
| 124 | |
| 125 | BT_HIDDEN |
| 126 | enum ctf_type_id bt_ctf_field_type_get_type_id( |
| 127 | struct bt_ctf_field_type *type); |
| 128 | |
| 129 | BT_HIDDEN |
| 130 | struct bt_ctf_field_type *bt_ctf_field_type_structure_get_type( |
| 131 | struct bt_ctf_field_type_structure *structure, |
| 132 | const char *name); |
| 133 | |
| 134 | BT_HIDDEN |
| 135 | struct bt_ctf_field_type *bt_ctf_field_type_array_get_element_type( |
| 136 | struct bt_ctf_field_type_array *array); |
| 137 | |
| 138 | BT_HIDDEN |
| 139 | struct bt_ctf_field_type *bt_ctf_field_type_sequence_get_element_type( |
| 140 | struct bt_ctf_field_type_sequence *sequence); |
| 141 | |
| 142 | BT_HIDDEN |
| 143 | struct bt_ctf_field_type *bt_ctf_field_type_variant_get_field_type( |
| 144 | struct bt_ctf_field_type_variant *variant, int64_t tag_value); |
| 145 | |
| 146 | BT_HIDDEN |
| 147 | int bt_ctf_field_type_serialize(struct bt_ctf_field_type *type, |
| 148 | struct metadata_context *context); |
| 149 | |
| 150 | BT_HIDDEN |
| 151 | int bt_ctf_field_type_validate(struct bt_ctf_field_type *type); |
| 152 | |
| 153 | #endif /* BABELTRACE_CTF_WRITER_EVENT_TYPES_INTERNAL_H */ |