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>
51 void bt_ctf_event_class_destroy(struct bt_object
*obj
);
53 struct bt_ctf_event_class
*bt_ctf_event_class_create(const char *name
)
56 struct bt_value
*obj
= NULL
;
57 struct bt_ctf_event_class
*event_class
= NULL
;
59 BT_LOGD("Creating event class object: name=\"%s\"",
62 if (bt_ctf_validate_identifier(name
)) {
63 BT_LOGW("Invalid parameter: event class's name is not a valid CTF identifier: "
68 event_class
= g_new0(struct bt_ctf_event_class
, 1);
70 BT_LOGE_STR("Failed to allocate one event class.");
75 bt_object_init(event_class
, bt_ctf_event_class_destroy
);
76 event_class
->fields
= bt_ctf_field_type_structure_create();
77 if (!event_class
->fields
) {
78 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
82 event_class
->attributes
= bt_ctf_attributes_create();
83 if (!event_class
->attributes
) {
84 BT_LOGE_STR("Cannot create event class's attributes object.");
88 obj
= bt_value_integer_create_init(-1);
90 BT_LOGE_STR("Cannot create integer value object.");
94 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
97 BT_LOGE("Cannot set event class's attributes's `id` field: ret=%d",
104 obj
= bt_value_string_create_init(name
);
106 BT_LOGE_STR("Cannot create string value object.");
110 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
113 BT_LOGE("Cannot set event class's attributes's `name` field: ret=%d",
119 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
120 event_class
, bt_ctf_event_class_get_name(event_class
));
129 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
131 struct bt_value
*obj
= NULL
;
132 const char *name
= NULL
;
136 BT_LOGW_STR("Invalid parameter: event class is NULL.");
140 if (event_class
->name
) {
141 name
= event_class
->name
;
145 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
146 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
148 ret
= bt_value_string_get(obj
, &name
);
156 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
158 struct bt_value
*obj
= NULL
;
163 BT_LOGW_STR("Invalid parameter: event class is NULL.");
168 if (event_class
->id
>= 0) {
169 ret
= (int64_t) event_class
->id
;
173 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
174 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
176 int_ret
= bt_value_integer_get(obj
, &ret
);
177 assert(int_ret
== 0);
179 /* means ID is not set */
180 BT_LOGV("Event class's ID is not set: addr=%p, name=\"%s\"",
181 event_class
, bt_ctf_event_class_get_name(event_class
));
191 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
195 struct bt_value
*obj
= NULL
;
196 int64_t id
= (int64_t) id_param
;
199 BT_LOGW_STR("Invalid parameter: event class is NULL.");
204 if (event_class
->frozen
) {
205 BT_LOGW("Invalid parameter: event class is frozen: "
206 "addr=%p, name=\"%s\", id=%" PRId64
,
207 event_class
, bt_ctf_event_class_get_name(event_class
),
208 bt_ctf_event_class_get_id(event_class
));
214 BT_LOGW("Invalid parameter: invalid event class's ID: "
215 "addr=%p, name=\"%s\", id=%" PRIu64
,
216 event_class
, bt_ctf_event_class_get_name(event_class
),
222 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
223 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
225 ret
= bt_value_integer_set(obj
, id
);
227 BT_LOGV("Set event class's ID: "
228 "addr=%p, name=\"%s\", id=%" PRId64
,
229 event_class
, bt_ctf_event_class_get_name(event_class
), id
);
236 int bt_ctf_event_class_set_attribute(
237 struct bt_ctf_event_class
*event_class
, const char *name
,
238 struct bt_value
*value
)
242 if (!event_class
|| !name
|| !value
) {
243 BT_LOGW("Invalid parameter: event class, name, or value is NULL: "
244 "event-class-addr=%p, name-addr=%p, value-addr=%p",
245 event_class
, name
, value
);
250 if (event_class
->frozen
) {
251 BT_LOGW("Invalid parameter: event class is frozen: "
252 "addr=%p, name=\"%s\", id=%" PRId64
", attr-name=\"%s\"",
253 event_class
, bt_ctf_event_class_get_name(event_class
),
254 bt_ctf_event_class_get_id(event_class
), name
);
259 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel") ||
260 !strcmp(name
, "stream_id")) {
261 if (!bt_value_is_integer(value
)) {
262 BT_LOGW("Invalid parameter: this event class's attribute must have an integer value: "
263 "event-class-addr=%p, event-class-name=\"%s\", "
264 "event-class-id=%" PRId64
", attr-name=\"%s\", "
265 "attr-type=%s", event_class
,
266 bt_ctf_event_class_get_name(event_class
),
267 bt_ctf_event_class_get_id(event_class
), name
,
268 bt_value_type_string(bt_value_get_type(value
)));
272 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri") ||
273 !strcmp(name
, "loglevel_string")) {
274 if (!bt_value_is_string(value
)) {
275 BT_LOGW("Invalid parameter: this event class's attribute must have a string value: "
276 "event-class-addr=%p, event-class-name=\"%s\", "
277 "event-class-id=%" PRId64
", attr-name=\"%s\", "
278 "attr-type=%s", event_class
,
279 bt_ctf_event_class_get_name(event_class
),
280 bt_ctf_event_class_get_id(event_class
), name
,
281 bt_value_type_string(bt_value_get_type(value
)));
286 /* unknown attribute */
287 BT_LOGW("Invalid parameter: unknown event class's attribute name: "
288 "event-class-addr=%p, event-class-name=\"%s\", "
289 "event-class-id=%" PRId64
", attr-name=\"%s\"",
290 event_class
, bt_ctf_event_class_get_name(event_class
),
291 bt_ctf_event_class_get_id(event_class
), name
);
296 /* "id" special case: >= 0 */
297 if (!strcmp(name
, "id")) {
300 ret
= bt_value_integer_get(value
, &val
);
302 BT_LOGV("Setting event's ID: id=%" PRId64
, val
);
303 ret
= bt_ctf_event_class_set_id(event_class
, (uint64_t) val
);
309 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
313 if (BT_LOG_ON_VERBOSE
) {
314 if (bt_value_is_integer(value
)) {
317 ret
= bt_value_integer_get(value
, &val
);
319 BT_LOGV("Set event class's integer attribute: "
320 "event-class-addr=%p, event-class-name=\"%s\", "
321 "event-class-id=%" PRId64
", attr-name=\"%s\", "
322 "attr-value=%" PRId64
,
323 event_class
, bt_ctf_event_class_get_name(event_class
),
324 bt_ctf_event_class_get_id(event_class
), name
,
326 } else if (bt_value_is_string(value
)) {
329 ret
= bt_value_string_get(value
, &val
);
331 BT_LOGV("Set event class's string attribute: "
332 "event-class-addr=%p, event-class-name=\"%s\", "
333 "event-class-id=%" PRId64
", attr-name=\"%s\", "
335 event_class
, bt_ctf_event_class_get_name(event_class
),
336 bt_ctf_event_class_get_id(event_class
), name
,
345 int64_t bt_ctf_event_class_get_attribute_count(
346 struct bt_ctf_event_class
*event_class
)
351 BT_LOGW_STR("Invalid parameter: event class is NULL.");
356 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
364 bt_ctf_event_class_get_attribute_name_by_index(
365 struct bt_ctf_event_class
*event_class
, uint64_t index
)
370 BT_LOGW_STR("Invalid parameter: event class is NULL.");
375 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
377 BT_LOGW("Cannot get event class's attribute name by index: "
378 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
379 event_class
, bt_ctf_event_class_get_name(event_class
),
380 bt_ctf_event_class_get_id(event_class
), index
);
388 bt_ctf_event_class_get_attribute_value_by_index(
389 struct bt_ctf_event_class
*event_class
, uint64_t index
)
391 struct bt_value
*ret
;
394 BT_LOGW_STR("Invalid parameter: event class is NULL.");
399 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
401 BT_LOGW("Cannot get event class's attribute value by index: "
402 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
403 event_class
, bt_ctf_event_class_get_name(event_class
),
404 bt_ctf_event_class_get_id(event_class
), index
);
412 bt_ctf_event_class_get_attribute_value_by_name(
413 struct bt_ctf_event_class
*event_class
, const char *name
)
415 struct bt_value
*ret
;
417 if (!event_class
|| !name
) {
418 BT_LOGW("Invalid parameter: event class or name is NULL: "
419 "event-class-addr=%p, name-addr=%p",
425 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
428 BT_LOGV("Cannot find event class's attribute: "
429 "addr=%p, event-class-name=\"%s\", id=%" PRId64
", "
431 event_class
, bt_ctf_event_class_get_name(event_class
),
432 bt_ctf_event_class_get_id(event_class
), name
);
440 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
441 struct bt_ctf_event_class
*event_class
)
444 bt_get(bt_ctf_event_class_borrow_stream_class(event_class
)) :
448 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
449 struct bt_ctf_event_class
*event_class
)
451 struct bt_ctf_field_type
*payload
= NULL
;
454 BT_LOGW_STR("Invalid parameter: event class is NULL.");
458 bt_get(event_class
->fields
);
459 payload
= event_class
->fields
;
464 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
465 struct bt_ctf_field_type
*payload
)
470 BT_LOGW_STR("Invalid parameter: event class is NULL.");
475 if (payload
&& bt_ctf_field_type_get_type_id(payload
) !=
476 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
477 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
478 "addr=%p, name=\"%s\", id=%" PRId64
", "
479 "payload-ft-addr=%p, payload-ft-id=%s",
480 event_class
, bt_ctf_event_class_get_name(event_class
),
481 bt_ctf_event_class_get_id(event_class
), payload
,
482 bt_ctf_field_type_id_string(
483 bt_ctf_field_type_get_type_id(payload
)));
488 bt_put(event_class
->fields
);
489 event_class
->fields
= bt_get(payload
);
490 BT_LOGV("Set event class's payload field type: "
491 "event-class-addr=%p, event-class-name=\"%s\", "
492 "event-class-id=%" PRId64
", payload-ft-addr=%p",
493 event_class
, bt_ctf_event_class_get_name(event_class
),
494 bt_ctf_event_class_get_id(event_class
), payload
);
499 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
500 struct bt_ctf_field_type
*type
,
505 if (!event_class
|| !type
) {
506 BT_LOGW("Invalid parameter: event class or field type is NULL: "
507 "event-class-addr=%p, field-type-addr=%p",
513 if (bt_ctf_validate_identifier(name
)) {
514 BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: "
515 "addr=%p, name=\"%s\", id=%" PRId64
", field-name=\"%s\"",
516 event_class
, bt_ctf_event_class_get_name(event_class
),
517 bt_ctf_event_class_get_id(event_class
),
523 if (event_class
->frozen
) {
524 BT_LOGW("Invalid parameter: event class is frozen: "
525 "addr=%p, name=\"%s\", id=%" PRId64
,
526 event_class
, bt_ctf_event_class_get_name(event_class
),
527 bt_ctf_event_class_get_id(event_class
));
532 if (!event_class
->fields
) {
533 BT_LOGW("Event class has no payload field type: "
534 "addr=%p, name=\"%s\", id=%" PRId64
,
535 event_class
, bt_ctf_event_class_get_name(event_class
),
536 bt_ctf_event_class_get_id(event_class
));
541 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
542 BT_CTF_FIELD_TYPE_ID_STRUCT
);
543 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
545 BT_LOGV("Added field to event class's payload field type: "
546 "event-class-addr=%p, event-class-name=\"%s\", "
547 "event-class-id=%" PRId64
", field-name=\"%s\", ft-addr=%p",
548 event_class
, bt_ctf_event_class_get_name(event_class
),
549 bt_ctf_event_class_get_id(event_class
), name
, type
);
554 int64_t bt_ctf_event_class_get_payload_type_field_count(
555 struct bt_ctf_event_class
*event_class
)
560 BT_LOGW_STR("Invalid parameter: event class is NULL.");
565 if (!event_class
->fields
) {
566 BT_LOGV("Event class has no payload field type: "
567 "addr=%p, name=\"%s\", id=%" PRId64
,
568 event_class
, bt_ctf_event_class_get_name(event_class
),
569 bt_ctf_event_class_get_id(event_class
));
574 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
575 BT_CTF_FIELD_TYPE_ID_STRUCT
);
576 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
581 int bt_ctf_event_class_get_payload_type_field_by_index(
582 struct bt_ctf_event_class
*event_class
,
583 const char **field_name
, struct bt_ctf_field_type
**field_type
,
589 BT_LOGW_STR("Invalid parameter: event class is NULL.");
594 if (!event_class
->fields
) {
595 BT_LOGV("Event class has no payload field type: "
596 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
597 event_class
, bt_ctf_event_class_get_name(event_class
),
598 bt_ctf_event_class_get_id(event_class
), index
);
603 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
604 BT_CTF_FIELD_TYPE_ID_STRUCT
);
605 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
606 field_name
, field_type
, index
);
611 struct bt_ctf_field_type
*
612 bt_ctf_event_class_get_payload_type_field_type_by_name(
613 struct bt_ctf_event_class
*event_class
, const char *name
)
616 struct bt_ctf_field_type
*field_type
= NULL
;
618 if (!event_class
|| !name
) {
619 BT_LOGW("Invalid parameter: event class or name is NULL: "
620 "event-class-addr=%p, name-addr=%p",
625 if (!event_class
->fields
) {
626 BT_LOGV("Event class has no payload field type: "
627 "addr=%p, name=\"%s\", id=%" PRId64
,
628 event_class
, bt_ctf_event_class_get_name(event_class
),
629 bt_ctf_event_class_get_id(event_class
));
633 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
634 BT_CTF_FIELD_TYPE_ID_STRUCT
);
635 name_quark
= g_quark_try_string(name
);
637 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
642 * No need to increment field_type's reference count since getting it
643 * from the structure already does.
645 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
646 event_class
->fields
, name
);
651 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
652 struct bt_ctf_event_class
*event_class
)
654 struct bt_ctf_field_type
*context_type
= NULL
;
657 BT_LOGW_STR("Invalid parameter: event class is NULL.");
661 if (!event_class
->context
) {
662 BT_LOGV("Event class has no context field type: "
663 "addr=%p, name=\"%s\", id=%" PRId64
,
664 event_class
, bt_ctf_event_class_get_name(event_class
),
665 bt_ctf_event_class_get_id(event_class
));
669 bt_get(event_class
->context
);
670 context_type
= event_class
->context
;
675 int bt_ctf_event_class_set_context_type(
676 struct bt_ctf_event_class
*event_class
,
677 struct bt_ctf_field_type
*context
)
682 BT_LOGW_STR("Invalid parameter: event class is NULL.");
687 if (event_class
->frozen
) {
688 BT_LOGW("Invalid parameter: event class is frozen: "
689 "addr=%p, name=\"%s\", id=%" PRId64
,
690 event_class
, bt_ctf_event_class_get_name(event_class
),
691 bt_ctf_event_class_get_id(event_class
));
696 if (context
&& bt_ctf_field_type_get_type_id(context
) !=
697 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
698 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
699 "addr=%p, name=\"%s\", id=%" PRId64
", "
701 event_class
, bt_ctf_event_class_get_name(event_class
),
702 bt_ctf_event_class_get_id(event_class
),
703 bt_ctf_field_type_id_string(
704 bt_ctf_field_type_get_type_id(context
)));
709 bt_put(event_class
->context
);
710 event_class
->context
= bt_get(context
);
711 BT_LOGV("Set event class's context field type: "
712 "event-class-addr=%p, event-class-name=\"%s\", "
713 "event-class-id=%" PRId64
", context-ft-addr=%p",
714 event_class
, bt_ctf_event_class_get_name(event_class
),
715 bt_ctf_event_class_get_id(event_class
), context
);
721 /* Pre-2.0 CTF writer backward compatibility */
722 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
727 /* Pre-2.0 CTF writer backward compatibility */
728 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
734 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
735 uint64_t stream_id_param
)
738 struct bt_value
*obj
= NULL
;
739 int64_t stream_id
= (int64_t) stream_id_param
;
742 assert(stream_id
>= 0);
743 obj
= bt_value_integer_create_init(stream_id
);
745 BT_LOGE_STR("Cannot create integer value object.");
750 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
753 BT_LOGE("Cannot set event class's attributes's `stream_id` field: "
754 "addr=%p, name=\"%s\", id=%" PRId64
", ret=%d",
755 event_class
, bt_ctf_event_class_get_name(event_class
),
756 bt_ctf_event_class_get_id(event_class
), ret
);
760 if (event_class
->frozen
) {
761 BT_LOGV_STR("Freezing event class's attributes because event class is frozen.");
762 bt_ctf_attributes_freeze(event_class
->attributes
);
765 BT_LOGV("Set event class's stream class ID: "
766 "event-class-addr=%p, event-class-name=\"%s\", "
767 "event-class-id=%" PRId64
", stream-class-id=%" PRId64
,
768 event_class
, bt_ctf_event_class_get_name(event_class
),
769 bt_ctf_event_class_get_id(event_class
), stream_id
);
777 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
779 struct bt_ctf_event_class
*event_class
;
781 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
782 BT_LOGD("Destroying event class: addr=%p, name=\"%s\", id=%" PRId64
,
783 event_class
, bt_ctf_event_class_get_name(event_class
),
784 bt_ctf_event_class_get_id(event_class
));
785 BT_LOGD_STR("Destroying event class's attributes.");
786 bt_ctf_attributes_destroy(event_class
->attributes
);
787 BT_LOGD_STR("Putting context field type.");
788 bt_put(event_class
->context
);
789 BT_LOGD_STR("Putting payload field type.");
790 bt_put(event_class
->fields
);
795 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
799 if (event_class
->frozen
) {
803 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
804 event_class
, bt_ctf_event_class_get_name(event_class
),
805 bt_ctf_event_class_get_id(event_class
));
806 event_class
->frozen
= 1;
807 event_class
->name
= bt_ctf_event_class_get_name(event_class
);
808 event_class
->id
= bt_ctf_event_class_get_id(event_class
);
809 BT_LOGD_STR("Freezing event class's context field type.");
810 bt_ctf_field_type_freeze(event_class
->context
);
811 BT_LOGD_STR("Freezing event class's payload field type.");
812 bt_ctf_field_type_freeze(event_class
->fields
);
813 BT_LOGD_STR("Freezing event class's attributes.");
814 bt_ctf_attributes_freeze(event_class
->attributes
);
818 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
819 struct metadata_context
*context
)
824 struct bt_value
*attr_value
= NULL
;
828 BT_LOGD("Serializing event class's metadata: "
829 "event-class-addr=%p, event-class-name=\"%s\", "
830 "event-class-id=%" PRId64
", metadata-context-addr=%p",
831 event_class
, bt_ctf_event_class_get_name(event_class
),
832 bt_ctf_event_class_get_id(event_class
), context
);
833 context
->current_indentation_level
= 1;
834 g_string_assign(context
->field_name
, "");
835 g_string_append(context
->string
, "event {\n");
836 count
= bt_ctf_event_class_get_attribute_count(event_class
);
839 for (i
= 0; i
< count
; ++i
) {
840 const char *attr_name
= NULL
;
842 attr_name
= bt_ctf_event_class_get_attribute_name_by_index(
845 attr_value
= bt_ctf_event_class_get_attribute_value_by_index(
849 switch (bt_value_get_type(attr_value
)) {
850 case BT_VALUE_TYPE_INTEGER
:
854 ret
= bt_value_integer_get(attr_value
, &value
);
856 g_string_append_printf(context
->string
,
857 "\t%s = %" PRId64
";\n", attr_name
, value
);
861 case BT_VALUE_TYPE_STRING
:
865 ret
= bt_value_string_get(attr_value
, &value
);
867 g_string_append_printf(context
->string
,
868 "\t%s = \"%s\";\n", attr_name
, value
);
873 /* should never happen */
881 if (event_class
->context
) {
882 g_string_append(context
->string
, "\tcontext := ");
883 BT_LOGD_STR("Serializing event class's context field type metadata.");
884 ret
= bt_ctf_field_type_serialize(event_class
->context
,
887 BT_LOGW("Cannot serialize event class's context field type's metadata: "
891 g_string_append(context
->string
, ";\n");
894 if (event_class
->fields
) {
895 g_string_append(context
->string
, "\tfields := ");
896 BT_LOGD_STR("Serializing event class's payload field type metadata.");
897 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
899 BT_LOGW("Cannot serialize event class's payload field type's metadata: "
903 g_string_append(context
->string
, ";\n");
906 g_string_append(context
->string
, "};\n\n");
908 context
->current_indentation_level
= 0;