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 event_class
= g_new0(struct bt_ctf_event_class
, 1);
64 BT_LOGE_STR("Failed to allocate one event class.");
69 bt_object_init(event_class
, bt_ctf_event_class_destroy
);
70 event_class
->fields
= bt_ctf_field_type_structure_create();
71 if (!event_class
->fields
) {
72 BT_LOGE_STR("Cannot create event class's initial payload field type object.");
76 event_class
->attributes
= bt_ctf_attributes_create();
77 if (!event_class
->attributes
) {
78 BT_LOGE_STR("Cannot create event class's attributes object.");
82 obj
= bt_value_integer_create_init(-1);
84 BT_LOGE_STR("Cannot create integer value object.");
88 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
91 BT_LOGE("Cannot set event class's attributes's `id` field: ret=%d",
98 obj
= bt_value_string_create_init(name
);
100 BT_LOGE_STR("Cannot create string value object.");
104 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
107 BT_LOGE("Cannot set event class's attributes's `name` field: ret=%d",
113 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
114 event_class
, bt_ctf_event_class_get_name(event_class
));
123 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
125 struct bt_value
*obj
= NULL
;
126 const char *name
= NULL
;
130 BT_LOGW_STR("Invalid parameter: event class is NULL.");
134 if (event_class
->name
) {
135 name
= event_class
->name
;
139 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
140 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
142 ret
= bt_value_string_get(obj
, &name
);
150 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
152 struct bt_value
*obj
= NULL
;
157 BT_LOGW_STR("Invalid parameter: event class is NULL.");
162 if (event_class
->id
>= 0) {
163 ret
= (int64_t) event_class
->id
;
167 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
168 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
170 int_ret
= bt_value_integer_get(obj
, &ret
);
171 assert(int_ret
== 0);
173 /* means ID is not set */
174 BT_LOGV("Event class's ID is not set: addr=%p, name=\"%s\"",
175 event_class
, bt_ctf_event_class_get_name(event_class
));
185 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
189 struct bt_value
*obj
= NULL
;
190 int64_t id
= (int64_t) id_param
;
193 BT_LOGW_STR("Invalid parameter: event class is NULL.");
198 if (event_class
->frozen
) {
199 BT_LOGW("Invalid parameter: event class is frozen: "
200 "addr=%p, name=\"%s\", id=%" PRId64
,
201 event_class
, bt_ctf_event_class_get_name(event_class
),
202 bt_ctf_event_class_get_id(event_class
));
208 BT_LOGW("Invalid parameter: invalid event class's ID: "
209 "addr=%p, name=\"%s\", id=%" PRIu64
,
210 event_class
, bt_ctf_event_class_get_name(event_class
),
216 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
217 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
219 ret
= bt_value_integer_set(obj
, id
);
221 BT_LOGV("Set event class's ID: "
222 "addr=%p, name=\"%s\", id=%" PRId64
,
223 event_class
, bt_ctf_event_class_get_name(event_class
), id
);
230 int bt_ctf_event_class_set_attribute(
231 struct bt_ctf_event_class
*event_class
, const char *name
,
232 struct bt_value
*value
)
236 if (!event_class
|| !name
|| !value
) {
237 BT_LOGW("Invalid parameter: event class, name, or value is NULL: "
238 "event-class-addr=%p, name-addr=%p, value-addr=%p",
239 event_class
, name
, value
);
244 if (event_class
->frozen
) {
245 BT_LOGW("Invalid parameter: event class is frozen: "
246 "addr=%p, name=\"%s\", id=%" PRId64
", attr-name=\"%s\"",
247 event_class
, bt_ctf_event_class_get_name(event_class
),
248 bt_ctf_event_class_get_id(event_class
), name
);
253 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel") ||
254 !strcmp(name
, "stream_id")) {
255 if (!bt_value_is_integer(value
)) {
256 BT_LOGW("Invalid parameter: this event class's attribute must have an integer value: "
257 "event-class-addr=%p, event-class-name=\"%s\", "
258 "event-class-id=%" PRId64
", attr-name=\"%s\", "
259 "attr-type=%s", event_class
,
260 bt_ctf_event_class_get_name(event_class
),
261 bt_ctf_event_class_get_id(event_class
), name
,
262 bt_value_type_string(bt_value_get_type(value
)));
266 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri") ||
267 !strcmp(name
, "loglevel_string")) {
268 if (!bt_value_is_string(value
)) {
269 BT_LOGW("Invalid parameter: this event class's attribute must have a string value: "
270 "event-class-addr=%p, event-class-name=\"%s\", "
271 "event-class-id=%" PRId64
", attr-name=\"%s\", "
272 "attr-type=%s", event_class
,
273 bt_ctf_event_class_get_name(event_class
),
274 bt_ctf_event_class_get_id(event_class
), name
,
275 bt_value_type_string(bt_value_get_type(value
)));
280 /* unknown attribute */
281 BT_LOGW("Invalid parameter: unknown event class's attribute name: "
282 "event-class-addr=%p, event-class-name=\"%s\", "
283 "event-class-id=%" PRId64
", attr-name=\"%s\"",
284 event_class
, bt_ctf_event_class_get_name(event_class
),
285 bt_ctf_event_class_get_id(event_class
), name
);
290 /* "id" special case: >= 0 */
291 if (!strcmp(name
, "id")) {
294 ret
= bt_value_integer_get(value
, &val
);
296 BT_LOGV("Setting event's ID: id=%" PRId64
, val
);
297 ret
= bt_ctf_event_class_set_id(event_class
, (uint64_t) val
);
303 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
307 if (BT_LOG_ON_VERBOSE
) {
308 if (bt_value_is_integer(value
)) {
311 ret
= bt_value_integer_get(value
, &val
);
313 BT_LOGV("Set event class's integer attribute: "
314 "event-class-addr=%p, event-class-name=\"%s\", "
315 "event-class-id=%" PRId64
", attr-name=\"%s\", "
316 "attr-value=%" PRId64
,
317 event_class
, bt_ctf_event_class_get_name(event_class
),
318 bt_ctf_event_class_get_id(event_class
), name
,
320 } else if (bt_value_is_string(value
)) {
323 ret
= bt_value_string_get(value
, &val
);
325 BT_LOGV("Set event class's string attribute: "
326 "event-class-addr=%p, event-class-name=\"%s\", "
327 "event-class-id=%" PRId64
", attr-name=\"%s\", "
329 event_class
, bt_ctf_event_class_get_name(event_class
),
330 bt_ctf_event_class_get_id(event_class
), name
,
339 int64_t bt_ctf_event_class_get_attribute_count(
340 struct bt_ctf_event_class
*event_class
)
345 BT_LOGW_STR("Invalid parameter: event class is NULL.");
350 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
358 bt_ctf_event_class_get_attribute_name_by_index(
359 struct bt_ctf_event_class
*event_class
, uint64_t index
)
364 BT_LOGW_STR("Invalid parameter: event class is NULL.");
369 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
371 BT_LOGW("Cannot get event class's attribute name by index: "
372 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
373 event_class
, bt_ctf_event_class_get_name(event_class
),
374 bt_ctf_event_class_get_id(event_class
), index
);
382 bt_ctf_event_class_get_attribute_value_by_index(
383 struct bt_ctf_event_class
*event_class
, uint64_t index
)
385 struct bt_value
*ret
;
388 BT_LOGW_STR("Invalid parameter: event class is NULL.");
393 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
395 BT_LOGW("Cannot get event class's attribute value by index: "
396 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
397 event_class
, bt_ctf_event_class_get_name(event_class
),
398 bt_ctf_event_class_get_id(event_class
), index
);
406 bt_ctf_event_class_get_attribute_value_by_name(
407 struct bt_ctf_event_class
*event_class
, const char *name
)
409 struct bt_value
*ret
;
411 if (!event_class
|| !name
) {
412 BT_LOGW("Invalid parameter: event class or name is NULL: "
413 "event-class-addr=%p, name-addr=%p",
419 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
422 BT_LOGV("Cannot find event class's attribute: "
423 "addr=%p, event-class-name=\"%s\", id=%" PRId64
", "
425 event_class
, bt_ctf_event_class_get_name(event_class
),
426 bt_ctf_event_class_get_id(event_class
), name
);
434 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
435 struct bt_ctf_event_class
*event_class
)
438 bt_get(bt_ctf_event_class_borrow_stream_class(event_class
)) :
442 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
443 struct bt_ctf_event_class
*event_class
)
445 struct bt_ctf_field_type
*payload
= NULL
;
448 BT_LOGW_STR("Invalid parameter: event class is NULL.");
452 bt_get(event_class
->fields
);
453 payload
= event_class
->fields
;
458 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
459 struct bt_ctf_field_type
*payload
)
464 BT_LOGW_STR("Invalid parameter: event class is NULL.");
469 if (payload
&& bt_ctf_field_type_get_type_id(payload
) !=
470 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
471 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
472 "addr=%p, name=\"%s\", id=%" PRId64
", "
473 "payload-ft-addr=%p, payload-ft-id=%s",
474 event_class
, bt_ctf_event_class_get_name(event_class
),
475 bt_ctf_event_class_get_id(event_class
), payload
,
476 bt_ctf_field_type_id_string(
477 bt_ctf_field_type_get_type_id(payload
)));
482 bt_put(event_class
->fields
);
483 event_class
->fields
= bt_get(payload
);
484 BT_LOGV("Set event class's payload field type: "
485 "event-class-addr=%p, event-class-name=\"%s\", "
486 "event-class-id=%" PRId64
", payload-ft-addr=%p",
487 event_class
, bt_ctf_event_class_get_name(event_class
),
488 bt_ctf_event_class_get_id(event_class
), payload
);
493 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
494 struct bt_ctf_field_type
*type
,
499 if (!event_class
|| !type
) {
500 BT_LOGW("Invalid parameter: event class or field type is NULL: "
501 "event-class-addr=%p, field-type-addr=%p",
507 if (bt_ctf_validate_identifier(name
)) {
508 BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: "
509 "addr=%p, name=\"%s\", id=%" PRId64
", field-name=\"%s\"",
510 event_class
, bt_ctf_event_class_get_name(event_class
),
511 bt_ctf_event_class_get_id(event_class
),
517 if (event_class
->frozen
) {
518 BT_LOGW("Invalid parameter: event class is frozen: "
519 "addr=%p, name=\"%s\", id=%" PRId64
,
520 event_class
, bt_ctf_event_class_get_name(event_class
),
521 bt_ctf_event_class_get_id(event_class
));
526 if (!event_class
->fields
) {
527 BT_LOGW("Event class has no payload field type: "
528 "addr=%p, name=\"%s\", id=%" PRId64
,
529 event_class
, bt_ctf_event_class_get_name(event_class
),
530 bt_ctf_event_class_get_id(event_class
));
535 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
536 BT_CTF_FIELD_TYPE_ID_STRUCT
);
537 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
539 BT_LOGV("Added field to event class's payload field type: "
540 "event-class-addr=%p, event-class-name=\"%s\", "
541 "event-class-id=%" PRId64
", field-name=\"%s\", ft-addr=%p",
542 event_class
, bt_ctf_event_class_get_name(event_class
),
543 bt_ctf_event_class_get_id(event_class
), name
, type
);
548 int64_t bt_ctf_event_class_get_payload_type_field_count(
549 struct bt_ctf_event_class
*event_class
)
554 BT_LOGW_STR("Invalid parameter: event class is NULL.");
559 if (!event_class
->fields
) {
560 BT_LOGV("Event class has no payload field type: "
561 "addr=%p, name=\"%s\", id=%" PRId64
,
562 event_class
, bt_ctf_event_class_get_name(event_class
),
563 bt_ctf_event_class_get_id(event_class
));
568 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
569 BT_CTF_FIELD_TYPE_ID_STRUCT
);
570 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
575 int bt_ctf_event_class_get_payload_type_field_by_index(
576 struct bt_ctf_event_class
*event_class
,
577 const char **field_name
, struct bt_ctf_field_type
**field_type
,
583 BT_LOGW_STR("Invalid parameter: event class is NULL.");
588 if (!event_class
->fields
) {
589 BT_LOGV("Event class has no payload field type: "
590 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
591 event_class
, bt_ctf_event_class_get_name(event_class
),
592 bt_ctf_event_class_get_id(event_class
), index
);
597 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
598 BT_CTF_FIELD_TYPE_ID_STRUCT
);
599 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
600 field_name
, field_type
, index
);
605 struct bt_ctf_field_type
*
606 bt_ctf_event_class_get_payload_type_field_type_by_name(
607 struct bt_ctf_event_class
*event_class
, const char *name
)
610 struct bt_ctf_field_type
*field_type
= NULL
;
612 if (!event_class
|| !name
) {
613 BT_LOGW("Invalid parameter: event class or name is NULL: "
614 "event-class-addr=%p, name-addr=%p",
619 if (!event_class
->fields
) {
620 BT_LOGV("Event class has no payload field type: "
621 "addr=%p, name=\"%s\", id=%" PRId64
,
622 event_class
, bt_ctf_event_class_get_name(event_class
),
623 bt_ctf_event_class_get_id(event_class
));
627 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
628 BT_CTF_FIELD_TYPE_ID_STRUCT
);
629 name_quark
= g_quark_try_string(name
);
631 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
636 * No need to increment field_type's reference count since getting it
637 * from the structure already does.
639 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
640 event_class
->fields
, name
);
645 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
646 struct bt_ctf_event_class
*event_class
)
648 struct bt_ctf_field_type
*context_type
= NULL
;
651 BT_LOGW_STR("Invalid parameter: event class is NULL.");
655 if (!event_class
->context
) {
656 BT_LOGV("Event class has no context field type: "
657 "addr=%p, name=\"%s\", id=%" PRId64
,
658 event_class
, bt_ctf_event_class_get_name(event_class
),
659 bt_ctf_event_class_get_id(event_class
));
663 bt_get(event_class
->context
);
664 context_type
= event_class
->context
;
669 int bt_ctf_event_class_set_context_type(
670 struct bt_ctf_event_class
*event_class
,
671 struct bt_ctf_field_type
*context
)
676 BT_LOGW_STR("Invalid parameter: event class is NULL.");
681 if (event_class
->frozen
) {
682 BT_LOGW("Invalid parameter: event class is frozen: "
683 "addr=%p, name=\"%s\", id=%" PRId64
,
684 event_class
, bt_ctf_event_class_get_name(event_class
),
685 bt_ctf_event_class_get_id(event_class
));
690 if (context
&& bt_ctf_field_type_get_type_id(context
) !=
691 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
692 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
693 "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
),
697 bt_ctf_field_type_id_string(
698 bt_ctf_field_type_get_type_id(context
)));
703 bt_put(event_class
->context
);
704 event_class
->context
= bt_get(context
);
705 BT_LOGV("Set event class's context field type: "
706 "event-class-addr=%p, event-class-name=\"%s\", "
707 "event-class-id=%" PRId64
", context-ft-addr=%p",
708 event_class
, bt_ctf_event_class_get_name(event_class
),
709 bt_ctf_event_class_get_id(event_class
), context
);
715 /* Pre-2.0 CTF writer backward compatibility */
716 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
721 /* Pre-2.0 CTF writer backward compatibility */
722 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
728 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
729 uint64_t stream_id_param
)
732 struct bt_value
*obj
= NULL
;
733 int64_t stream_id
= (int64_t) stream_id_param
;
736 assert(stream_id
>= 0);
737 obj
= bt_value_integer_create_init(stream_id
);
739 BT_LOGE_STR("Cannot create integer value object.");
744 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
747 BT_LOGE("Cannot set event class's attributes's `stream_id` field: "
748 "addr=%p, name=\"%s\", id=%" PRId64
", ret=%d",
749 event_class
, bt_ctf_event_class_get_name(event_class
),
750 bt_ctf_event_class_get_id(event_class
), ret
);
754 if (event_class
->frozen
) {
755 BT_LOGV_STR("Freezing event class's attributes because event class is frozen.");
756 bt_ctf_attributes_freeze(event_class
->attributes
);
759 BT_LOGV("Set event class's stream class ID: "
760 "event-class-addr=%p, event-class-name=\"%s\", "
761 "event-class-id=%" PRId64
", stream-class-id=%" PRId64
,
762 event_class
, bt_ctf_event_class_get_name(event_class
),
763 bt_ctf_event_class_get_id(event_class
), stream_id
);
771 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
773 struct bt_ctf_event_class
*event_class
;
775 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
776 BT_LOGD("Destroying event class: addr=%p, name=\"%s\", id=%" PRId64
,
777 event_class
, bt_ctf_event_class_get_name(event_class
),
778 bt_ctf_event_class_get_id(event_class
));
779 BT_LOGD_STR("Destroying event class's attributes.");
780 bt_ctf_attributes_destroy(event_class
->attributes
);
781 BT_LOGD_STR("Putting context field type.");
782 bt_put(event_class
->context
);
783 BT_LOGD_STR("Putting payload field type.");
784 bt_put(event_class
->fields
);
789 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
793 if (event_class
->frozen
) {
797 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
798 event_class
, bt_ctf_event_class_get_name(event_class
),
799 bt_ctf_event_class_get_id(event_class
));
800 event_class
->frozen
= 1;
801 event_class
->name
= bt_ctf_event_class_get_name(event_class
);
802 event_class
->id
= bt_ctf_event_class_get_id(event_class
);
803 BT_LOGD_STR("Freezing event class's context field type.");
804 bt_ctf_field_type_freeze(event_class
->context
);
805 BT_LOGD_STR("Freezing event class's payload field type.");
806 bt_ctf_field_type_freeze(event_class
->fields
);
807 BT_LOGD_STR("Freezing event class's attributes.");
808 bt_ctf_attributes_freeze(event_class
->attributes
);
812 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
813 struct metadata_context
*context
)
818 struct bt_value
*attr_value
= NULL
;
822 BT_LOGD("Serializing event class's metadata: "
823 "event-class-addr=%p, event-class-name=\"%s\", "
824 "event-class-id=%" PRId64
", metadata-context-addr=%p",
825 event_class
, bt_ctf_event_class_get_name(event_class
),
826 bt_ctf_event_class_get_id(event_class
), context
);
827 context
->current_indentation_level
= 1;
828 g_string_assign(context
->field_name
, "");
829 g_string_append(context
->string
, "event {\n");
830 count
= bt_ctf_event_class_get_attribute_count(event_class
);
833 for (i
= 0; i
< count
; ++i
) {
834 const char *attr_name
= NULL
;
836 attr_name
= bt_ctf_event_class_get_attribute_name_by_index(
839 attr_value
= bt_ctf_event_class_get_attribute_value_by_index(
843 switch (bt_value_get_type(attr_value
)) {
844 case BT_VALUE_TYPE_INTEGER
:
848 ret
= bt_value_integer_get(attr_value
, &value
);
850 g_string_append_printf(context
->string
,
851 "\t%s = %" PRId64
";\n", attr_name
, value
);
855 case BT_VALUE_TYPE_STRING
:
859 ret
= bt_value_string_get(attr_value
, &value
);
861 g_string_append_printf(context
->string
,
862 "\t%s = \"%s\";\n", attr_name
, value
);
867 /* should never happen */
875 if (event_class
->context
) {
876 g_string_append(context
->string
, "\tcontext := ");
877 BT_LOGD_STR("Serializing event class's context field type metadata.");
878 ret
= bt_ctf_field_type_serialize(event_class
->context
,
881 BT_LOGW("Cannot serialize event class's context field type's metadata: "
885 g_string_append(context
->string
, ";\n");
888 if (event_class
->fields
) {
889 g_string_append(context
->string
, "\tfields := ");
890 BT_LOGD_STR("Serializing event class's payload field type metadata.");
891 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
893 BT_LOGW("Cannot serialize event class's payload field type's metadata: "
897 g_string_append(context
->string
, ";\n");
900 g_string_append(context
->string
, "};\n\n");
902 context
->current_indentation_level
= 0;