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 #define ctf_enum_value(_string, _value) \
35 .signedness = lttng_is_signed_type(__typeof__(_value)), \
36 .value = lttng_is_signed_type(__typeof__(_value)) ? \
37 (long long) (_value) : (_value), \
40 .signedness = lttng_is_signed_type(__typeof__(_value)), \
41 .value = lttng_is_signed_type(__typeof__(_value)) ? \
42 (long long) (_value) : (_value), \
44 .string = (_string), \
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)
62 static const struct lttng_enum_desc dt_enum_desc
= {
63 .name
= "dynamic_type_enum",
65 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
68 const struct lttng_event_field dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
69 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
72 .atype
= atype_struct
,
73 .u
._struct
.nr_fields
= 0, /* empty struct. */
77 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
79 .type
= __type_integer(int8_t, BYTE_ORDER
, 10, none
),
82 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
84 .type
= __type_integer(int16_t, BYTE_ORDER
, 10, none
),
87 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
89 .type
= __type_integer(int32_t, BYTE_ORDER
, 10, none
),
92 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
94 .type
= __type_integer(int64_t, BYTE_ORDER
, 10, none
),
97 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
99 .type
= __type_integer(uint8_t, BYTE_ORDER
, 10, none
),
102 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
104 .type
= __type_integer(uint16_t, BYTE_ORDER
, 10, none
),
107 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
109 .type
= __type_integer(uint32_t, BYTE_ORDER
, 10, none
),
112 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
114 .type
= __type_integer(uint64_t, BYTE_ORDER
, 10, none
),
117 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
119 .type
= __type_float(float),
122 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
124 .type
= __type_float(double),
127 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
130 .atype
= atype_string
,
131 .u
.basic
.string
.encoding
= lttng_encode_UTF8
,
137 static const struct lttng_event_field dt_enum_field
= {
139 .type
.atype
= atype_enum
,
140 .type
.u
.basic
.enumeration
.desc
= &dt_enum_desc
,
141 .type
.u
.basic
.enumeration
.container_type
= {
142 .size
= sizeof(char) * CHAR_BIT
,
143 .alignment
= lttng_alignof(char) * CHAR_BIT
,
144 .signedness
= lttng_is_signed_type(char),
145 .reverse_byte_order
= 0,
147 .encoding
= lttng_encode_none
,
152 const struct lttng_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
154 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
156 return &dt_var_fields
[value
];
159 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_event_field
**choices
)
161 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
162 *choices
= dt_var_fields
;
166 const struct lttng_event_field
*lttng_ust_dynamic_type_tag_field(void)
168 return &dt_enum_field
;