Commit | Line | Data |
---|---|---|
53569322 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
53569322 MD |
3 | * |
4 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
c0c0989a | 6 | * UST dynamic type implementation. |
53569322 MD |
7 | */ |
8 | ||
3fbec7dc | 9 | #define _LGPL_SOURCE |
53569322 MD |
10 | #include <stdio.h> |
11 | #include <stdint.h> | |
12 | #include <stddef.h> | |
13 | #include <inttypes.h> | |
14 | ||
9d315d6d MJ |
15 | #include "common/macros.h" |
16 | #include "common/dynamic-type.h" | |
53569322 | 17 | |
78684808 | 18 | #define lttng_ust_field_enum_value(_string, _value) \ |
5defa774 | 19 | LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \ |
891d6b55 | 20 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ |
a6f80644 | 21 | .start = { \ |
eae3c729 MJ |
22 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
23 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ | |
a6f80644 MD |
24 | (long long) (_value) : (_value), \ |
25 | }, \ | |
26 | .end = { \ | |
eae3c729 MJ |
27 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
28 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ | |
a6f80644 MD |
29 | (long long) (_value) : (_value), \ |
30 | }, \ | |
31 | .string = (_string), \ | |
891d6b55 | 32 | }), |
a6f80644 | 33 | |
4e48b5d2 | 34 | static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = { |
78684808 MJ |
35 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = lttng_ust_field_enum_value("_none", 0) |
36 | [LTTNG_UST_DYNAMIC_TYPE_S8] = lttng_ust_field_enum_value("_int8", 1) | |
37 | [LTTNG_UST_DYNAMIC_TYPE_S16] = lttng_ust_field_enum_value("_int16", 2) | |
38 | [LTTNG_UST_DYNAMIC_TYPE_S32] = lttng_ust_field_enum_value("_int32", 3) | |
39 | [LTTNG_UST_DYNAMIC_TYPE_S64] = lttng_ust_field_enum_value("_int64", 4) | |
40 | [LTTNG_UST_DYNAMIC_TYPE_U8] = lttng_ust_field_enum_value("_uint8", 5) | |
41 | [LTTNG_UST_DYNAMIC_TYPE_U16] = lttng_ust_field_enum_value("_uint16", 6) | |
42 | [LTTNG_UST_DYNAMIC_TYPE_U32] = lttng_ust_field_enum_value("_uint32", 7) | |
43 | [LTTNG_UST_DYNAMIC_TYPE_U64] = lttng_ust_field_enum_value("_uint64", 8) | |
44 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = lttng_ust_field_enum_value("_float", 9) | |
45 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = lttng_ust_field_enum_value("_double", 10) | |
46 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = lttng_ust_field_enum_value("_string", 11) | |
53569322 MD |
47 | }; |
48 | ||
a084756d | 49 | static struct lttng_ust_enum_desc dt_enum_desc = { |
53569322 MD |
50 | .name = "dynamic_type_enum", |
51 | .entries = dt_enum, | |
52 | .nr_entries = LTTNG_ARRAY_SIZE(dt_enum), | |
53 | }; | |
54 | ||
f78f3df1 | 55 | static const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { |
5defa774 | 56 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 57 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 58 | .name = "none", |
5defa774 | 59 | .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_struct, { |
a084756d MD |
60 | .parent = { |
61 | .type = lttng_ust_type_struct, | |
62 | }, | |
63 | .struct_size = sizeof(struct lttng_ust_type_struct), | |
64 | .nr_fields = 0, /* empty struct */ | |
65 | .alignment = 0, | |
66 | }), | |
53569322 | 67 | .nowrite = 0, |
25cff019 | 68 | }), |
5defa774 | 69 | [LTTNG_UST_DYNAMIC_TYPE_S8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 70 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 71 | .name = "int8", |
baa8acf3 | 72 | .type = lttng_ust_type_integer_define(int8_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 73 | .nowrite = 0, |
25cff019 | 74 | }), |
5defa774 | 75 | [LTTNG_UST_DYNAMIC_TYPE_S16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 76 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 77 | .name = "int16", |
baa8acf3 | 78 | .type = lttng_ust_type_integer_define(int16_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 79 | .nowrite = 0, |
25cff019 | 80 | }), |
5defa774 | 81 | [LTTNG_UST_DYNAMIC_TYPE_S32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 82 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 83 | .name = "int32", |
baa8acf3 | 84 | .type = lttng_ust_type_integer_define(int32_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 85 | .nowrite = 0, |
25cff019 | 86 | }), |
5defa774 | 87 | [LTTNG_UST_DYNAMIC_TYPE_S64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 88 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 89 | .name = "int64", |
baa8acf3 | 90 | .type = lttng_ust_type_integer_define(int64_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 91 | .nowrite = 0, |
25cff019 | 92 | }), |
5defa774 | 93 | [LTTNG_UST_DYNAMIC_TYPE_U8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 94 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 95 | .name = "uint8", |
baa8acf3 | 96 | .type = lttng_ust_type_integer_define(uint8_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 97 | .nowrite = 0, |
25cff019 | 98 | }), |
5defa774 | 99 | [LTTNG_UST_DYNAMIC_TYPE_U16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 100 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 101 | .name = "uint16", |
baa8acf3 | 102 | .type = lttng_ust_type_integer_define(uint16_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 103 | .nowrite = 0, |
25cff019 | 104 | }), |
5defa774 | 105 | [LTTNG_UST_DYNAMIC_TYPE_U32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 106 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 107 | .name = "uint32", |
baa8acf3 | 108 | .type = lttng_ust_type_integer_define(uint32_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 109 | .nowrite = 0, |
25cff019 | 110 | }), |
5defa774 | 111 | [LTTNG_UST_DYNAMIC_TYPE_U64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 112 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 113 | .name = "uint64", |
baa8acf3 | 114 | .type = lttng_ust_type_integer_define(uint64_t, LTTNG_UST_BYTE_ORDER, 10), |
53569322 | 115 | .nowrite = 0, |
25cff019 | 116 | }), |
5defa774 | 117 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 118 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 119 | .name = "float", |
a084756d | 120 | .type = lttng_ust_type_float_define(float), |
53569322 | 121 | .nowrite = 0, |
25cff019 | 122 | }), |
5defa774 | 123 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 124 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 125 | .name = "double", |
a084756d | 126 | .type = lttng_ust_type_float_define(double), |
53569322 | 127 | .nowrite = 0, |
25cff019 | 128 | }), |
5defa774 | 129 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { |
25cff019 | 130 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 131 | .name = "string", |
5defa774 | 132 | .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_string, { |
a084756d MD |
133 | .parent = { |
134 | .type = lttng_ust_type_string, | |
135 | }, | |
136 | .struct_size = sizeof(struct lttng_ust_type_string), | |
137 | .encoding = lttng_ust_string_encoding_UTF8, | |
138 | }), | |
53569322 | 139 | .nowrite = 0, |
25cff019 | 140 | }), |
53569322 MD |
141 | }; |
142 | ||
4e48b5d2 | 143 | static const struct lttng_ust_event_field dt_enum_field = { |
a084756d | 144 | .struct_size = sizeof(struct lttng_ust_event_field), |
53569322 | 145 | .name = NULL, |
5defa774 | 146 | .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_enum, { |
a084756d MD |
147 | .parent = { |
148 | .type = lttng_ust_type_enum, | |
149 | }, | |
150 | .struct_size = sizeof(struct lttng_ust_type_enum), | |
151 | .desc = &dt_enum_desc, | |
baa8acf3 | 152 | .container_type = lttng_ust_type_integer_define(char, LTTNG_UST_BYTE_ORDER, 10), |
a084756d | 153 | }), |
53569322 MD |
154 | .nowrite = 0, |
155 | }; | |
156 | ||
4e48b5d2 | 157 | const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value) |
53569322 MD |
158 | { |
159 | if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0) | |
160 | return NULL; | |
25cff019 | 161 | return dt_var_fields[value]; |
53569322 MD |
162 | } |
163 | ||
3d33ca1d | 164 | int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field * const **choices) |
53569322 MD |
165 | { |
166 | *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES; | |
167 | *choices = dt_var_fields; | |
168 | return 0; | |
169 | } | |
170 | ||
4e48b5d2 | 171 | const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void) |
53569322 MD |
172 | { |
173 | return &dt_enum_field; | |
174 | } |