4 * Babeltrace CTF IR - Event class
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #define BT_LOG_TAG "EVENT-CLASS"
30 #include <babeltrace/lib-logging-internal.h>
32 #include <babeltrace/assert-pre-internal.h>
33 #include <babeltrace/ctf-ir/clock-value-internal.h>
34 #include <babeltrace/ctf-ir/fields-internal.h>
35 #include <babeltrace/ctf-ir/field-types-internal.h>
36 #include <babeltrace/ctf-ir/event-class.h>
37 #include <babeltrace/ctf-ir/event-class-internal.h>
38 #include <babeltrace/ctf-ir/event-internal.h>
39 #include <babeltrace/ctf-ir/stream-class.h>
40 #include <babeltrace/ctf-ir/stream-class-internal.h>
41 #include <babeltrace/ctf-ir/trace-internal.h>
42 #include <babeltrace/ctf-ir/validation-internal.h>
43 #include <babeltrace/ctf-ir/utils.h>
44 #include <babeltrace/ctf-ir/utils-internal.h>
45 #include <babeltrace/ref.h>
46 #include <babeltrace/ctf-ir/attributes-internal.h>
47 #include <babeltrace/compiler-internal.h>
48 #include <babeltrace/endian-internal.h>
49 #include <babeltrace/types.h>
50 #include <babeltrace/values-internal.h>
51 #include <babeltrace/assert-internal.h>
56 void bt_event_class_finalize(struct bt_object
*obj
)
58 struct bt_event_class
*event_class
;
60 event_class
= container_of(obj
, struct bt_event_class
, base
);
61 BT_LOGD("Finalizing event class: addr=%p, name=\"%s\", id=%" PRId64
,
62 event_class
, bt_event_class_get_name(event_class
),
63 bt_event_class_get_id(event_class
));
65 if (event_class
->name
) {
66 g_string_free(event_class
->name
, TRUE
);
69 if (event_class
->emf_uri
) {
70 g_string_free(event_class
->emf_uri
, TRUE
);
73 BT_LOGD_STR("Putting context field type.");
74 bt_put(event_class
->context_field_type
);
75 BT_LOGD_STR("Putting payload field type.");
76 bt_put(event_class
->payload_field_type
);
80 int bt_event_class_initialize(struct bt_event_class
*event_class
,
81 const char *name
, bt_object_release_func release_func
,
82 bt_field_type_structure_create_func ft_struct_create_func
)
86 BT_LOGD("Initializing event class object: name=\"%s\"",
88 bt_object_init_shared_with_parent(&event_class
->base
, release_func
);
89 event_class
->payload_field_type
= ft_struct_create_func();
90 if (!event_class
->payload_field_type
) {
91 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
96 event_class
->name
= g_string_new(name
);
97 if (!event_class
->name
) {
98 BT_LOGE_STR("Failed to allocate a GString.");
102 event_class
->emf_uri
= g_string_new(NULL
);
103 if (!event_class
->emf_uri
) {
104 BT_LOGE_STR("Failed to allocate a GString.");
108 event_class
->log_level
= BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
;
109 BT_LOGD("Initialized event class object: addr=%p, name=\"%s\"",
110 event_class
, bt_event_class_get_name(event_class
));
119 void bt_event_class_destroy(struct bt_object
*obj
)
121 struct bt_event_class
*event_class
= (void *) obj
;
123 BT_LOGD("Destroying event class: addr=%p", obj
);
124 bt_event_class_finalize(obj
);
125 bt_object_pool_finalize(&event_class
->event_pool
);
130 void free_event(struct bt_event
*event
,
131 struct bt_event_class
*event_class
)
133 bt_event_destroy(event
);
136 struct bt_event_class
*bt_event_class_create(const char *name
)
139 struct bt_event_class
*event_class
= NULL
;
142 BT_LOGW_STR("Invalid parameter: name is NULL.");
146 BT_LOGD("Creating event class object: name=\"%s\"",
148 event_class
= g_new0(struct bt_event_class
, 1);
150 BT_LOGE_STR("Failed to allocate one event class.");
154 ret
= bt_event_class_initialize(event_class
,
155 name
, bt_event_class_destroy
,
156 (bt_field_type_structure_create_func
)
157 bt_field_type_structure_create
);
162 ret
= bt_object_pool_initialize(&event_class
->event_pool
,
163 (bt_object_pool_new_object_func
) bt_event_new
,
164 (bt_object_pool_destroy_object_func
) free_event
,
167 BT_LOGE("Failed to initialize event pool: ret=%d",
172 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
173 event_class
, bt_event_class_get_name(event_class
));
183 const char *bt_event_class_get_name(struct bt_event_class
*event_class
)
185 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
186 BT_ASSERT(event_class
->name
);
187 return event_class
->name
->str
;
190 int64_t bt_event_class_get_id(struct bt_event_class
*event_class
)
192 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
193 return event_class
->id
;
196 int bt_event_class_set_id(struct bt_event_class
*event_class
,
200 int64_t id
= (int64_t) id_param
;
203 BT_LOGW_STR("Invalid parameter: event class is NULL.");
208 if (event_class
->frozen
) {
209 BT_LOGW("Invalid parameter: event class is frozen: "
210 "addr=%p, name=\"%s\", id=%" PRId64
,
212 bt_event_class_get_name(event_class
),
213 bt_event_class_get_id(event_class
));
219 BT_LOGW("Invalid parameter: invalid event class's ID: "
220 "addr=%p, name=\"%s\", id=%" PRIu64
,
222 bt_event_class_get_name(event_class
),
228 event_class
->id
= id
;
229 BT_LOGV("Set event class's ID: "
230 "addr=%p, name=\"%s\", id=%" PRId64
,
231 event_class
, bt_event_class_get_name(event_class
), id
);
237 enum bt_event_class_log_level
bt_event_class_get_log_level(
238 struct bt_event_class
*event_class
)
240 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
241 return event_class
->log_level
;
244 int bt_event_class_set_log_level(struct bt_event_class
*event_class
,
245 enum bt_event_class_log_level log_level
)
250 BT_LOGW_STR("Invalid parameter: event class is NULL.");
255 if (event_class
->frozen
) {
256 BT_LOGW("Invalid parameter: event class is frozen: "
257 "addr=%p, name=\"%s\", id=%" PRId64
,
259 bt_event_class_get_name(event_class
),
260 bt_event_class_get_id(event_class
));
266 case BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
:
267 case BT_EVENT_CLASS_LOG_LEVEL_EMERGENCY
:
268 case BT_EVENT_CLASS_LOG_LEVEL_ALERT
:
269 case BT_EVENT_CLASS_LOG_LEVEL_CRITICAL
:
270 case BT_EVENT_CLASS_LOG_LEVEL_ERROR
:
271 case BT_EVENT_CLASS_LOG_LEVEL_WARNING
:
272 case BT_EVENT_CLASS_LOG_LEVEL_NOTICE
:
273 case BT_EVENT_CLASS_LOG_LEVEL_INFO
:
274 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
:
275 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
:
276 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
:
277 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
:
278 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
:
279 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
:
280 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
:
281 case BT_EVENT_CLASS_LOG_LEVEL_DEBUG
:
284 BT_LOGW("Invalid parameter: unknown event class log level: "
285 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%d",
286 event_class
, bt_event_class_get_name(event_class
),
287 bt_event_class_get_id(event_class
), log_level
);
292 event_class
->log_level
= log_level
;
293 BT_LOGV("Set event class's log level: "
294 "addr=%p, name=\"%s\", id=%" PRId64
", log-level=%s",
295 event_class
, bt_event_class_get_name(event_class
),
296 bt_event_class_get_id(event_class
),
297 bt_common_event_class_log_level_string(log_level
));
303 const char *bt_event_class_get_emf_uri(struct bt_event_class
*event_class
)
305 const char *emf_uri
= NULL
;
307 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
309 if (event_class
->emf_uri
->len
> 0) {
310 emf_uri
= event_class
->emf_uri
->str
;
316 int bt_event_class_set_emf_uri(struct bt_event_class
*event_class
,
322 BT_LOGW_STR("Invalid parameter: event class is NULL.");
327 if (emf_uri
&& strlen(emf_uri
) == 0) {
328 BT_LOGW_STR("Invalid parameter: EMF URI is empty.");
333 if (event_class
->frozen
) {
334 BT_LOGW("Invalid parameter: event class is frozen: "
335 "addr=%p, name=\"%s\", id=%" PRId64
,
336 event_class
, bt_event_class_get_name(event_class
),
337 bt_event_class_get_id(event_class
));
343 g_string_assign(event_class
->emf_uri
, emf_uri
);
344 BT_LOGV("Set event class's EMF URI: "
345 "addr=%p, name=\"%s\", id=%" PRId64
", emf-uri=\"%s\"",
346 event_class
, bt_event_class_get_name(event_class
),
347 bt_event_class_get_id(event_class
), emf_uri
);
349 g_string_assign(event_class
->emf_uri
, "");
350 BT_LOGV("Reset event class's EMF URI: "
351 "addr=%p, name=\"%s\", id=%" PRId64
,
352 event_class
, bt_event_class_get_name(event_class
),
353 bt_event_class_get_id(event_class
));
360 struct bt_stream_class
*bt_event_class_borrow_stream_class(
361 struct bt_event_class
*event_class
)
363 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
364 return (void *) bt_object_borrow_parent(&event_class
->base
);
367 struct bt_field_type
*bt_event_class_borrow_payload_field_type(
368 struct bt_event_class
*event_class
)
370 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
371 return event_class
->payload_field_type
;
374 int bt_event_class_set_payload_field_type(struct bt_event_class
*event_class
,
375 struct bt_field_type
*field_type
)
380 BT_LOGW_STR("Invalid parameter: event class is NULL.");
385 if (field_type
&& bt_field_type_get_type_id(field_type
) !=
386 BT_FIELD_TYPE_ID_STRUCT
) {
387 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
388 "addr=%p, name=\"%s\", id=%" PRId64
", "
389 "payload-ft-addr=%p, payload-ft-id=%s",
390 event_class
, bt_event_class_get_name(event_class
),
391 bt_event_class_get_id(event_class
), field_type
,
392 bt_common_field_type_id_string(
393 bt_field_type_get_type_id(field_type
)));
398 bt_put(event_class
->payload_field_type
);
399 event_class
->payload_field_type
= bt_get(field_type
);
400 BT_LOGV("Set event class's payload field type: "
401 "event-class-addr=%p, event-class-name=\"%s\", "
402 "event-class-id=%" PRId64
", payload-ft-addr=%p",
403 event_class
, bt_event_class_get_name(event_class
),
404 bt_event_class_get_id(event_class
), field_type
);
409 struct bt_field_type
*bt_event_class_borrow_context_field_type(
410 struct bt_event_class
*event_class
)
412 struct bt_field_type
*context_ft
= NULL
;
414 BT_ASSERT_PRE_NON_NULL(event_class
, "Event class");
416 if (!event_class
->context_field_type
) {
417 BT_LOGV("Event class has no context field type: "
418 "addr=%p, name=\"%s\", id=%" PRId64
,
419 event_class
, bt_event_class_get_name(event_class
),
420 bt_event_class_get_id(event_class
));
424 context_ft
= event_class
->context_field_type
;
430 int bt_event_class_set_context_field_type(
431 struct bt_event_class
*event_class
,
432 struct bt_field_type
*field_type
)
437 BT_LOGW_STR("Invalid parameter: event class is NULL.");
442 if (event_class
->frozen
) {
443 BT_LOGW("Invalid parameter: event class is frozen: "
444 "addr=%p, name=\"%s\", id=%" PRId64
,
445 event_class
, bt_event_class_get_name(event_class
),
446 bt_event_class_get_id(event_class
));
451 if (field_type
&& bt_field_type_get_type_id(field_type
) !=
452 BT_FIELD_TYPE_ID_STRUCT
) {
453 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
454 "addr=%p, name=\"%s\", id=%" PRId64
", "
456 event_class
, bt_event_class_get_name(event_class
),
457 bt_event_class_get_id(event_class
),
458 bt_common_field_type_id_string(
459 bt_field_type_get_type_id(field_type
)));
464 bt_put(event_class
->context_field_type
);
465 event_class
->context_field_type
= bt_get(field_type
);
466 BT_LOGV("Set event class's context field type: "
467 "event-class-addr=%p, event-class-name=\"%s\", "
468 "event-class-id=%" PRId64
", context-ft-addr=%p",
469 event_class
, bt_event_class_get_name(event_class
),
470 bt_event_class_get_id(event_class
), field_type
);
477 void bt_event_class_freeze(struct bt_event_class
*event_class
)
479 BT_ASSERT(event_class
);
481 if (event_class
->frozen
) {
485 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
486 event_class
, bt_event_class_get_name(event_class
),
487 bt_event_class_get_id(event_class
));
488 event_class
->frozen
= 1;
489 BT_LOGD_STR("Freezing event class's context field type.");
490 bt_field_type_freeze(event_class
->context_field_type
);
491 BT_LOGD_STR("Freezing event class's payload field type.");
492 bt_field_type_freeze(event_class
->payload_field_type
);
496 int bt_event_class_validate_single_clock_class(
497 struct bt_event_class
*event_class
,
498 struct bt_clock_class
**expected_clock_class
)
502 BT_ASSERT(event_class
);
503 BT_ASSERT(expected_clock_class
);
504 ret
= bt_field_type_validate_single_clock_class(
505 event_class
->context_field_type
,
506 expected_clock_class
);
508 BT_LOGW("Event class's context field type "
509 "is not recursively mapped to the "
510 "expected clock class: "
511 "event-class-addr=%p, "
512 "event-class-name=\"%s\", "
513 "event-class-id=%" PRId64
", "
516 bt_event_class_get_name(event_class
),
518 event_class
->context_field_type
);
522 ret
= bt_field_type_validate_single_clock_class(
523 event_class
->payload_field_type
,
524 expected_clock_class
);
526 BT_LOGW("Event class's payload field type "
527 "is not recursively mapped to the "
528 "expected clock class: "
529 "event-class-addr=%p, "
530 "event-class-name=\"%s\", "
531 "event-class-id=%" PRId64
", "
534 bt_event_class_get_name(event_class
),
536 event_class
->payload_field_type
);