Refactoring: struct lttng_event_field
[lttng-ust.git] / liblttng-ust / lttng-ust-dynamic-type.c
1 /*
2 * SPDX-License-Identifier: LGPL-2.1-only
3 *
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * UST dynamic type implementation.
7 */
8
9 #define _LGPL_SOURCE
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stddef.h>
13 #include <inttypes.h>
14
15 #include <ust-helper.h>
16 #include <ust-dynamic-type.h>
17
18 #define ctf_enum_value(_string, _value) \
19 { \
20 .start = { \
21 .signedness = lttng_is_signed_type(__typeof__(_value)), \
22 .value = lttng_is_signed_type(__typeof__(_value)) ? \
23 (long long) (_value) : (_value), \
24 }, \
25 .end = { \
26 .signedness = lttng_is_signed_type(__typeof__(_value)), \
27 .value = lttng_is_signed_type(__typeof__(_value)) ? \
28 (long long) (_value) : (_value), \
29 }, \
30 .string = (_string), \
31 },
32
33 static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
34 [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0)
35 [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1)
36 [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2)
37 [LTTNG_UST_DYNAMIC_TYPE_S32] = ctf_enum_value("_int32", 3)
38 [LTTNG_UST_DYNAMIC_TYPE_S64] = ctf_enum_value("_int64", 4)
39 [LTTNG_UST_DYNAMIC_TYPE_U8] = ctf_enum_value("_uint8", 5)
40 [LTTNG_UST_DYNAMIC_TYPE_U16] = ctf_enum_value("_uint16", 6)
41 [LTTNG_UST_DYNAMIC_TYPE_U32] = ctf_enum_value("_uint32", 7)
42 [LTTNG_UST_DYNAMIC_TYPE_U64] = ctf_enum_value("_uint64", 8)
43 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = ctf_enum_value("_float", 9)
44 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = ctf_enum_value("_double", 10)
45 [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11)
46 };
47
48 static const struct lttng_enum_desc dt_enum_desc = {
49 .name = "dynamic_type_enum",
50 .entries = dt_enum,
51 .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
52 };
53
54 const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
55 [LTTNG_UST_DYNAMIC_TYPE_NONE] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
56 .struct_size = sizeof(struct lttng_ust_event_field),
57 .name = "none",
58 .type = {
59 .atype = atype_struct_nestable,
60 .u.struct_nestable.nr_fields = 0, /* empty struct. */
61 .u.struct_nestable.alignment = 0,
62 },
63 .nowrite = 0,
64 }),
65 [LTTNG_UST_DYNAMIC_TYPE_S8] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
66 .struct_size = sizeof(struct lttng_ust_event_field),
67 .name = "int8",
68 .type = __type_integer(int8_t, BYTE_ORDER, 10, none),
69 .nowrite = 0,
70 }),
71 [LTTNG_UST_DYNAMIC_TYPE_S16] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
72 .struct_size = sizeof(struct lttng_ust_event_field),
73 .name = "int16",
74 .type = __type_integer(int16_t, BYTE_ORDER, 10, none),
75 .nowrite = 0,
76 }),
77 [LTTNG_UST_DYNAMIC_TYPE_S32] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
78 .struct_size = sizeof(struct lttng_ust_event_field),
79 .name = "int32",
80 .type = __type_integer(int32_t, BYTE_ORDER, 10, none),
81 .nowrite = 0,
82 }),
83 [LTTNG_UST_DYNAMIC_TYPE_S64] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
84 .struct_size = sizeof(struct lttng_ust_event_field),
85 .name = "int64",
86 .type = __type_integer(int64_t, BYTE_ORDER, 10, none),
87 .nowrite = 0,
88 }),
89 [LTTNG_UST_DYNAMIC_TYPE_U8] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
90 .struct_size = sizeof(struct lttng_ust_event_field),
91 .name = "uint8",
92 .type = __type_integer(uint8_t, BYTE_ORDER, 10, none),
93 .nowrite = 0,
94 }),
95 [LTTNG_UST_DYNAMIC_TYPE_U16] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
96 .struct_size = sizeof(struct lttng_ust_event_field),
97 .name = "uint16",
98 .type = __type_integer(uint16_t, BYTE_ORDER, 10, none),
99 .nowrite = 0,
100 }),
101 [LTTNG_UST_DYNAMIC_TYPE_U32] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
102 .struct_size = sizeof(struct lttng_ust_event_field),
103 .name = "uint32",
104 .type = __type_integer(uint32_t, BYTE_ORDER, 10, none),
105 .nowrite = 0,
106 }),
107 [LTTNG_UST_DYNAMIC_TYPE_U64] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
108 .struct_size = sizeof(struct lttng_ust_event_field),
109 .name = "uint64",
110 .type = __type_integer(uint64_t, BYTE_ORDER, 10, none),
111 .nowrite = 0,
112 }),
113 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
114 .struct_size = sizeof(struct lttng_ust_event_field),
115 .name = "float",
116 .type = __type_float(float),
117 .nowrite = 0,
118 }),
119 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
120 .struct_size = sizeof(struct lttng_ust_event_field),
121 .name = "double",
122 .type = __type_float(double),
123 .nowrite = 0,
124 }),
125 [LTTNG_UST_DYNAMIC_TYPE_STRING] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, {
126 .struct_size = sizeof(struct lttng_ust_event_field),
127 .name = "string",
128 .type = {
129 .atype = atype_string,
130 .u.string.encoding = lttng_encode_UTF8,
131 },
132 .nowrite = 0,
133 }),
134 };
135
136 static const struct lttng_ust_event_field dt_enum_field = {
137 .name = NULL,
138 .type.atype = atype_enum_nestable,
139 .type.u.enum_nestable.desc = &dt_enum_desc,
140 .type.u.enum_nestable.container_type =
141 __LTTNG_COMPOUND_LITERAL(struct lttng_type,
142 __type_integer(char, BYTE_ORDER, 10, none)),
143 .nowrite = 0,
144 };
145
146 const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
147 {
148 if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
149 return NULL;
150 return dt_var_fields[value];
151 }
152
153 int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field ***choices)
154 {
155 *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
156 *choices = dt_var_fields;
157 return 0;
158 }
159
160 const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void)
161 {
162 return &dt_enum_field;
163 }
This page took 0.033826 seconds and 5 git commands to generate.