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 | ||
a6918753 PP |
105 | BT_HIDDEN |
106 | int bt_event_class_update_event_pool_clock_values( | |
107 | struct bt_event_class *event_class); | |
108 | ||
8deee039 PP |
109 | static inline |
110 | const char *bt_event_class_common_get_name( | |
111 | struct bt_event_class_common *event_class) | |
112 | { | |
113 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
114 | BT_ASSERT(event_class->name); | |
115 | return event_class->name->str; | |
116 | } | |
117 | ||
118 | static inline | |
119 | int64_t bt_event_class_common_get_id( | |
120 | struct bt_event_class_common *event_class) | |
121 | { | |
122 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
123 | return event_class->id; | |
124 | } | |
125 | ||
126 | static inline | |
127 | int bt_event_class_common_set_id( | |
128 | struct bt_event_class_common *event_class, uint64_t id_param) | |
9cf5d083 | 129 | { |
8deee039 PP |
130 | int ret = 0; |
131 | int64_t id = (int64_t) id_param; | |
132 | ||
133 | if (!event_class) { | |
134 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
135 | ret = -1; | |
136 | goto end; | |
137 | } | |
138 | ||
139 | if (event_class->frozen) { | |
140 | BT_LOGW("Invalid parameter: event class is frozen: " | |
141 | "addr=%p, name=\"%s\", id=%" PRId64, | |
142 | event_class, | |
143 | bt_event_class_common_get_name(event_class), | |
144 | bt_event_class_common_get_id(event_class)); | |
145 | ret = -1; | |
146 | goto end; | |
147 | } | |
148 | ||
149 | if (id < 0) { | |
150 | BT_LOGW("Invalid parameter: invalid event class's ID: " | |
151 | "addr=%p, name=\"%s\", id=%" PRIu64, | |
152 | event_class, | |
153 | bt_event_class_common_get_name(event_class), | |
154 | id_param); | |
155 | ret = -1; | |
156 | goto end; | |
157 | } | |
158 | ||
159 | event_class->id = id; | |
160 | BT_LOGV("Set event class's ID: " | |
161 | "addr=%p, name=\"%s\", id=%" PRId64, | |
162 | event_class, bt_event_class_common_get_name(event_class), id); | |
163 | ||
164 | end: | |
165 | return ret; | |
166 | } | |
167 | ||
168 | static inline | |
169 | int bt_event_class_common_get_log_level( | |
170 | struct bt_event_class_common *event_class) | |
171 | { | |
172 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
173 | return event_class->log_level; | |
174 | } | |
175 | ||
176 | static inline | |
177 | int bt_event_class_common_set_log_level( | |
178 | struct bt_event_class_common *event_class, int log_level) | |
179 | { | |
180 | int ret = 0; | |
181 | ||
182 | if (!event_class) { | |
183 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
184 | ret = -1; | |
185 | goto end; | |
186 | } | |
187 | ||
188 | if (event_class->frozen) { | |
189 | BT_LOGW("Invalid parameter: event class is frozen: " | |
190 | "addr=%p, name=\"%s\", id=%" PRId64, | |
191 | event_class, | |
192 | bt_event_class_common_get_name(event_class), | |
193 | bt_event_class_common_get_id(event_class)); | |
194 | ret = -1; | |
195 | goto end; | |
196 | } | |
197 | ||
198 | switch (log_level) { | |
839d52a5 | 199 | case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED: |
839d52a5 | 200 | case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY: |
839d52a5 | 201 | case BT_EVENT_CLASS_LOG_LEVEL_ALERT: |
839d52a5 | 202 | case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL: |
839d52a5 | 203 | case BT_EVENT_CLASS_LOG_LEVEL_ERROR: |
839d52a5 | 204 | case BT_EVENT_CLASS_LOG_LEVEL_WARNING: |
839d52a5 | 205 | case BT_EVENT_CLASS_LOG_LEVEL_NOTICE: |
839d52a5 | 206 | case BT_EVENT_CLASS_LOG_LEVEL_INFO: |
839d52a5 | 207 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM: |
839d52a5 | 208 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM: |
839d52a5 | 209 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS: |
839d52a5 | 210 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE: |
839d52a5 | 211 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT: |
839d52a5 | 212 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION: |
839d52a5 | 213 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE: |
839d52a5 | 214 | case BT_EVENT_CLASS_LOG_LEVEL_DEBUG: |
8deee039 | 215 | break; |
9cf5d083 | 216 | default: |
8deee039 PP |
217 | BT_LOGW("Invalid parameter: unknown event class log level: " |
218 | "addr=%p, name=\"%s\", id=%" PRId64 ", log-level=%d", | |
219 | event_class, bt_event_class_common_get_name(event_class), | |
220 | bt_event_class_common_get_id(event_class), log_level); | |
221 | ret = -1; | |
222 | goto end; | |
9cf5d083 | 223 | } |
9cf5d083 | 224 | |
8deee039 PP |
225 | event_class->log_level = log_level; |
226 | BT_LOGV("Set event class's log level: " | |
227 | "addr=%p, name=\"%s\", id=%" PRId64 ", log-level=%s", | |
228 | event_class, bt_event_class_common_get_name(event_class), | |
229 | bt_event_class_common_get_id(event_class), | |
230 | bt_common_event_class_log_level_string(log_level)); | |
231 | ||
232 | end: | |
233 | return ret; | |
234 | } | |
235 | ||
236 | static inline | |
237 | const char *bt_event_class_common_get_emf_uri( | |
238 | struct bt_event_class_common *event_class) | |
239 | { | |
240 | const char *emf_uri = NULL; | |
241 | ||
242 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
243 | ||
244 | if (event_class->emf_uri->len > 0) { | |
245 | emf_uri = event_class->emf_uri->str; | |
246 | } | |
247 | ||
248 | return emf_uri; | |
249 | } | |
250 | ||
251 | static inline | |
252 | int bt_event_class_common_set_emf_uri( | |
253 | struct bt_event_class_common *event_class, | |
254 | const char *emf_uri) | |
255 | { | |
256 | int ret = 0; | |
257 | ||
258 | if (!event_class) { | |
259 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
260 | ret = -1; | |
261 | goto end; | |
262 | } | |
263 | ||
264 | if (emf_uri && strlen(emf_uri) == 0) { | |
265 | BT_LOGW_STR("Invalid parameter: EMF URI is empty."); | |
266 | ret = -1; | |
267 | goto end; | |
268 | } | |
269 | ||
270 | if (event_class->frozen) { | |
271 | BT_LOGW("Invalid parameter: event class is frozen: " | |
272 | "addr=%p, name=\"%s\", id=%" PRId64, | |
273 | event_class, bt_event_class_common_get_name(event_class), | |
274 | bt_event_class_common_get_id(event_class)); | |
275 | ret = -1; | |
276 | goto end; | |
277 | } | |
278 | ||
279 | if (emf_uri) { | |
280 | g_string_assign(event_class->emf_uri, emf_uri); | |
281 | BT_LOGV("Set event class's EMF URI: " | |
282 | "addr=%p, name=\"%s\", id=%" PRId64 ", emf-uri=\"%s\"", | |
283 | event_class, bt_event_class_common_get_name(event_class), | |
284 | bt_event_class_common_get_id(event_class), emf_uri); | |
285 | } else { | |
286 | g_string_assign(event_class->emf_uri, ""); | |
287 | BT_LOGV("Reset event class's EMF URI: " | |
288 | "addr=%p, name=\"%s\", id=%" PRId64, | |
289 | event_class, bt_event_class_common_get_name(event_class), | |
290 | bt_event_class_common_get_id(event_class)); | |
291 | } | |
292 | ||
293 | end: | |
294 | return ret; | |
295 | } | |
296 | ||
297 | static inline | |
5fe68922 | 298 | struct bt_field_type_common *bt_event_class_common_borrow_context_field_type( |
8deee039 PP |
299 | struct bt_event_class_common *event_class) |
300 | { | |
301 | struct bt_field_type_common *context_ft = NULL; | |
302 | ||
303 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
304 | ||
305 | if (!event_class->context_field_type) { | |
306 | BT_LOGV("Event class has no context field type: " | |
307 | "addr=%p, name=\"%s\", id=%" PRId64, | |
308 | event_class, bt_event_class_common_get_name(event_class), | |
309 | bt_event_class_common_get_id(event_class)); | |
310 | goto end; | |
311 | } | |
312 | ||
5fe68922 | 313 | context_ft = event_class->context_field_type; |
8deee039 PP |
314 | |
315 | end: | |
316 | return context_ft; | |
317 | } | |
318 | ||
319 | static inline | |
320 | int bt_event_class_common_set_context_field_type( | |
321 | struct bt_event_class_common *event_class, | |
322 | struct bt_field_type_common *context_ft) | |
323 | { | |
324 | int ret = 0; | |
325 | ||
326 | if (!event_class) { | |
327 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
328 | ret = -1; | |
329 | goto end; | |
330 | } | |
331 | ||
332 | if (event_class->frozen) { | |
333 | BT_LOGW("Invalid parameter: event class is frozen: " | |
334 | "addr=%p, name=\"%s\", id=%" PRId64, | |
335 | event_class, bt_event_class_common_get_name(event_class), | |
336 | bt_event_class_common_get_id(event_class)); | |
337 | ret = -1; | |
338 | goto end; | |
339 | } | |
340 | ||
341 | if (context_ft && bt_field_type_common_get_type_id(context_ft) != | |
342 | BT_FIELD_TYPE_ID_STRUCT) { | |
343 | BT_LOGW("Invalid parameter: event class's context field type must be a structure: " | |
344 | "addr=%p, name=\"%s\", id=%" PRId64 ", " | |
345 | "context-ft-id=%s", | |
346 | event_class, bt_event_class_common_get_name(event_class), | |
347 | bt_event_class_common_get_id(event_class), | |
348 | bt_common_field_type_id_string( | |
349 | bt_field_type_common_get_type_id(context_ft))); | |
350 | ret = -1; | |
351 | goto end; | |
352 | } | |
353 | ||
354 | bt_put(event_class->context_field_type); | |
355 | event_class->context_field_type = bt_get(context_ft); | |
356 | BT_LOGV("Set event class's context field type: " | |
357 | "event-class-addr=%p, event-class-name=\"%s\", " | |
358 | "event-class-id=%" PRId64 ", context-ft-addr=%p", | |
359 | event_class, bt_event_class_common_get_name(event_class), | |
360 | bt_event_class_common_get_id(event_class), context_ft); | |
361 | ||
362 | end: | |
363 | return ret; | |
364 | } | |
365 | ||
366 | static inline | |
5fe68922 | 367 | struct bt_field_type_common *bt_event_class_common_borrow_payload_field_type( |
8deee039 PP |
368 | struct bt_event_class_common *event_class) |
369 | { | |
370 | BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); | |
5fe68922 | 371 | return event_class->payload_field_type; |
8deee039 PP |
372 | } |
373 | ||
374 | static inline | |
375 | int bt_event_class_common_set_payload_field_type( | |
376 | struct bt_event_class_common *event_class, | |
377 | struct bt_field_type_common *payload_ft) | |
378 | { | |
379 | int ret = 0; | |
380 | ||
381 | if (!event_class) { | |
382 | BT_LOGW_STR("Invalid parameter: event class is NULL."); | |
383 | ret = -1; | |
384 | goto end; | |
385 | } | |
386 | ||
387 | if (payload_ft && bt_field_type_common_get_type_id(payload_ft) != | |
388 | BT_FIELD_TYPE_ID_STRUCT) { | |
389 | BT_LOGW("Invalid parameter: event class's payload field type must be a structure: " | |
390 | "addr=%p, name=\"%s\", id=%" PRId64 ", " | |
391 | "payload-ft-addr=%p, payload-ft-id=%s", | |
392 | event_class, bt_event_class_common_get_name(event_class), | |
393 | bt_event_class_common_get_id(event_class), payload_ft, | |
394 | bt_common_field_type_id_string( | |
395 | bt_field_type_common_get_type_id(payload_ft))); | |
396 | ret = -1; | |
397 | goto end; | |
398 | } | |
399 | ||
400 | bt_put(event_class->payload_field_type); | |
401 | event_class->payload_field_type = bt_get(payload_ft); | |
402 | BT_LOGV("Set event class's payload field type: " | |
403 | "event-class-addr=%p, event-class-name=\"%s\", " | |
404 | "event-class-id=%" PRId64 ", payload-ft-addr=%p", | |
405 | event_class, bt_event_class_common_get_name(event_class), | |
406 | bt_event_class_common_get_id(event_class), payload_ft); | |
407 | end: | |
408 | return ret; | |
409 | } | |
8c4a29ba | 410 | |
272df73e | 411 | #endif /* BABELTRACE_CTF_IR_EVENT_CLASS_INTERNAL_H */ |