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
30 #include <lttng/ust-dynamic-type.h>
32 static const struct lttng_enum_entry dt_enum
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
33 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
38 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
43 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
48 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
53 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
58 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
63 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
68 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
73 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
78 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
83 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
88 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
95 static const struct lttng_enum_desc dt_enum_desc
= {
96 .name
= "dynamic_type_enum",
98 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
101 const struct lttng_event_field dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
102 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
105 .atype
= atype_struct
,
106 .u
._struct
.nr_fields
= 0, /* empty struct. */
110 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
112 .type
= __type_integer(int8_t, BYTE_ORDER
, 10, none
),
115 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
117 .type
= __type_integer(int16_t, BYTE_ORDER
, 10, none
),
120 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
122 .type
= __type_integer(int32_t, BYTE_ORDER
, 10, none
),
125 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
127 .type
= __type_integer(int64_t, BYTE_ORDER
, 10, none
),
130 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
132 .type
= __type_integer(uint8_t, BYTE_ORDER
, 10, none
),
135 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
137 .type
= __type_integer(uint16_t, BYTE_ORDER
, 10, none
),
140 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
142 .type
= __type_integer(uint32_t, BYTE_ORDER
, 10, none
),
145 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
147 .type
= __type_integer(uint64_t, BYTE_ORDER
, 10, none
),
150 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
152 .type
= __type_float(float),
155 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
157 .type
= __type_float(double),
160 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
163 .atype
= atype_string
,
164 .u
.basic
.string
.encoding
= lttng_encode_UTF8
,
170 static const struct lttng_event_field dt_enum_field
= {
172 .type
.atype
= atype_enum
,
173 .type
.u
.basic
.enumeration
.desc
= &dt_enum_desc
,
174 .type
.u
.basic
.enumeration
.container_type
= {
175 .size
= sizeof(char) * CHAR_BIT
,
176 .alignment
= lttng_alignof(char) * CHAR_BIT
,
177 .signedness
= lttng_is_signed_type(char),
178 .reverse_byte_order
= 0,
180 .encoding
= lttng_encode_none
,
185 const struct lttng_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
187 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
189 return &dt_var_fields
[value
];
192 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_event_field
**choices
)
194 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
195 *choices
= dt_var_fields
;
199 const struct lttng_event_field
*lttng_ust_dynamic_type_tag_field(void)
201 return &dt_enum_field
;