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/ctf-ir/fields-internal.h>
33 #include <babeltrace/ctf-ir/field-types-internal.h>
34 #include <babeltrace/ctf-ir/event-class.h>
35 #include <babeltrace/ctf-ir/event-class-internal.h>
36 #include <babeltrace/ctf-ir/stream-class.h>
37 #include <babeltrace/ctf-ir/stream-class-internal.h>
38 #include <babeltrace/ctf-ir/trace-internal.h>
39 #include <babeltrace/ctf-ir/validation-internal.h>
40 #include <babeltrace/ctf-ir/utils.h>
41 #include <babeltrace/ref.h>
42 #include <babeltrace/ctf-ir/attributes-internal.h>
43 #include <babeltrace/compiler-internal.h>
44 #include <babeltrace/endian-internal.h>
45 #include <babeltrace/types.h>
46 #include <babeltrace/values-internal.h>
50 void bt_ctf_event_class_destroy(struct bt_object
*obj
);
52 struct bt_ctf_event_class
*bt_ctf_event_class_create(const char *name
)
55 struct bt_value
*obj
= NULL
;
56 struct bt_ctf_event_class
*event_class
= NULL
;
58 BT_LOGD("Creating event class object: name=\"%s\"",
61 if (bt_ctf_validate_identifier(name
)) {
62 BT_LOGW("Invalid parameter: event class's name is not a valid CTF identifier: "
67 event_class
= g_new0(struct bt_ctf_event_class
, 1);
69 BT_LOGE_STR("Failed to allocate one event class.");
74 bt_object_init(event_class
, bt_ctf_event_class_destroy
);
75 event_class
->fields
= bt_ctf_field_type_structure_create();
76 if (!event_class
->fields
) {
77 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
81 event_class
->context
= bt_ctf_field_type_structure_create();
82 if (!event_class
->context
) {
83 BT_LOGE_STR("Cannot create event class's initial context field type object.");
87 event_class
->attributes
= bt_ctf_attributes_create();
88 if (!event_class
->attributes
) {
89 BT_LOGE_STR("Cannot create event class's attributes object.");
93 obj
= bt_value_integer_create_init(-1);
95 BT_LOGE_STR("Cannot create integer value object.");
99 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
102 BT_LOGE("Cannot set event class's attributes's `id` field: ret=%d",
109 obj
= bt_value_string_create_init(name
);
111 BT_LOGE_STR("Cannot create string value object.");
115 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
118 BT_LOGE("Cannot set event class's attributes's `name` field: ret=%d",
124 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
125 event_class
, bt_ctf_event_class_get_name(event_class
));
134 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
136 struct bt_value
*obj
= NULL
;
137 const char *name
= NULL
;
141 BT_LOGW_STR("Invalid parameter: event class is NULL.");
145 if (event_class
->name
) {
146 name
= event_class
->name
;
150 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
151 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
153 ret
= bt_value_string_get(obj
, &name
);
161 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
163 struct bt_value
*obj
= NULL
;
168 BT_LOGW_STR("Invalid parameter: event class is NULL.");
173 if (event_class
->id
>= 0) {
174 ret
= (int64_t) event_class
->id
;
178 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
179 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
181 int_ret
= bt_value_integer_get(obj
, &ret
);
182 assert(int_ret
== 0);
184 /* means ID is not set */
185 BT_LOGV("Event class's ID is not set: addr=%p, name=\"%s\"",
186 event_class
, bt_ctf_event_class_get_name(event_class
));
196 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
200 struct bt_value
*obj
= NULL
;
201 int64_t id
= (int64_t) id_param
;
204 BT_LOGW_STR("Invalid parameter: event class is NULL.");
209 if (event_class
->frozen
) {
210 BT_LOGW("Invalid parameter: event class is frozen: "
211 "addr=%p, name=\"%s\", id=%" PRId64
,
212 event_class
, bt_ctf_event_class_get_name(event_class
),
213 bt_ctf_event_class_get_id(event_class
));
219 BT_LOGW("Invalid parameter: invalid event class's ID: "
220 "addr=%p, name=\"%s\", id=%" PRIu64
,
221 event_class
, bt_ctf_event_class_get_name(event_class
),
227 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
228 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
230 ret
= bt_value_integer_set(obj
, id
);
232 BT_LOGV("Set event class's ID: "
233 "addr=%p, name=\"%s\", id=%" PRId64
,
234 event_class
, bt_ctf_event_class_get_name(event_class
), id
);
241 int bt_ctf_event_class_set_attribute(
242 struct bt_ctf_event_class
*event_class
, const char *name
,
243 struct bt_value
*value
)
247 if (!event_class
|| !name
|| !value
) {
248 BT_LOGW("Invalid parameter: event class, name, or value is NULL: "
249 "event-class-addr=%p, name-addr=%p, value-addr=%p",
250 event_class
, name
, value
);
255 if (event_class
->frozen
) {
256 BT_LOGW("Invalid parameter: event class is frozen: "
257 "addr=%p, name=\"%s\", id=%" PRId64
", attr-name=\"%s\"",
258 event_class
, bt_ctf_event_class_get_name(event_class
),
259 bt_ctf_event_class_get_id(event_class
), name
);
264 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel") ||
265 !strcmp(name
, "stream_id")) {
266 if (!bt_value_is_integer(value
)) {
267 BT_LOGW("Invalid parameter: this event class's attribute must have an integer value: "
268 "event-class-addr=%p, event-class-name=\"%s\", "
269 "event-class-id=%" PRId64
", attr-name=\"%s\", "
270 "attr-type=%s", event_class
,
271 bt_ctf_event_class_get_name(event_class
),
272 bt_ctf_event_class_get_id(event_class
), name
,
273 bt_value_type_string(bt_value_get_type(value
)));
277 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri") ||
278 !strcmp(name
, "loglevel_string")) {
279 if (!bt_value_is_string(value
)) {
280 BT_LOGW("Invalid parameter: this event class's attribute must have a string value: "
281 "event-class-addr=%p, event-class-name=\"%s\", "
282 "event-class-id=%" PRId64
", attr-name=\"%s\", "
283 "attr-type=%s", event_class
,
284 bt_ctf_event_class_get_name(event_class
),
285 bt_ctf_event_class_get_id(event_class
), name
,
286 bt_value_type_string(bt_value_get_type(value
)));
291 /* unknown attribute */
292 BT_LOGW("Invalid parameter: unknown event class's attribute name: "
293 "event-class-addr=%p, event-class-name=\"%s\", "
294 "event-class-id=%" PRId64
", attr-name=\"%s\"",
295 event_class
, bt_ctf_event_class_get_name(event_class
),
296 bt_ctf_event_class_get_id(event_class
), name
);
301 /* "id" special case: >= 0 */
302 if (!strcmp(name
, "id")) {
305 ret
= bt_value_integer_get(value
, &val
);
307 BT_LOGV("Setting event's ID: id=%" PRId64
, val
);
308 ret
= bt_ctf_event_class_set_id(event_class
, (uint64_t) val
);
314 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
318 if (BT_LOG_ON_VERBOSE
) {
319 if (bt_value_is_integer(value
)) {
322 ret
= bt_value_integer_get(value
, &val
);
324 BT_LOGV("Set event class's integer attribute: "
325 "event-class-addr=%p, event-class-name=\"%s\", "
326 "event-class-id=%" PRId64
", attr-name=\"%s\", "
327 "attr-value=%" PRId64
,
328 event_class
, bt_ctf_event_class_get_name(event_class
),
329 bt_ctf_event_class_get_id(event_class
), name
,
331 } else if (bt_value_is_string(value
)) {
334 ret
= bt_value_string_get(value
, &val
);
336 BT_LOGV("Set event class's string attribute: "
337 "event-class-addr=%p, event-class-name=\"%s\", "
338 "event-class-id=%" PRId64
", attr-name=\"%s\", "
340 event_class
, bt_ctf_event_class_get_name(event_class
),
341 bt_ctf_event_class_get_id(event_class
), name
,
350 int64_t bt_ctf_event_class_get_attribute_count(
351 struct bt_ctf_event_class
*event_class
)
356 BT_LOGW_STR("Invalid parameter: event class is NULL.");
361 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
369 bt_ctf_event_class_get_attribute_name_by_index(
370 struct bt_ctf_event_class
*event_class
, uint64_t index
)
375 BT_LOGW_STR("Invalid parameter: event class is NULL.");
380 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
382 BT_LOGW("Cannot get event class's attribute name by index: "
383 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
384 event_class
, bt_ctf_event_class_get_name(event_class
),
385 bt_ctf_event_class_get_id(event_class
), index
);
393 bt_ctf_event_class_get_attribute_value_by_index(
394 struct bt_ctf_event_class
*event_class
, uint64_t index
)
396 struct bt_value
*ret
;
399 BT_LOGW_STR("Invalid parameter: event class is NULL.");
404 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
406 BT_LOGW("Cannot get event class's attribute value by index: "
407 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
408 event_class
, bt_ctf_event_class_get_name(event_class
),
409 bt_ctf_event_class_get_id(event_class
), index
);
417 bt_ctf_event_class_get_attribute_value_by_name(
418 struct bt_ctf_event_class
*event_class
, const char *name
)
420 struct bt_value
*ret
;
422 if (!event_class
|| !name
) {
423 BT_LOGW("Invalid parameter: event class or name is NULL: "
424 "event-class-addr=%p, name-addr=%p",
430 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
433 BT_LOGV("Cannot find event class's attribute: "
434 "addr=%p, event-class-name=\"%s\", id=%" PRId64
", "
436 event_class
, bt_ctf_event_class_get_name(event_class
),
437 bt_ctf_event_class_get_id(event_class
), name
);
445 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
446 struct bt_ctf_event_class
*event_class
)
449 bt_get(bt_ctf_event_class_borrow_stream_class(event_class
)) :
453 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
454 struct bt_ctf_event_class
*event_class
)
456 struct bt_ctf_field_type
*payload
= NULL
;
459 BT_LOGW_STR("Invalid parameter: event class is NULL.");
463 bt_get(event_class
->fields
);
464 payload
= event_class
->fields
;
469 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
470 struct bt_ctf_field_type
*payload
)
475 BT_LOGW_STR("Invalid parameter: event class is NULL.");
480 if (payload
&& bt_ctf_field_type_get_type_id(payload
) !=
481 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
482 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
483 "addr=%p, name=\"%s\", id=%" PRId64
", "
484 "payload-ft-addr=%p, payload-ft-id=%s",
485 event_class
, bt_ctf_event_class_get_name(event_class
),
486 bt_ctf_event_class_get_id(event_class
), payload
,
487 bt_ctf_field_type_id_string(
488 bt_ctf_field_type_get_type_id(payload
)));
493 bt_put(event_class
->fields
);
494 event_class
->fields
= bt_get(payload
);
495 BT_LOGV("Set event class's payload field type: "
496 "event-class-addr=%p, event-class-name=\"%s\", "
497 "event-class-id=%" PRId64
", payload-ft-addr=%p",
498 event_class
, bt_ctf_event_class_get_name(event_class
),
499 bt_ctf_event_class_get_id(event_class
), payload
);
504 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
505 struct bt_ctf_field_type
*type
,
510 if (!event_class
|| !type
) {
511 BT_LOGW("Invalid parameter: event class or field type is NULL: "
512 "event-class-addr=%p, field-type-addr=%p",
518 if (bt_ctf_validate_identifier(name
)) {
519 BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: "
520 "addr=%p, name=\"%s\", id=%" PRId64
", field-name=\"%s\"",
521 event_class
, bt_ctf_event_class_get_name(event_class
),
522 bt_ctf_event_class_get_id(event_class
),
528 if (event_class
->frozen
) {
529 BT_LOGW("Invalid parameter: event class is frozen: "
530 "addr=%p, name=\"%s\", id=%" PRId64
,
531 event_class
, bt_ctf_event_class_get_name(event_class
),
532 bt_ctf_event_class_get_id(event_class
));
537 if (!event_class
->fields
) {
538 BT_LOGW("Event class has no payload field type: "
539 "addr=%p, name=\"%s\", id=%" PRId64
,
540 event_class
, bt_ctf_event_class_get_name(event_class
),
541 bt_ctf_event_class_get_id(event_class
));
546 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
547 BT_CTF_FIELD_TYPE_ID_STRUCT
);
548 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
550 BT_LOGV("Added field to event class's payload field type: "
551 "event-class-addr=%p, event-class-name=\"%s\", "
552 "event-class-id=%" PRId64
", field-name=\"%s\", ft-addr=%p",
553 event_class
, bt_ctf_event_class_get_name(event_class
),
554 bt_ctf_event_class_get_id(event_class
), name
, type
);
559 int64_t bt_ctf_event_class_get_payload_type_field_count(
560 struct bt_ctf_event_class
*event_class
)
565 BT_LOGW_STR("Invalid parameter: event class is NULL.");
570 if (!event_class
->fields
) {
571 BT_LOGV("Event class has no payload field type: "
572 "addr=%p, name=\"%s\", id=%" PRId64
,
573 event_class
, bt_ctf_event_class_get_name(event_class
),
574 bt_ctf_event_class_get_id(event_class
));
579 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
580 BT_CTF_FIELD_TYPE_ID_STRUCT
);
581 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
586 int bt_ctf_event_class_get_payload_type_field_by_index(
587 struct bt_ctf_event_class
*event_class
,
588 const char **field_name
, struct bt_ctf_field_type
**field_type
,
594 BT_LOGW_STR("Invalid parameter: event class is NULL.");
599 if (!event_class
->fields
) {
600 BT_LOGV("Event class has no payload field type: "
601 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
602 event_class
, bt_ctf_event_class_get_name(event_class
),
603 bt_ctf_event_class_get_id(event_class
), index
);
608 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
609 BT_CTF_FIELD_TYPE_ID_STRUCT
);
610 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
611 field_name
, field_type
, index
);
616 struct bt_ctf_field_type
*
617 bt_ctf_event_class_get_payload_type_field_type_by_name(
618 struct bt_ctf_event_class
*event_class
, const char *name
)
621 struct bt_ctf_field_type
*field_type
= NULL
;
623 if (!event_class
|| !name
) {
624 BT_LOGW("Invalid parameter: event class or name is NULL: "
625 "event-class-addr=%p, name-addr=%p",
630 if (!event_class
->fields
) {
631 BT_LOGV("Event class has no payload field type: "
632 "addr=%p, name=\"%s\", id=%" PRId64
,
633 event_class
, bt_ctf_event_class_get_name(event_class
),
634 bt_ctf_event_class_get_id(event_class
));
638 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
639 BT_CTF_FIELD_TYPE_ID_STRUCT
);
640 name_quark
= g_quark_try_string(name
);
642 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
647 * No need to increment field_type's reference count since getting it
648 * from the structure already does.
650 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
651 event_class
->fields
, name
);
656 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
657 struct bt_ctf_event_class
*event_class
)
659 struct bt_ctf_field_type
*context_type
= NULL
;
662 BT_LOGW_STR("Invalid parameter: event class is NULL.");
666 if (!event_class
->context
) {
667 BT_LOGV("Event class has no context field type: "
668 "addr=%p, name=\"%s\", id=%" PRId64
,
669 event_class
, bt_ctf_event_class_get_name(event_class
),
670 bt_ctf_event_class_get_id(event_class
));
674 bt_get(event_class
->context
);
675 context_type
= event_class
->context
;
680 int bt_ctf_event_class_set_context_type(
681 struct bt_ctf_event_class
*event_class
,
682 struct bt_ctf_field_type
*context
)
687 BT_LOGW_STR("Invalid parameter: event class is NULL.");
692 if (event_class
->frozen
) {
693 BT_LOGW("Invalid parameter: event class is frozen: "
694 "addr=%p, name=\"%s\", id=%" PRId64
,
695 event_class
, bt_ctf_event_class_get_name(event_class
),
696 bt_ctf_event_class_get_id(event_class
));
701 if (context
&& bt_ctf_field_type_get_type_id(context
) !=
702 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
703 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
704 "addr=%p, name=\"%s\", id=%" PRId64
", "
706 event_class
, bt_ctf_event_class_get_name(event_class
),
707 bt_ctf_event_class_get_id(event_class
),
708 bt_ctf_field_type_id_string(
709 bt_ctf_field_type_get_type_id(context
)));
714 bt_put(event_class
->context
);
715 event_class
->context
= bt_get(context
);
716 BT_LOGV("Set event class's context field type: "
717 "event-class-addr=%p, event-class-name=\"%s\", "
718 "event-class-id=%" PRId64
", context-ft-addr=%p",
719 event_class
, bt_ctf_event_class_get_name(event_class
),
720 bt_ctf_event_class_get_id(event_class
), context
);
726 /* Pre-2.0 CTF writer backward compatibility */
727 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
732 /* Pre-2.0 CTF writer backward compatibility */
733 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
739 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
740 uint64_t stream_id_param
)
743 struct bt_value
*obj
= NULL
;
744 int64_t stream_id
= (int64_t) stream_id_param
;
747 assert(stream_id
>= 0);
748 obj
= bt_value_integer_create_init(stream_id
);
750 BT_LOGE_STR("Cannot create integer value object.");
755 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
758 BT_LOGE("Cannot set event class's attributes's `stream_id` field: "
759 "addr=%p, name=\"%s\", id=%" PRId64
", ret=%d",
760 event_class
, bt_ctf_event_class_get_name(event_class
),
761 bt_ctf_event_class_get_id(event_class
), ret
);
765 if (event_class
->frozen
) {
766 BT_LOGV_STR("Freezing event class's attributes because event class is frozen.");
767 bt_ctf_attributes_freeze(event_class
->attributes
);
770 BT_LOGV("Set event class's stream class ID: "
771 "event-class-addr=%p, event-class-name=\"%s\", "
772 "event-class-id=%" PRId64
", stream-class-id=%" PRId64
,
773 event_class
, bt_ctf_event_class_get_name(event_class
),
774 bt_ctf_event_class_get_id(event_class
), stream_id
);
782 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
784 struct bt_ctf_event_class
*event_class
;
786 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
787 BT_LOGD("Destroying event class: addr=%p, name=\"%s\", id=%" PRId64
,
788 event_class
, bt_ctf_event_class_get_name(event_class
),
789 bt_ctf_event_class_get_id(event_class
));
790 BT_LOGD_STR("Destroying event class's attributes.");
791 bt_ctf_attributes_destroy(event_class
->attributes
);
792 BT_LOGD_STR("Putting event class's context field type.");
793 bt_put(event_class
->context
);
794 BT_LOGD_STR("Putting event class's payload field type.");
795 bt_put(event_class
->fields
);
800 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
804 if (event_class
->frozen
) {
808 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
809 event_class
, bt_ctf_event_class_get_name(event_class
),
810 bt_ctf_event_class_get_id(event_class
));
811 event_class
->frozen
= 1;
812 event_class
->name
= bt_ctf_event_class_get_name(event_class
);
813 event_class
->id
= bt_ctf_event_class_get_id(event_class
);
814 BT_LOGD_STR("Freezing event class's context field type.");
815 bt_ctf_field_type_freeze(event_class
->context
);
816 BT_LOGD_STR("Freezing event class's payload field type.");
817 bt_ctf_field_type_freeze(event_class
->fields
);
818 BT_LOGD_STR("Freezing event class's attributes.");
819 bt_ctf_attributes_freeze(event_class
->attributes
);
823 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
824 struct metadata_context
*context
)
829 struct bt_value
*attr_value
= NULL
;
833 BT_LOGD("Serializing event class's metadata: "
834 "event-class-addr=%p, event-class-name=\"%s\", "
835 "event-class-id=%" PRId64
", metadata-context-addr=%p",
836 event_class
, bt_ctf_event_class_get_name(event_class
),
837 bt_ctf_event_class_get_id(event_class
), context
);
838 context
->current_indentation_level
= 1;
839 g_string_assign(context
->field_name
, "");
840 g_string_append(context
->string
, "event {\n");
841 count
= bt_ctf_event_class_get_attribute_count(event_class
);
844 for (i
= 0; i
< count
; ++i
) {
845 const char *attr_name
= NULL
;
847 attr_name
= bt_ctf_event_class_get_attribute_name_by_index(
850 attr_value
= bt_ctf_event_class_get_attribute_value_by_index(
854 switch (bt_value_get_type(attr_value
)) {
855 case BT_VALUE_TYPE_INTEGER
:
859 ret
= bt_value_integer_get(attr_value
, &value
);
861 g_string_append_printf(context
->string
,
862 "\t%s = %" PRId64
";\n", attr_name
, value
);
866 case BT_VALUE_TYPE_STRING
:
870 ret
= bt_value_string_get(attr_value
, &value
);
872 g_string_append_printf(context
->string
,
873 "\t%s = \"%s\";\n", attr_name
, value
);
878 /* should never happen */
886 if (event_class
->context
) {
887 g_string_append(context
->string
, "\tcontext := ");
888 BT_LOGD_STR("Serializing event class's context field type metadata.");
889 ret
= bt_ctf_field_type_serialize(event_class
->context
,
892 BT_LOGW("Cannot serialize event class's context field type's metadata: "
896 g_string_append(context
->string
, ";\n");
899 if (event_class
->fields
) {
900 g_string_append(context
->string
, "\tfields := ");
901 BT_LOGD_STR("Serializing event class's payload field type metadata.");
902 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
904 BT_LOGW("Cannot serialize event class's payload field type's metadata: "
908 g_string_append(context
->string
, ";\n");
911 g_string_append(context
->string
, "};\n\n");
913 context
->current_indentation_level
= 0;