2 * lttng-ust-dynamic-type.c
4 * UST dynamic type implementation.
6 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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.
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.
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
31 #include <lttng/ust-dynamic-type.h>
33 #define ctf_enum_value(_string, _value) \
36 .signedness = lttng_is_signed_type(__typeof__(_value)), \
37 .value = lttng_is_signed_type(__typeof__(_value)) ? \
38 (long long) (_value) : (_value), \
41 .signedness = lttng_is_signed_type(__typeof__(_value)), \
42 .value = lttng_is_signed_type(__typeof__(_value)) ? \
43 (long long) (_value) : (_value), \
45 .string = (_string), \
48 static const struct lttng_enum_entry dt_enum
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
49 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = ctf_enum_value("_none", 0)
50 [LTTNG_UST_DYNAMIC_TYPE_S8
] = ctf_enum_value("_int8", 1)
51 [LTTNG_UST_DYNAMIC_TYPE_S16
] = ctf_enum_value("_int16", 2)
52 [LTTNG_UST_DYNAMIC_TYPE_S32
] = ctf_enum_value("_int32", 3)
53 [LTTNG_UST_DYNAMIC_TYPE_S64
] = ctf_enum_value("_int64", 4)
54 [LTTNG_UST_DYNAMIC_TYPE_U8
] = ctf_enum_value("_uint8", 5)
55 [LTTNG_UST_DYNAMIC_TYPE_U16
] = ctf_enum_value("_uint16", 6)
56 [LTTNG_UST_DYNAMIC_TYPE_U32
] = ctf_enum_value("_uint32", 7)
57 [LTTNG_UST_DYNAMIC_TYPE_U64
] = ctf_enum_value("_uint64", 8)
58 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = ctf_enum_value("_float", 9)
59 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = ctf_enum_value("_double", 10)
60 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = ctf_enum_value("_string", 11)
63 static const struct lttng_enum_desc dt_enum_desc
= {
64 .name
= "dynamic_type_enum",
66 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
69 const struct lttng_event_field dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
70 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
73 .atype
= atype_struct_nestable
,
74 .u
.struct_nestable
.nr_fields
= 0, /* empty struct. */
75 .u
.struct_nestable
.alignment
= 0,
79 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
81 .type
= __type_integer(int8_t, BYTE_ORDER
, 10, none
),
84 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
86 .type
= __type_integer(int16_t, BYTE_ORDER
, 10, none
),
89 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
91 .type
= __type_integer(int32_t, BYTE_ORDER
, 10, none
),
94 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
96 .type
= __type_integer(int64_t, BYTE_ORDER
, 10, none
),
99 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
101 .type
= __type_integer(uint8_t, BYTE_ORDER
, 10, none
),
104 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
106 .type
= __type_integer(uint16_t, BYTE_ORDER
, 10, none
),
109 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
111 .type
= __type_integer(uint32_t, BYTE_ORDER
, 10, none
),
114 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
116 .type
= __type_integer(uint64_t, BYTE_ORDER
, 10, none
),
119 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
121 .type
= __type_float(float),
124 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
126 .type
= __type_float(double),
129 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
132 .atype
= atype_string
,
133 .u
.string
.encoding
= lttng_encode_UTF8
,
139 static const struct lttng_event_field dt_enum_field
= {
141 .type
.atype
= atype_enum_nestable
,
142 .type
.u
.enum_nestable
.desc
= &dt_enum_desc
,
143 .type
.u
.enum_nestable
.container_type
=
144 __LTTNG_COMPOUND_LITERAL(struct lttng_type
,
145 __type_integer(char, BYTE_ORDER
, 10, none
)),
149 const struct lttng_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
151 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
153 return &dt_var_fields
[value
];
156 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_event_field
**choices
)
158 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
159 *choices
= dt_var_fields
;
163 const struct lttng_event_field
*lttng_ust_dynamic_type_tag_field(void)
165 return &dt_enum_field
;