| 1 | /* |
| 2 | * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_EVENT_FIELD_VALUE_INTERNAL_H |
| 9 | #define LTTNG_EVENT_FIELD_VALUE_INTERNAL_H |
| 10 | |
| 11 | #include <stdint.h> |
| 12 | #include <lttng/event-field-value.h> |
| 13 | #include <common/dynamic-array.h> |
| 14 | |
| 15 | struct lttng_event_field_value { |
| 16 | enum lttng_event_field_value_type type; |
| 17 | }; |
| 18 | |
| 19 | /* |
| 20 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_INT`. |
| 21 | */ |
| 22 | struct lttng_event_field_value_uint { |
| 23 | struct lttng_event_field_value parent; |
| 24 | uint64_t val; |
| 25 | }; |
| 26 | |
| 27 | /* |
| 28 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_INT`. |
| 29 | */ |
| 30 | struct lttng_event_field_value_int { |
| 31 | struct lttng_event_field_value parent; |
| 32 | int64_t val; |
| 33 | }; |
| 34 | |
| 35 | /* |
| 36 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` and |
| 37 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM` (base). |
| 38 | */ |
| 39 | struct lttng_event_field_value_enum { |
| 40 | struct lttng_event_field_value parent; |
| 41 | |
| 42 | /* |
| 43 | * Array of `char *` (owned by this). |
| 44 | */ |
| 45 | struct lttng_dynamic_pointer_array labels; |
| 46 | }; |
| 47 | |
| 48 | /* |
| 49 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM`. |
| 50 | */ |
| 51 | struct lttng_event_field_value_enum_uint { |
| 52 | struct lttng_event_field_value_enum parent; |
| 53 | uint64_t val; |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. |
| 58 | */ |
| 59 | struct lttng_event_field_value_enum_int { |
| 60 | struct lttng_event_field_value_enum parent; |
| 61 | int64_t val; |
| 62 | }; |
| 63 | |
| 64 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_REAL` */ |
| 65 | struct lttng_event_field_value_real { |
| 66 | struct lttng_event_field_value parent; |
| 67 | double val; |
| 68 | }; |
| 69 | |
| 70 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ |
| 71 | struct lttng_event_field_value_string { |
| 72 | struct lttng_event_field_value parent; |
| 73 | |
| 74 | /* Owned by this */ |
| 75 | char *val; |
| 76 | }; |
| 77 | |
| 78 | /* `LTTNG_EVENT_FIELD_VALUE_TYPE_STRING` */ |
| 79 | struct lttng_event_field_value_array { |
| 80 | struct lttng_event_field_value parent; |
| 81 | |
| 82 | /* |
| 83 | * Array of `struct lttng_event_field_value *` (owned by this). |
| 84 | * |
| 85 | * A `NULL` element means it's unavailable |
| 86 | * (`LTTNG_EVENT_FIELD_VALUE_STATUS_UNAVAILABLE` status). |
| 87 | */ |
| 88 | struct lttng_dynamic_pointer_array elems; |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * This is internal since the session daemon knows nothing about the |
| 93 | * enumeration fields produced by the kernel tracer. Indeed, the kernel tracer |
| 94 | * manages its own metadata which remains opaque to the rest of the toolchain. |
| 95 | * |
| 96 | * Enumerations could be supported for the user space tracer, but it is not the |
| 97 | * case right now. |
| 98 | */ |
| 99 | |
| 100 | /* |
| 101 | * Sets `*count` to the number of labels of the enumeration event field |
| 102 | * value `field_val`. |
| 103 | * |
| 104 | * Returns: |
| 105 | * |
| 106 | * `LTTNG_EVENT_FIELD_VALUE_STATUS_OK`: |
| 107 | * Success. |
| 108 | * |
| 109 | * `LTTNG_EVENT_FIELD_VALUE_STATUS_INVALID`: |
| 110 | * * `field_val` is `NULL`. |
| 111 | * * The type of `field_val` is not |
| 112 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or |
| 113 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. |
| 114 | * * `count` is `NULL`. |
| 115 | */ |
| 116 | LTTNG_HIDDEN |
| 117 | enum lttng_event_field_value_status |
| 118 | lttng_event_field_value_enum_get_label_count( |
| 119 | const struct lttng_event_field_value *field_val, |
| 120 | unsigned int *count); |
| 121 | |
| 122 | /* |
| 123 | * Returns the label at index `index` of the enumeration event field |
| 124 | * value `field_val`, or `NULL` if: |
| 125 | * |
| 126 | * * `field_val` is `NULL`. |
| 127 | * * The type of `field_val` is not |
| 128 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_UNSIGNED_ENUM` or |
| 129 | * `LTTNG_EVENT_FIELD_VALUE_TYPE_SIGNED_ENUM`. |
| 130 | * * `index` is greater than or equal to the label count of `field_val`, |
| 131 | * as returned by lttng_event_field_value_enum_get_label_count(). |
| 132 | */ |
| 133 | LTTNG_HIDDEN |
| 134 | const char *lttng_event_field_value_enum_get_label_at_index( |
| 135 | const struct lttng_event_field_value *field_val, |
| 136 | unsigned int index); |
| 137 | |
| 138 | LTTNG_HIDDEN |
| 139 | struct lttng_event_field_value *lttng_event_field_value_uint_create( |
| 140 | uint64_t val); |
| 141 | |
| 142 | LTTNG_HIDDEN |
| 143 | struct lttng_event_field_value *lttng_event_field_value_int_create( |
| 144 | int64_t val); |
| 145 | |
| 146 | LTTNG_HIDDEN |
| 147 | struct lttng_event_field_value *lttng_event_field_value_enum_uint_create( |
| 148 | uint64_t val); |
| 149 | |
| 150 | LTTNG_HIDDEN |
| 151 | struct lttng_event_field_value *lttng_event_field_value_enum_int_create( |
| 152 | int64_t val); |
| 153 | |
| 154 | LTTNG_HIDDEN |
| 155 | struct lttng_event_field_value *lttng_event_field_value_real_create(double val); |
| 156 | |
| 157 | LTTNG_HIDDEN |
| 158 | struct lttng_event_field_value *lttng_event_field_value_string_create( |
| 159 | const char *val); |
| 160 | |
| 161 | LTTNG_HIDDEN |
| 162 | struct lttng_event_field_value *lttng_event_field_value_string_create_with_size( |
| 163 | const char *val, size_t size); |
| 164 | |
| 165 | LTTNG_HIDDEN |
| 166 | struct lttng_event_field_value *lttng_event_field_value_array_create(void); |
| 167 | |
| 168 | LTTNG_HIDDEN |
| 169 | int lttng_event_field_value_enum_append_label( |
| 170 | struct lttng_event_field_value *field_val, const char *label); |
| 171 | |
| 172 | LTTNG_HIDDEN |
| 173 | int lttng_event_field_value_enum_append_label_with_size( |
| 174 | struct lttng_event_field_value *field_val, const char *label, |
| 175 | size_t size); |
| 176 | |
| 177 | LTTNG_HIDDEN |
| 178 | int lttng_event_field_value_array_append( |
| 179 | struct lttng_event_field_value *array_field_val, |
| 180 | struct lttng_event_field_value *field_val); |
| 181 | |
| 182 | LTTNG_HIDDEN |
| 183 | int lttng_event_field_value_array_append_unavailable( |
| 184 | struct lttng_event_field_value *array_field_val); |
| 185 | |
| 186 | LTTNG_HIDDEN |
| 187 | void lttng_event_field_value_destroy(struct lttng_event_field_value *field_val); |
| 188 | |
| 189 | #endif /* LTTNG_EVENT_FIELD_VALUE_INTERNAL_H */ |