Rename "tsc" to "timestamp"
[lttng-ust.git] / liblttng-ust / lttng-ust-dynamic-type.c
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
23 #define _GNU_SOURCE
24 #define _LGPL_SOURCE
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <inttypes.h>
29
30 #include <helper.h>
31 #include <lttng/ust-dynamic-type.h>
32
33 #define ctf_enum_value(_string, _value) \
34 { \
35 .start = { \
36 .signedness = lttng_is_signed_type(__typeof__(_value)), \
37 .value = lttng_is_signed_type(__typeof__(_value)) ? \
38 (long long) (_value) : (_value), \
39 }, \
40 .end = { \
41 .signedness = lttng_is_signed_type(__typeof__(_value)), \
42 .value = lttng_is_signed_type(__typeof__(_value)) ? \
43 (long long) (_value) : (_value), \
44 }, \
45 .string = (_string), \
46 },
47
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)
61 };
62
63 static const struct lttng_enum_desc dt_enum_desc = {
64 .name = "dynamic_type_enum",
65 .entries = dt_enum,
66 .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
67 };
68
69 const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
70 [LTTNG_UST_DYNAMIC_TYPE_NONE] = {
71 .name = "none",
72 .type = {
73 .atype = atype_struct_nestable,
74 .u.struct_nestable.nr_fields = 0, /* empty struct. */
75 .u.struct_nestable.alignment = 0,
76 },
77 .nowrite = 0,
78 },
79 [LTTNG_UST_DYNAMIC_TYPE_S8] = {
80 .name = "int8",
81 .type = __type_integer(int8_t, BYTE_ORDER, 10, none),
82 .nowrite = 0,
83 },
84 [LTTNG_UST_DYNAMIC_TYPE_S16] = {
85 .name = "int16",
86 .type = __type_integer(int16_t, BYTE_ORDER, 10, none),
87 .nowrite = 0,
88 },
89 [LTTNG_UST_DYNAMIC_TYPE_S32] = {
90 .name = "int32",
91 .type = __type_integer(int32_t, BYTE_ORDER, 10, none),
92 .nowrite = 0,
93 },
94 [LTTNG_UST_DYNAMIC_TYPE_S64] = {
95 .name = "int64",
96 .type = __type_integer(int64_t, BYTE_ORDER, 10, none),
97 .nowrite = 0,
98 },
99 [LTTNG_UST_DYNAMIC_TYPE_U8] = {
100 .name = "uint8",
101 .type = __type_integer(uint8_t, BYTE_ORDER, 10, none),
102 .nowrite = 0,
103 },
104 [LTTNG_UST_DYNAMIC_TYPE_U16] = {
105 .name = "uint16",
106 .type = __type_integer(uint16_t, BYTE_ORDER, 10, none),
107 .nowrite = 0,
108 },
109 [LTTNG_UST_DYNAMIC_TYPE_U32] = {
110 .name = "uint32",
111 .type = __type_integer(uint32_t, BYTE_ORDER, 10, none),
112 .nowrite = 0,
113 },
114 [LTTNG_UST_DYNAMIC_TYPE_U64] = {
115 .name = "uint64",
116 .type = __type_integer(uint64_t, BYTE_ORDER, 10, none),
117 .nowrite = 0,
118 },
119 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = {
120 .name = "float",
121 .type = __type_float(float),
122 .nowrite = 0,
123 },
124 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = {
125 .name = "double",
126 .type = __type_float(double),
127 .nowrite = 0,
128 },
129 [LTTNG_UST_DYNAMIC_TYPE_STRING] = {
130 .name = "string",
131 .type = {
132 .atype = atype_string,
133 .u.string.encoding = lttng_encode_UTF8,
134 },
135 .nowrite = 0,
136 },
137 };
138
139 static const struct lttng_event_field dt_enum_field = {
140 .name = NULL,
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)),
146 .nowrite = 0,
147 };
148
149 const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value)
150 {
151 if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
152 return NULL;
153 return &dt_var_fields[value];
154 }
155
156 int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices)
157 {
158 *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
159 *choices = dt_var_fields;
160 return 0;
161 }
162
163 const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void)
164 {
165 return &dt_enum_field;
166 }
This page took 0.0318 seconds and 4 git commands to generate.