Commit | Line | Data |
---|---|---|
53569322 MD |
1 | /* |
2 | * lttng-ust-dynamic-type.c | |
3 | * | |
4 | * UST dynamic type implementation. | |
5 | * | |
6 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; only | |
11 | * version 2.1 of the License. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | */ | |
22 | ||
3fbec7dc | 23 | #define _LGPL_SOURCE |
53569322 MD |
24 | #include <stdio.h> |
25 | #include <stdint.h> | |
26 | #include <stddef.h> | |
27 | #include <inttypes.h> | |
28 | ||
29 | #include <helper.h> | |
30 | #include <lttng/ust-dynamic-type.h> | |
31 | ||
a6f80644 MD |
32 | #define ctf_enum_value(_string, _value) \ |
33 | { \ | |
34 | .start = { \ | |
35 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
36 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
37 | (long long) (_value) : (_value), \ | |
38 | }, \ | |
39 | .end = { \ | |
40 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
41 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
42 | (long long) (_value) : (_value), \ | |
43 | }, \ | |
44 | .string = (_string), \ | |
53569322 | 45 | }, |
a6f80644 MD |
46 | |
47 | static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = { | |
48 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0) | |
49 | [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1) | |
50 | [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2) | |
51 | [LTTNG_UST_DYNAMIC_TYPE_S32] = ctf_enum_value("_int32", 3) | |
52 | [LTTNG_UST_DYNAMIC_TYPE_S64] = ctf_enum_value("_int64", 4) | |
53 | [LTTNG_UST_DYNAMIC_TYPE_U8] = ctf_enum_value("_uint8", 5) | |
54 | [LTTNG_UST_DYNAMIC_TYPE_U16] = ctf_enum_value("_uint16", 6) | |
55 | [LTTNG_UST_DYNAMIC_TYPE_U32] = ctf_enum_value("_uint32", 7) | |
56 | [LTTNG_UST_DYNAMIC_TYPE_U64] = ctf_enum_value("_uint64", 8) | |
57 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = ctf_enum_value("_float", 9) | |
58 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = ctf_enum_value("_double", 10) | |
59 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11) | |
53569322 MD |
60 | }; |
61 | ||
62 | static const struct lttng_enum_desc dt_enum_desc = { | |
63 | .name = "dynamic_type_enum", | |
64 | .entries = dt_enum, | |
65 | .nr_entries = LTTNG_ARRAY_SIZE(dt_enum), | |
66 | }; | |
67 | ||
68 | const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { | |
69 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = { | |
70 | .name = "none", | |
71 | .type = { | |
218deb69 MD |
72 | .atype = atype_struct_nestable, |
73 | .u.struct_nestable.nr_fields = 0, /* empty struct. */ | |
74 | .u.struct_nestable.alignment = 0, | |
53569322 MD |
75 | }, |
76 | .nowrite = 0, | |
77 | }, | |
78 | [LTTNG_UST_DYNAMIC_TYPE_S8] = { | |
79 | .name = "int8", | |
80 | .type = __type_integer(int8_t, BYTE_ORDER, 10, none), | |
81 | .nowrite = 0, | |
82 | }, | |
83 | [LTTNG_UST_DYNAMIC_TYPE_S16] = { | |
84 | .name = "int16", | |
85 | .type = __type_integer(int16_t, BYTE_ORDER, 10, none), | |
86 | .nowrite = 0, | |
87 | }, | |
88 | [LTTNG_UST_DYNAMIC_TYPE_S32] = { | |
89 | .name = "int32", | |
90 | .type = __type_integer(int32_t, BYTE_ORDER, 10, none), | |
91 | .nowrite = 0, | |
92 | }, | |
93 | [LTTNG_UST_DYNAMIC_TYPE_S64] = { | |
94 | .name = "int64", | |
95 | .type = __type_integer(int64_t, BYTE_ORDER, 10, none), | |
96 | .nowrite = 0, | |
97 | }, | |
98 | [LTTNG_UST_DYNAMIC_TYPE_U8] = { | |
99 | .name = "uint8", | |
100 | .type = __type_integer(uint8_t, BYTE_ORDER, 10, none), | |
101 | .nowrite = 0, | |
102 | }, | |
103 | [LTTNG_UST_DYNAMIC_TYPE_U16] = { | |
104 | .name = "uint16", | |
105 | .type = __type_integer(uint16_t, BYTE_ORDER, 10, none), | |
106 | .nowrite = 0, | |
107 | }, | |
108 | [LTTNG_UST_DYNAMIC_TYPE_U32] = { | |
109 | .name = "uint32", | |
110 | .type = __type_integer(uint32_t, BYTE_ORDER, 10, none), | |
111 | .nowrite = 0, | |
112 | }, | |
113 | [LTTNG_UST_DYNAMIC_TYPE_U64] = { | |
114 | .name = "uint64", | |
115 | .type = __type_integer(uint64_t, BYTE_ORDER, 10, none), | |
116 | .nowrite = 0, | |
117 | }, | |
118 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = { | |
119 | .name = "float", | |
120 | .type = __type_float(float), | |
121 | .nowrite = 0, | |
122 | }, | |
123 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = { | |
124 | .name = "double", | |
125 | .type = __type_float(double), | |
126 | .nowrite = 0, | |
127 | }, | |
128 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = { | |
129 | .name = "string", | |
130 | .type = { | |
131 | .atype = atype_string, | |
218deb69 | 132 | .u.string.encoding = lttng_encode_UTF8, |
53569322 MD |
133 | }, |
134 | .nowrite = 0, | |
135 | }, | |
136 | }; | |
137 | ||
138 | static const struct lttng_event_field dt_enum_field = { | |
139 | .name = NULL, | |
218deb69 MD |
140 | .type.atype = atype_enum_nestable, |
141 | .type.u.enum_nestable.desc = &dt_enum_desc, | |
142 | .type.u.enum_nestable.container_type = | |
143 | __LTTNG_COMPOUND_LITERAL(struct lttng_type, | |
144 | __type_integer(char, BYTE_ORDER, 10, none)), | |
53569322 MD |
145 | .nowrite = 0, |
146 | }; | |
147 | ||
148 | const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value) | |
149 | { | |
150 | if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0) | |
151 | return NULL; | |
152 | return &dt_var_fields[value]; | |
153 | } | |
154 | ||
155 | int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices) | |
156 | { | |
157 | *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES; | |
158 | *choices = dt_var_fields; | |
159 | return 0; | |
160 | } | |
161 | ||
162 | const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void) | |
163 | { | |
164 | return &dt_enum_field; | |
165 | } |