Commit | Line | Data |
---|---|---|
272df73e PP |
1 | #ifndef BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H |
2 | #define BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H | |
3 | ||
4 | /* | |
5 | * Babeltrace - CTF IR: Event class internal | |
6 | * | |
7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
8deee039 | 30 | #include <babeltrace/assert-pre-internal.h> |
272df73e PP |
31 | #include <babeltrace/ctf-ir/field-types.h> |
32 | #include <babeltrace/ctf-ir/fields.h> | |
33 | #include <babeltrace/babeltrace-internal.h> | |
34 | #include <babeltrace/values.h> | |
6af7ca28 | 35 | #include <babeltrace/ctf-ir/trace-internal.h> |
272df73e PP |
36 | #include <babeltrace/ctf-ir/stream-class.h> |
37 | #include <babeltrace/ctf-ir/stream.h> | |
9cf5d083 | 38 | #include <babeltrace/ctf-ir/event-class.h> |
272df73e | 39 | #include <babeltrace/object-internal.h> |
8b45963b | 40 | #include <babeltrace/assert-internal.h> |
a6918753 | 41 | #include <babeltrace/object-pool-internal.h> |
272df73e PP |
42 | #include <glib.h> |
43 | ||
8deee039 | 44 | struct bt_event_class_common { |
272df73e | 45 | struct bt_object base; |
8deee039 PP |
46 | struct bt_field_type_common *context_field_type; |
47 | struct bt_field_type_common *payload_field_type; | |
272df73e PP |
48 | int frozen; |
49 | ||
50 | /* | |
51 | * This flag indicates if the event class is valid. A valid | |
52 | * event class is _always_ frozen. However, an event class | |
53 | * may be frozen, but not valid yet. This is okay, as long as | |
54 | * no events are created out of this event class. | |
55 | */ | |
56 | int valid; | |
5990dd44 | 57 | |
9cf5d083 PP |
58 | /* Attributes */ |
59 | GString *name; | |
5990dd44 | 60 | int64_t id; |
8deee039 | 61 | int log_level; |
9cf5d083 | 62 | GString *emf_uri; |
272df73e PP |
63 | }; |
64 | ||
8deee039 PP |
65 | struct bt_event_class { |
66 | struct bt_event_class_common common; | |
a6918753 PP |
67 | |
68 | /* Pool of `struct bt_event *` */ | |
69 | struct bt_object_pool event_pool; | |
8deee039 PP |
70 | }; |
71 | ||
272df73e | 72 | BT_HIDDEN |
839d52a5 | 73 | void bt_event_class_freeze(struct bt_event_class *event_class); |
272df73e PP |
74 | |
75 | BT_HIDDEN | |
8deee039 | 76 | void bt_event_class_common_freeze(struct bt_event_class_common *event_class); |
272df73e PP |
77 | |
78 | BT_HIDDEN | |
8deee039 PP |
79 | void bt_event_class_common_set_native_byte_order( |
80 | struct bt_event_class_common *event_class, int byte_order); | |
272df73e | 81 | |
dc3fffef | 82 | static inline |
8deee039 PP |
83 | struct bt_stream_class_common *bt_event_class_common_borrow_stream_class( |
84 | struct bt_event_class_common *event_class) | |
dc3fffef | 85 | { |
8b45963b | 86 | BT_ASSERT(event_class); |
1d7bf349 | 87 | return (void *) bt_object_borrow_parent(&event_class->base); |
dc3fffef PP |
88 | } |
89 | ||
8deee039 PP |
90 | typedef struct bt_field_type_common *(*bt_field_type_structure_create_func)(); |
91 | ||
92 | BT_HIDDEN | |
93 | int bt_event_class_common_initialize(struct bt_event_class_common *event_class, | |
94 | const char *name, bt_object_release_func release_func, | |
95 | bt_field_type_structure_create_func ft_struct_create_func); | |
96 | ||
97 | BT_HIDDEN | |
98 | void bt_event_class_common_finalize(struct bt_object *obj); | |
99 | ||
100 | BT_HIDDEN | |
101 | int bt_event_class_common_validate_single_clock_class( | |
102 | struct bt_event_class_common *event_class, | |
103 | struct bt_clock_class **expected_clock_class); | |
104 | ||
105 | static inline | |
106 | const char *bt_event_class_common_get_name( | |
107 | struct bt_event_class_common *event_class) | |
108 | { | |
109 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
110 | BT_ASSERT(event_class->name); | |
111 | return event_class->name->str; | |
112 | } | |
113 | ||
114 | static inline | |
115 | int64_t bt_event_class_common_get_id( | |
116 | struct bt_event_class_common *event_class) | |
117 | { | |
118 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
119 | return event_class->id; | |
120 | } | |
121 | ||
122 | static inline | |
123 | int bt_event_class_common_set_id( | |
124 | struct bt_event_class_common *event_class, uint64_t id_param) | |
9cf5d083 | 125 | { |
8deee039 PP |
126 | int ret = 0; |
127 | int64_t id = (int64_t) id_param; | |
128 | ||
129 | if (!event_class) { | |
130 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
131 | ret = -1; | |
132 | goto end; | |
133 | } | |
134 | ||
135 | if (event_class->frozen) { | |
136 | BT_LOGW("Invalid parameter: event class is frozen: " | |
137 | "addr=%p, name=\"%s\", id=%" PRId64, | |
138 | event_class, | |
139 | bt_event_class_common_get_name(event_class), | |
140 | bt_event_class_common_get_id(event_class)); | |
141 | ret = -1; | |
142 | goto end; | |
143 | } | |
144 | ||
145 | if (id < 0) { | |
146 | BT_LOGW("Invalid parameter: invalid event class's ID: " | |
147 | "addr=%p, name=\"%s\", id=%" PRIu64, | |
148 | event_class, | |
149 | bt_event_class_common_get_name(event_class), | |
150 | id_param); | |
151 | ret = -1; | |
152 | goto end; | |
153 | } | |
154 | ||
155 | event_class->id = id; | |
156 | BT_LOGV("Set event class's ID: " | |
157 | "addr=%p, name=\"%s\", id=%" PRId64, | |
158 | event_class, bt_event_class_common_get_name(event_class), id); | |
159 | ||
160 | end: | |
161 | return ret; | |
162 | } | |
163 | ||
164 | static inline | |
165 | int bt_event_class_common_get_log_level( | |
166 | struct bt_event_class_common *event_class) | |
167 | { | |
168 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
169 | return event_class->log_level; | |
170 | } | |
171 | ||
172 | static inline | |
173 | int bt_event_class_common_set_log_level( | |
174 | struct bt_event_class_common *event_class, int log_level) | |
175 | { | |
176 | int ret = 0; | |
177 | ||
178 | if (!event_class) { | |
179 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
180 | ret = -1; | |
181 | goto end; | |
182 | } | |
183 | ||
184 | if (event_class->frozen) { | |
185 | BT_LOGW("Invalid parameter: event class is frozen: " | |
186 | "addr=%p, name=\"%s\", id=%" PRId64, | |
187 | event_class, | |
188 | bt_event_class_common_get_name(event_class), | |
189 | bt_event_class_common_get_id(event_class)); | |
190 | ret = -1; | |
191 | goto end; | |
192 | } | |
193 | ||
194 | switch (log_level) { | |
839d52a5 | 195 | case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED: |
839d52a5 | 196 | case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY: |
839d52a5 | 197 | case BT_EVENT_CLASS_LOG_LEVEL_ALERT: |
839d52a5 | 198 | case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL: |
839d52a5 | 199 | case BT_EVENT_CLASS_LOG_LEVEL_ERROR: |
839d52a5 | 200 | case BT_EVENT_CLASS_LOG_LEVEL_WARNING: |
839d52a5 | 201 | case BT_EVENT_CLASS_LOG_LEVEL_NOTICE: |
839d52a5 | 202 | case BT_EVENT_CLASS_LOG_LEVEL_INFO: |
839d52a5 | 203 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: |
839d52a5 | 204 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: |
839d52a5 | 205 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: |
839d52a5 | 206 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: |
839d52a5 | 207 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: |
839d52a5 | 208 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: |
839d52a5 | 209 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: |
839d52a5 | 210 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG: |
8deee039 | 211 | break; |
9cf5d083 | 212 | default: |
8deee039 PP |
213 | BT_LOGW("Invalid parameter: unknown event class log level: " |
214 | "addr=%p, name=\"%s\", id=%" PRId64 ", log-level=%d", | |
215 | event_class, bt_event_class_common_get_name(event_class), | |
216 | bt_event_class_common_get_id(event_class), log_level); | |
217 | ret = -1; | |
218 | goto end; | |
9cf5d083 | 219 | } |
9cf5d083 | 220 | |
8deee039 PP |
221 | event_class->log_level = log_level; |
222 | BT_LOGV("Set event class's log level: " | |
223 | "addr=%p, name=\"%s\", id=%" PRId64 ", log-level=%s", | |
224 | event_class, bt_event_class_common_get_name(event_class), | |
225 | bt_event_class_common_get_id(event_class), | |
226 | bt_common_event_class_log_level_string(log_level)); | |
227 | ||
228 | end: | |
229 | return ret; | |
230 | } | |
231 | ||
232 | static inline | |
233 | const char *bt_event_class_common_get_emf_uri( | |
234 | struct bt_event_class_common *event_class) | |
235 | { | |
236 | const char *emf_uri = NULL; | |
237 | ||
238 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
239 | ||
240 | if (event_class->emf_uri->len > 0) { | |
241 | emf_uri = event_class->emf_uri->str; | |
242 | } | |
243 | ||
244 | return emf_uri; | |
245 | } | |
246 | ||
247 | static inline | |
248 | int bt_event_class_common_set_emf_uri( | |
249 | struct bt_event_class_common *event_class, | |
250 | const char *emf_uri) | |
251 | { | |
252 | int ret = 0; | |
253 | ||
254 | if (!event_class) { | |
255 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
256 | ret = -1; | |
257 | goto end; | |
258 | } | |
259 | ||
260 | if (emf_uri && strlen(emf_uri) == 0) { | |
261 | BT_LOGW_STR("Invalid parameter: EMF URI is empty."); | |
262 | ret = -1; | |
263 | goto end; | |
264 | } | |
265 | ||
266 | if (event_class->frozen) { | |
267 | BT_LOGW("Invalid parameter: event class is frozen: " | |
268 | "addr=%p, name=\"%s\", id=%" PRId64, | |
269 | event_class, bt_event_class_common_get_name(event_class), | |
270 | bt_event_class_common_get_id(event_class)); | |
271 | ret = -1; | |
272 | goto end; | |
273 | } | |
274 | ||
275 | if (emf_uri) { | |
276 | g_string_assign(event_class->emf_uri, emf_uri); | |
277 | BT_LOGV("Set event class's EMF URI: " | |
278 | "addr=%p, name=\"%s\", id=%" PRId64 ", emf-uri=\"%s\"", | |
279 | event_class, bt_event_class_common_get_name(event_class), | |
280 | bt_event_class_common_get_id(event_class), emf_uri); | |
281 | } else { | |
282 | g_string_assign(event_class->emf_uri, ""); | |
283 | BT_LOGV("Reset event class's EMF URI: " | |
284 | "addr=%p, name=\"%s\", id=%" PRId64, | |
285 | event_class, bt_event_class_common_get_name(event_class), | |
286 | bt_event_class_common_get_id(event_class)); | |
287 | } | |
288 | ||
289 | end: | |
290 | return ret; | |
291 | } | |
292 | ||
293 | static inline | |
5fe68922 | 294 | struct bt_field_type_common *bt_event_class_common_borrow_context_field_type( |
8deee039 PP |
295 | struct bt_event_class_common *event_class) |
296 | { | |
297 | struct bt_field_type_common *context_ft = NULL; | |
298 | ||
299 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
300 | ||
301 | if (!event_class->context_field_type) { | |
302 | BT_LOGV("Event class has no context field type: " | |
303 | "addr=%p, name=\"%s\", id=%" PRId64, | |
304 | event_class, bt_event_class_common_get_name(event_class), | |
305 | bt_event_class_common_get_id(event_class)); | |
306 | goto end; | |
307 | } | |
308 | ||
5fe68922 | 309 | context_ft = event_class->context_field_type; |
8deee039 PP |
310 | |
311 | end: | |
312 | return context_ft; | |
313 | } | |
314 | ||
315 | static inline | |
316 | int bt_event_class_common_set_context_field_type( | |
317 | struct bt_event_class_common *event_class, | |
318 | struct bt_field_type_common *context_ft) | |
319 | { | |
320 | int ret = 0; | |
321 | ||
322 | if (!event_class) { | |
323 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
324 | ret = -1; | |
325 | goto end; | |
326 | } | |
327 | ||
328 | if (event_class->frozen) { | |
329 | BT_LOGW("Invalid parameter: event class is frozen: " | |
330 | "addr=%p, name=\"%s\", id=%" PRId64, | |
331 | event_class, bt_event_class_common_get_name(event_class), | |
332 | bt_event_class_common_get_id(event_class)); | |
333 | ret = -1; | |
334 | goto end; | |
335 | } | |
336 | ||
337 | if (context_ft && bt_field_type_common_get_type_id(context_ft) != | |
338 | BT_FIELD_TYPE_ID_STRUCT) { | |
339 | BT_LOGW("Invalid parameter: event class's context field type must be a structure: " | |
340 | "addr=%p, name=\"%s\", id=%" PRId64 ", " | |
341 | "context-ft-id=%s", | |
342 | event_class, bt_event_class_common_get_name(event_class), | |
343 | bt_event_class_common_get_id(event_class), | |
344 | bt_common_field_type_id_string( | |
345 | bt_field_type_common_get_type_id(context_ft))); | |
346 | ret = -1; | |
347 | goto end; | |
348 | } | |
349 | ||
350 | bt_put(event_class->context_field_type); | |
351 | event_class->context_field_type = bt_get(context_ft); | |
352 | BT_LOGV("Set event class's context field type: " | |
353 | "event-class-addr=%p, event-class-name=\"%s\", " | |
354 | "event-class-id=%" PRId64 ", context-ft-addr=%p", | |
355 | event_class, bt_event_class_common_get_name(event_class), | |
356 | bt_event_class_common_get_id(event_class), context_ft); | |
357 | ||
358 | end: | |
359 | return ret; | |
360 | } | |
361 | ||
362 | static inline | |
5fe68922 | 363 | struct bt_field_type_common *bt_event_class_common_borrow_payload_field_type( |
8deee039 PP |
364 | struct bt_event_class_common *event_class) |
365 | { | |
366 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
5fe68922 | 367 | return event_class->payload_field_type; |
8deee039 PP |
368 | } |
369 | ||
370 | static inline | |
371 | int bt_event_class_common_set_payload_field_type( | |
372 | struct bt_event_class_common *event_class, | |
373 | struct bt_field_type_common *payload_ft) | |
374 | { | |
375 | int ret = 0; | |
376 | ||
377 | if (!event_class) { | |
378 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
379 | ret = -1; | |
380 | goto end; | |
381 | } | |
382 | ||
383 | if (payload_ft && bt_field_type_common_get_type_id(payload_ft) != | |
384 | BT_FIELD_TYPE_ID_STRUCT) { | |
385 | BT_LOGW("Invalid parameter: event class's payload field type must be a structure: " | |
386 | "addr=%p, name=\"%s\", id=%" PRId64 ", " | |
387 | "payload-ft-addr=%p, payload-ft-id=%s", | |
388 | event_class, bt_event_class_common_get_name(event_class), | |
389 | bt_event_class_common_get_id(event_class), payload_ft, | |
390 | bt_common_field_type_id_string( | |
391 | bt_field_type_common_get_type_id(payload_ft))); | |
392 | ret = -1; | |
393 | goto end; | |
394 | } | |
395 | ||
396 | bt_put(event_class->payload_field_type); | |
397 | event_class->payload_field_type = bt_get(payload_ft); | |
398 | BT_LOGV("Set event class's payload field type: " | |
399 | "event-class-addr=%p, event-class-name=\"%s\", " | |
400 | "event-class-id=%" PRId64 ", payload-ft-addr=%p", | |
401 | event_class, bt_event_class_common_get_name(event_class), | |
402 | bt_event_class_common_get_id(event_class), payload_ft); | |
403 | end: | |
404 | return ret; | |
405 | } | |
8c4a29ba | 406 | |
272df73e | 407 | #endif /* BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H */ |