Commit | Line | Data |
---|---|---|
16ca5ff0 PP |
1 | #ifndef BABELTRACE_CTF_WRITER_UTILS_INTERNAL_H |
2 | #define BABELTRACE_CTF_WRITER_UTILS_INTERNAL_H | |
3 | ||
4 | /* | |
16ca5ff0 PP |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
3fadfbc0 MJ |
24 | #include <babeltrace2/babeltrace-internal.h> |
25 | #include <babeltrace2/ctf-writer/field-types.h> | |
26 | #include <babeltrace2/ctf-writer/field-path-internal.h> | |
27 | #include <babeltrace2/ctf-writer/event.h> | |
16ca5ff0 PP |
28 | #include <stdint.h> |
29 | ||
30 | #define BT_CTF_TO_COMMON(_obj) (&(_obj)->common) | |
31 | #define BT_CTF_FROM_COMMON(_obj) ((void *) _obj) | |
32 | ||
33 | struct bt_ctf_search_query { | |
34 | gpointer value; | |
35 | int found; | |
36 | }; | |
37 | ||
38 | BT_HIDDEN | |
39 | const char *bt_ctf_get_byte_order_string(enum bt_ctf_byte_order byte_order); | |
40 | ||
41 | static inline | |
42 | const char *bt_ctf_field_type_id_string(enum bt_ctf_field_type_id type_id) | |
43 | { | |
44 | switch (type_id) { | |
45 | case BT_CTF_FIELD_TYPE_ID_UNKNOWN: | |
46 | return "BT_CTF_FIELD_TYPE_ID_UNKNOWN"; | |
47 | case BT_CTF_FIELD_TYPE_ID_INTEGER: | |
48 | return "BT_CTF_FIELD_TYPE_ID_INTEGER"; | |
49 | case BT_CTF_FIELD_TYPE_ID_FLOAT: | |
50 | return "BT_CTF_FIELD_TYPE_ID_FLOAT"; | |
51 | case BT_CTF_FIELD_TYPE_ID_ENUM: | |
52 | return "BT_CTF_FIELD_TYPE_ID_ENUM"; | |
53 | case BT_CTF_FIELD_TYPE_ID_STRING: | |
54 | return "BT_CTF_FIELD_TYPE_ID_STRING"; | |
55 | case BT_CTF_FIELD_TYPE_ID_STRUCT: | |
56 | return "BT_CTF_FIELD_TYPE_ID_STRUCT"; | |
57 | case BT_CTF_FIELD_TYPE_ID_ARRAY: | |
58 | return "BT_CTF_FIELD_TYPE_ID_ARRAY"; | |
59 | case BT_CTF_FIELD_TYPE_ID_SEQUENCE: | |
60 | return "BT_CTF_FIELD_TYPE_ID_SEQUENCE"; | |
61 | case BT_CTF_FIELD_TYPE_ID_VARIANT: | |
62 | return "BT_CTF_FIELD_TYPE_ID_VARIANT"; | |
63 | default: | |
64 | return "(unknown)"; | |
65 | } | |
66 | }; | |
67 | ||
68 | static inline | |
69 | const char *bt_ctf_byte_order_string(enum bt_ctf_byte_order bo) | |
70 | { | |
71 | switch (bo) { | |
72 | case BT_CTF_BYTE_ORDER_UNKNOWN: | |
73 | return "BT_CTF_BYTE_ORDER_UNKNOWN"; | |
74 | case BT_CTF_BYTE_ORDER_UNSPECIFIED: | |
75 | return "BT_CTF_BYTE_ORDER_UNSPECIFIED"; | |
76 | case BT_CTF_BYTE_ORDER_NATIVE: | |
77 | return "BT_CTF_BYTE_ORDER_NATIVE"; | |
78 | case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN: | |
79 | return "BT_CTF_BYTE_ORDER_LITTLE_ENDIAN"; | |
80 | case BT_CTF_BYTE_ORDER_BIG_ENDIAN: | |
81 | return "BT_CTF_BYTE_ORDER_BIG_ENDIAN"; | |
82 | case BT_CTF_BYTE_ORDER_NETWORK: | |
83 | return "BT_CTF_BYTE_ORDER_NETWORK"; | |
84 | default: | |
85 | return "(unknown)"; | |
86 | } | |
87 | }; | |
88 | ||
89 | static inline | |
90 | const char *bt_ctf_string_encoding_string(enum bt_ctf_string_encoding encoding) | |
91 | { | |
92 | switch (encoding) { | |
93 | case BT_CTF_STRING_ENCODING_UNKNOWN: | |
94 | return "BT_CTF_STRING_ENCODING_UNKNOWN"; | |
95 | case BT_CTF_STRING_ENCODING_NONE: | |
96 | return "BT_CTF_STRING_ENCODING_NONE"; | |
97 | case BT_CTF_STRING_ENCODING_UTF8: | |
98 | return "BT_CTF_STRING_ENCODING_UTF8"; | |
99 | case BT_CTF_STRING_ENCODING_ASCII: | |
100 | return "BT_CTF_STRING_ENCODING_ASCII"; | |
101 | default: | |
102 | return "(unknown)"; | |
103 | } | |
104 | }; | |
105 | ||
106 | static inline | |
107 | const char *bt_ctf_integer_base_string(enum bt_ctf_integer_base base) | |
108 | { | |
109 | switch (base) { | |
110 | case BT_CTF_INTEGER_BASE_UNKNOWN: | |
111 | return "BT_CTF_INTEGER_BASE_UNKNOWN"; | |
112 | case BT_CTF_INTEGER_BASE_UNSPECIFIED: | |
113 | return "BT_CTF_INTEGER_BASE_UNSPECIFIED"; | |
114 | case BT_CTF_INTEGER_BASE_BINARY: | |
115 | return "BT_CTF_INTEGER_BASE_BINARY"; | |
116 | case BT_CTF_INTEGER_BASE_OCTAL: | |
117 | return "BT_CTF_INTEGER_BASE_OCTAL"; | |
118 | case BT_CTF_INTEGER_BASE_DECIMAL: | |
119 | return "BT_CTF_INTEGER_BASE_DECIMAL"; | |
120 | case BT_CTF_INTEGER_BASE_HEXADECIMAL: | |
121 | return "BT_CTF_INTEGER_BASE_HEXADECIMAL"; | |
122 | default: | |
123 | return "(unknown)"; | |
124 | } | |
125 | } | |
126 | ||
127 | static inline | |
128 | const char *bt_ctf_scope_string(enum bt_ctf_scope scope) | |
129 | { | |
130 | switch (scope) { | |
131 | case BT_CTF_SCOPE_UNKNOWN: | |
132 | return "BT_CTF_SCOPE_UNKNOWN"; | |
133 | case BT_CTF_SCOPE_TRACE_PACKET_HEADER: | |
134 | return "BT_CTF_SCOPE_TRACE_PACKET_HEADER"; | |
135 | case BT_CTF_SCOPE_STREAM_PACKET_CONTEXT: | |
136 | return "BT_CTF_SCOPE_STREAM_PACKET_CONTEXT"; | |
137 | case BT_CTF_SCOPE_STREAM_EVENT_HEADER: | |
138 | return "BT_CTF_SCOPE_STREAM_EVENT_HEADER"; | |
139 | case BT_CTF_SCOPE_STREAM_EVENT_CONTEXT: | |
140 | return "BT_CTF_SCOPE_STREAM_EVENT_CONTEXT"; | |
141 | case BT_CTF_SCOPE_EVENT_CONTEXT: | |
142 | return "BT_CTF_SCOPE_EVENT_CONTEXT"; | |
143 | case BT_CTF_SCOPE_EVENT_PAYLOAD: | |
144 | return "BT_CTF_SCOPE_EVENT_PAYLOAD"; | |
145 | case BT_CTF_SCOPE_ENV: | |
146 | return "BT_CTF_SCOPE_ENV"; | |
147 | default: | |
148 | return "(unknown)"; | |
149 | } | |
150 | } | |
151 | ||
152 | static inline | |
153 | const char *bt_ctf_event_class_log_level_string( | |
154 | enum bt_ctf_event_class_log_level level) | |
155 | { | |
156 | switch (level) { | |
157 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN: | |
158 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN"; | |
159 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED: | |
160 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED"; | |
161 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY: | |
162 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY"; | |
163 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT: | |
164 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_ALERT"; | |
165 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL: | |
166 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL"; | |
167 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR: | |
168 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_ERROR"; | |
169 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING: | |
170 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_WARNING"; | |
171 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE: | |
172 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_NOTICE"; | |
173 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO: | |
174 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_INFO"; | |
175 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: | |
176 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM"; | |
177 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: | |
178 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM"; | |
179 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: | |
180 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS"; | |
181 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: | |
182 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE"; | |
183 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: | |
184 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT"; | |
185 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: | |
186 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION"; | |
187 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: | |
188 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE"; | |
189 | case BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG: | |
190 | return "BT_CTF_EVENT_CLASS_LOG_LEVEL_DEBUG"; | |
191 | default: | |
192 | return "(unknown)"; | |
193 | } | |
194 | }; | |
195 | ||
196 | static inline | |
197 | GString *bt_ctf_field_path_string(struct bt_ctf_field_path *path) | |
198 | { | |
199 | GString *str = g_string_new(NULL); | |
200 | size_t i; | |
201 | ||
202 | BT_ASSERT(path); | |
203 | ||
204 | if (!str) { | |
205 | goto end; | |
206 | } | |
207 | ||
208 | g_string_append_printf(str, "[%s", bt_common_scope_string( | |
209 | bt_ctf_field_path_get_root_scope(path))); | |
210 | ||
211 | for (i = 0; i < bt_ctf_field_path_get_index_count(path); i++) { | |
212 | int index = bt_ctf_field_path_get_index(path, i); | |
213 | ||
214 | g_string_append_printf(str, ", %d", index); | |
215 | } | |
216 | ||
217 | g_string_append(str, "]"); | |
218 | ||
219 | end: | |
220 | return str; | |
221 | } | |
222 | ||
223 | #endif /* BABELTRACE_CTF_WRITER_UTILS_INTERNAL_H */ |