2b3ebd6551a99f7512bde77abf21eb5de87bd2b6
[lttng-ust.git] / src / lib / lttng-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 "common/macros.h"
16 #include "common/dynamic-type.h"
17
18 #define lttng_ust_field_enum_value(_string, _value) \
19 LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
20 .struct_size = sizeof(struct lttng_ust_enum_entry), \
21 .start = { \
22 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
23 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
24 (long long) (_value) : (_value), \
25 }, \
26 .end = { \
27 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
28 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
29 (long long) (_value) : (_value), \
30 }, \
31 .string = (_string), \
32 }),
33
34 static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
35 [LTTNG_UST_DYNAMIC_TYPE_NONE] = lttng_ust_field_enum_value("_none", 0)
36 [LTTNG_UST_DYNAMIC_TYPE_S8] = lttng_ust_field_enum_value("_int8", 1)
37 [LTTNG_UST_DYNAMIC_TYPE_S16] = lttng_ust_field_enum_value("_int16", 2)
38 [LTTNG_UST_DYNAMIC_TYPE_S32] = lttng_ust_field_enum_value("_int32", 3)
39 [LTTNG_UST_DYNAMIC_TYPE_S64] = lttng_ust_field_enum_value("_int64", 4)
40 [LTTNG_UST_DYNAMIC_TYPE_U8] = lttng_ust_field_enum_value("_uint8", 5)
41 [LTTNG_UST_DYNAMIC_TYPE_U16] = lttng_ust_field_enum_value("_uint16", 6)
42 [LTTNG_UST_DYNAMIC_TYPE_U32] = lttng_ust_field_enum_value("_uint32", 7)
43 [LTTNG_UST_DYNAMIC_TYPE_U64] = lttng_ust_field_enum_value("_uint64", 8)
44 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = lttng_ust_field_enum_value("_float", 9)
45 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = lttng_ust_field_enum_value("_double", 10)
46 [LTTNG_UST_DYNAMIC_TYPE_STRING] = lttng_ust_field_enum_value("_string", 11)
47 };
48
49 static struct lttng_ust_enum_desc dt_enum_desc = {
50 .name = "dynamic_type_enum",
51 .entries = dt_enum,
52 .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
53 };
54
55 const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
56 [LTTNG_UST_DYNAMIC_TYPE_NONE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
57 .struct_size = sizeof(struct lttng_ust_event_field),
58 .name = "none",
59 .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_struct, {
60 .parent = {
61 .type = lttng_ust_type_struct,
62 },
63 .struct_size = sizeof(struct lttng_ust_type_struct),
64 .nr_fields = 0, /* empty struct */
65 .alignment = 0,
66 }),
67 .nowrite = 0,
68 }),
69 [LTTNG_UST_DYNAMIC_TYPE_S8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
70 .struct_size = sizeof(struct lttng_ust_event_field),
71 .name = "int8",
72 .type = lttng_ust_type_integer_define(int8_t, LTTNG_UST_BYTE_ORDER, 10),
73 .nowrite = 0,
74 }),
75 [LTTNG_UST_DYNAMIC_TYPE_S16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
76 .struct_size = sizeof(struct lttng_ust_event_field),
77 .name = "int16",
78 .type = lttng_ust_type_integer_define(int16_t, LTTNG_UST_BYTE_ORDER, 10),
79 .nowrite = 0,
80 }),
81 [LTTNG_UST_DYNAMIC_TYPE_S32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
82 .struct_size = sizeof(struct lttng_ust_event_field),
83 .name = "int32",
84 .type = lttng_ust_type_integer_define(int32_t, LTTNG_UST_BYTE_ORDER, 10),
85 .nowrite = 0,
86 }),
87 [LTTNG_UST_DYNAMIC_TYPE_S64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
88 .struct_size = sizeof(struct lttng_ust_event_field),
89 .name = "int64",
90 .type = lttng_ust_type_integer_define(int64_t, LTTNG_UST_BYTE_ORDER, 10),
91 .nowrite = 0,
92 }),
93 [LTTNG_UST_DYNAMIC_TYPE_U8] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
94 .struct_size = sizeof(struct lttng_ust_event_field),
95 .name = "uint8",
96 .type = lttng_ust_type_integer_define(uint8_t, LTTNG_UST_BYTE_ORDER, 10),
97 .nowrite = 0,
98 }),
99 [LTTNG_UST_DYNAMIC_TYPE_U16] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
100 .struct_size = sizeof(struct lttng_ust_event_field),
101 .name = "uint16",
102 .type = lttng_ust_type_integer_define(uint16_t, LTTNG_UST_BYTE_ORDER, 10),
103 .nowrite = 0,
104 }),
105 [LTTNG_UST_DYNAMIC_TYPE_U32] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
106 .struct_size = sizeof(struct lttng_ust_event_field),
107 .name = "uint32",
108 .type = lttng_ust_type_integer_define(uint32_t, LTTNG_UST_BYTE_ORDER, 10),
109 .nowrite = 0,
110 }),
111 [LTTNG_UST_DYNAMIC_TYPE_U64] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
112 .struct_size = sizeof(struct lttng_ust_event_field),
113 .name = "uint64",
114 .type = lttng_ust_type_integer_define(uint64_t, LTTNG_UST_BYTE_ORDER, 10),
115 .nowrite = 0,
116 }),
117 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
118 .struct_size = sizeof(struct lttng_ust_event_field),
119 .name = "float",
120 .type = lttng_ust_type_float_define(float),
121 .nowrite = 0,
122 }),
123 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
124 .struct_size = sizeof(struct lttng_ust_event_field),
125 .name = "double",
126 .type = lttng_ust_type_float_define(double),
127 .nowrite = 0,
128 }),
129 [LTTNG_UST_DYNAMIC_TYPE_STRING] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, {
130 .struct_size = sizeof(struct lttng_ust_event_field),
131 .name = "string",
132 .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_string, {
133 .parent = {
134 .type = lttng_ust_type_string,
135 },
136 .struct_size = sizeof(struct lttng_ust_type_string),
137 .encoding = lttng_ust_string_encoding_UTF8,
138 }),
139 .nowrite = 0,
140 }),
141 };
142
143 static const struct lttng_ust_event_field dt_enum_field = {
144 .struct_size = sizeof(struct lttng_ust_event_field),
145 .name = NULL,
146 .type = (struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_enum, {
147 .parent = {
148 .type = lttng_ust_type_enum,
149 },
150 .struct_size = sizeof(struct lttng_ust_type_enum),
151 .desc = &dt_enum_desc,
152 .container_type = lttng_ust_type_integer_define(char, LTTNG_UST_BYTE_ORDER, 10),
153 }),
154 .nowrite = 0,
155 };
156
157 const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value)
158 {
159 if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
160 return NULL;
161 return dt_var_fields[value];
162 }
163
164 int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field * const **choices)
165 {
166 *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
167 *choices = dt_var_fields;
168 return 0;
169 }
170
171 const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void)
172 {
173 return &dt_enum_field;
174 }
This page took 0.034194 seconds and 3 git commands to generate.