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 ret
= bt_ctf_event_class_set_id(event_class
, (uint64_t) val
);
313 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
317 if (BT_LOG_ON_VERBOSE
) {
318 if (bt_value_is_integer(value
)) {
321 ret
= bt_value_integer_get(value
, &val
);
323 BT_LOGV("Set event class's integer attribute: "
324 "event-class-addr=%p, event-class-name=\"%s\", "
325 "event-class-id=%" PRId64
", attr-name=\"%s\", "
326 "attr-value=%" PRId64
,
327 event_class
, bt_ctf_event_class_get_name(event_class
),
328 bt_ctf_event_class_get_id(event_class
), name
,
330 } else if (bt_value_is_string(value
)) {
333 ret
= bt_value_string_get(value
, &val
);
335 BT_LOGV("Set event class's string attribute: "
336 "event-class-addr=%p, event-class-name=\"%s\", "
337 "event-class-id=%" PRId64
", attr-name=\"%s\", "
339 event_class
, bt_ctf_event_class_get_name(event_class
),
340 bt_ctf_event_class_get_id(event_class
), name
,
349 int64_t bt_ctf_event_class_get_attribute_count(
350 struct bt_ctf_event_class
*event_class
)
355 BT_LOGW_STR("Invalid parameter: event class is NULL.");
360 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
368 bt_ctf_event_class_get_attribute_name_by_index(
369 struct bt_ctf_event_class
*event_class
, uint64_t index
)
374 BT_LOGW_STR("Invalid parameter: event class is NULL.");
379 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
381 BT_LOGW("Cannot get event class's attribute name by index: "
382 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
383 event_class
, bt_ctf_event_class_get_name(event_class
),
384 bt_ctf_event_class_get_id(event_class
), index
);
392 bt_ctf_event_class_get_attribute_value_by_index(
393 struct bt_ctf_event_class
*event_class
, uint64_t index
)
395 struct bt_value
*ret
;
398 BT_LOGW_STR("Invalid parameter: event class is NULL.");
403 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
405 BT_LOGW("Cannot get event class's attribute value by index: "
406 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
407 event_class
, bt_ctf_event_class_get_name(event_class
),
408 bt_ctf_event_class_get_id(event_class
), index
);
416 bt_ctf_event_class_get_attribute_value_by_name(
417 struct bt_ctf_event_class
*event_class
, const char *name
)
419 struct bt_value
*ret
;
421 if (!event_class
|| !name
) {
422 BT_LOGW("Invalid parameter: event class or name is NULL: ",
423 "event-class-addr=%p, name-addr=%p",
429 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
432 BT_LOGV("Cannot find event class's attribute: "
433 "addr=%p, event-class-name=\"%s\", id=%" PRId64
", "
435 event_class
, bt_ctf_event_class_get_name(event_class
),
436 bt_ctf_event_class_get_id(event_class
), name
);
444 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
445 struct bt_ctf_event_class
*event_class
)
448 bt_get(bt_ctf_event_class_borrow_stream_class(event_class
)) :
452 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
453 struct bt_ctf_event_class
*event_class
)
455 struct bt_ctf_field_type
*payload
= NULL
;
458 BT_LOGW_STR("Invalid parameter: event class is NULL.");
462 bt_get(event_class
->fields
);
463 payload
= event_class
->fields
;
468 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
469 struct bt_ctf_field_type
*payload
)
474 BT_LOGW_STR("Invalid parameter: event class is NULL.");
479 if (payload
&& bt_ctf_field_type_get_type_id(payload
) !=
480 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
481 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
482 "addr=%p, name=\"%s\", id=%" PRId64
", "
483 "payload-ft-addr=%p, payload-ft-id=%s",
484 event_class
, bt_ctf_event_class_get_name(event_class
),
485 bt_ctf_event_class_get_id(event_class
), payload
,
486 bt_ctf_field_type_id_string(
487 bt_ctf_field_type_get_type_id(payload
)));
492 bt_put(event_class
->fields
);
493 event_class
->fields
= bt_get(payload
);
494 BT_LOGV("Set event class's payload field type: "
495 "event-class-addr=%p, event-class-name=\"%s\", "
496 "event-class-id=%" PRId64
", payload-ft-addr=%p",
497 event_class
, bt_ctf_event_class_get_name(event_class
),
498 bt_ctf_event_class_get_id(event_class
), payload
);
503 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
504 struct bt_ctf_field_type
*type
,
509 if (!event_class
|| !type
) {
510 BT_LOGW("Invalid parameter: event class or field type is NULL: "
511 "event-class-addr=%p, field-type-addr=%p",
517 if (bt_ctf_validate_identifier(name
)) {
518 BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: "
519 "addr=%p, name=\"%s\", id=%" PRId64
", field-name=\"%s\"",
520 event_class
, bt_ctf_event_class_get_name(event_class
),
521 bt_ctf_event_class_get_id(event_class
),
527 if (event_class
->frozen
) {
528 BT_LOGW("Invalid parameter: event class is frozen: "
529 "addr=%p, name=\"%s\", id=%" PRId64
,
530 event_class
, bt_ctf_event_class_get_name(event_class
),
531 bt_ctf_event_class_get_id(event_class
));
536 if (!event_class
->fields
) {
537 BT_LOGW("Event class has no payload field type: "
538 "addr=%p, name=\"%s\", id=%" PRId64
,
539 event_class
, bt_ctf_event_class_get_name(event_class
),
540 bt_ctf_event_class_get_id(event_class
));
545 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
546 BT_CTF_FIELD_TYPE_ID_STRUCT
);
547 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
549 BT_LOGV("Added field to event class's payload field type: "
550 "event-class-addr=%p, event-class-name=\"%s\", "
551 "event-class-id=%" PRId64
", field-name=\"%s\", ft-addr=%p",
552 event_class
, bt_ctf_event_class_get_name(event_class
),
553 bt_ctf_event_class_get_id(event_class
), name
, type
);
558 int64_t bt_ctf_event_class_get_payload_type_field_count(
559 struct bt_ctf_event_class
*event_class
)
564 BT_LOGW_STR("Invalid parameter: event class is NULL.");
569 if (!event_class
->fields
) {
570 BT_LOGV("Event class has no payload field type: "
571 "addr=%p, name=\"%s\", id=%" PRId64
,
572 event_class
, bt_ctf_event_class_get_name(event_class
),
573 bt_ctf_event_class_get_id(event_class
));
578 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
579 BT_CTF_FIELD_TYPE_ID_STRUCT
);
580 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
585 int bt_ctf_event_class_get_payload_type_field_by_index(
586 struct bt_ctf_event_class
*event_class
,
587 const char **field_name
, struct bt_ctf_field_type
**field_type
,
593 BT_LOGW_STR("Invalid parameter: event class is NULL.");
598 if (!event_class
->fields
) {
599 BT_LOGV("Event class has no payload field type: "
600 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
601 event_class
, bt_ctf_event_class_get_name(event_class
),
602 bt_ctf_event_class_get_id(event_class
), index
);
607 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
608 BT_CTF_FIELD_TYPE_ID_STRUCT
);
609 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
610 field_name
, field_type
, index
);
615 struct bt_ctf_field_type
*
616 bt_ctf_event_class_get_payload_type_field_type_by_name(
617 struct bt_ctf_event_class
*event_class
, const char *name
)
620 struct bt_ctf_field_type
*field_type
= NULL
;
622 if (!event_class
|| !name
) {
623 BT_LOGW("Invalid parameter: event class or name is NULL: ",
624 "event-class-addr=%p, name-addr=%p",
629 if (!event_class
->fields
) {
630 BT_LOGV("Event class has no payload field type: "
631 "addr=%p, name=\"%s\", id=%" PRId64
,
632 event_class
, bt_ctf_event_class_get_name(event_class
),
633 bt_ctf_event_class_get_id(event_class
));
637 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
638 BT_CTF_FIELD_TYPE_ID_STRUCT
);
639 name_quark
= g_quark_try_string(name
);
641 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
646 * No need to increment field_type's reference count since getting it
647 * from the structure already does.
649 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
650 event_class
->fields
, name
);
655 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
656 struct bt_ctf_event_class
*event_class
)
658 struct bt_ctf_field_type
*context_type
= NULL
;
661 BT_LOGW_STR("Invalid parameter: event class is NULL.");
665 if (!event_class
->context
) {
666 BT_LOGV("Event class has no context field type: "
667 "addr=%p, name=\"%s\", id=%" PRId64
,
668 event_class
, bt_ctf_event_class_get_name(event_class
),
669 bt_ctf_event_class_get_id(event_class
));
673 bt_get(event_class
->context
);
674 context_type
= event_class
->context
;
679 int bt_ctf_event_class_set_context_type(
680 struct bt_ctf_event_class
*event_class
,
681 struct bt_ctf_field_type
*context
)
686 BT_LOGW_STR("Invalid parameter: event class is NULL.");
691 if (event_class
->frozen
) {
692 BT_LOGW("Invalid parameter: event class is frozen: "
693 "addr=%p, name=\"%s\", id=%" PRId64
,
694 event_class
, bt_ctf_event_class_get_name(event_class
),
695 bt_ctf_event_class_get_id(event_class
));
700 if (context
&& bt_ctf_field_type_get_type_id(context
) !=
701 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
702 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
703 "addr=%p, name=\"%s\", id=%" PRId64
", "
705 event_class
, bt_ctf_event_class_get_name(event_class
),
706 bt_ctf_event_class_get_id(event_class
),
707 bt_ctf_field_type_id_string(
708 bt_ctf_field_type_get_type_id(context
)));
713 bt_put(event_class
->context
);
714 event_class
->context
= bt_get(context
);
715 BT_LOGV("Set event class's context field type: "
716 "event-class-addr=%p, event-class-name=\"%s\", "
717 "event-class-id=%" PRId64
", context-ft-addr=%p",
718 event_class
, bt_ctf_event_class_get_name(event_class
),
719 bt_ctf_event_class_get_id(event_class
), context
);
725 /* Pre-2.0 CTF writer backward compatibility */
726 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
731 /* Pre-2.0 CTF writer backward compatibility */
732 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
738 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
739 uint64_t stream_id_param
)
742 struct bt_value
*obj
= NULL
;
743 int64_t stream_id
= (int64_t) stream_id_param
;
746 assert(stream_id
>= 0);
747 obj
= bt_value_integer_create_init(stream_id
);
749 BT_LOGE_STR("Cannot create integer value object.");
754 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
757 BT_LOGE("Cannot set event class's attributes's `stream_id` field: "
758 "addr=%p, name=\"%s\", id=%" PRId64
", ret=%d",
759 event_class
, bt_ctf_event_class_get_name(event_class
),
760 bt_ctf_event_class_get_id(event_class
), ret
);
764 if (event_class
->frozen
) {
765 BT_LOGV_STR("Freezing event class's attributes because event class is frozen.");
766 bt_ctf_attributes_freeze(event_class
->attributes
);
769 BT_LOGV("Set event class's stream class ID: "
770 "event-class-addr=%p, event-class-name=\"%s\", "
771 "event-class-id=%" PRId64
", stream-class-id=%" PRId64
,
772 event_class
, bt_ctf_event_class_get_name(event_class
),
773 bt_ctf_event_class_get_id(event_class
), stream_id
);
781 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
783 struct bt_ctf_event_class
*event_class
;
785 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
786 BT_LOGD("Destroying event class: addr=%p, name=\"%s\", id=%" PRId64
,
787 event_class
, bt_ctf_event_class_get_name(event_class
),
788 bt_ctf_event_class_get_id(event_class
));
789 bt_ctf_attributes_destroy(event_class
->attributes
);
790 bt_put(event_class
->context
);
791 bt_put(event_class
->fields
);
796 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
800 if (event_class
->frozen
) {
804 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
805 event_class
, bt_ctf_event_class_get_name(event_class
),
806 bt_ctf_event_class_get_id(event_class
));
807 event_class
->frozen
= 1;
808 event_class
->name
= bt_ctf_event_class_get_name(event_class
);
809 event_class
->id
= bt_ctf_event_class_get_id(event_class
);
810 bt_ctf_field_type_freeze(event_class
->context
);
811 bt_ctf_field_type_freeze(event_class
->fields
);
812 bt_ctf_attributes_freeze(event_class
->attributes
);
816 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
817 struct metadata_context
*context
)
822 struct bt_value
*attr_value
= NULL
;
826 BT_LOGD("Serializing event class's metadata: "
827 "event-class-addr=%p, event-class-name=\"%s\", "
828 "event-class-id=%" PRId64
", metadata-context-addr=%p",
829 event_class
, bt_ctf_event_class_get_name(event_class
),
830 bt_ctf_event_class_get_id(event_class
), context
);
831 context
->current_indentation_level
= 1;
832 g_string_assign(context
->field_name
, "");
833 g_string_append(context
->string
, "event {\n");
834 count
= bt_ctf_event_class_get_attribute_count(event_class
);
837 for (i
= 0; i
< count
; ++i
) {
838 const char *attr_name
= NULL
;
840 attr_name
= bt_ctf_event_class_get_attribute_name_by_index(
843 attr_value
= bt_ctf_event_class_get_attribute_value_by_index(
847 switch (bt_value_get_type(attr_value
)) {
848 case BT_VALUE_TYPE_INTEGER
:
852 ret
= bt_value_integer_get(attr_value
, &value
);
854 g_string_append_printf(context
->string
,
855 "\t%s = %" PRId64
";\n", attr_name
, value
);
859 case BT_VALUE_TYPE_STRING
:
863 ret
= bt_value_string_get(attr_value
, &value
);
865 g_string_append_printf(context
->string
,
866 "\t%s = \"%s\";\n", attr_name
, value
);
871 /* should never happen */
879 if (event_class
->context
) {
880 g_string_append(context
->string
, "\tcontext := ");
881 ret
= bt_ctf_field_type_serialize(event_class
->context
,
884 BT_LOGE("Cannot serialize event class's context field type's metadata: "
888 g_string_append(context
->string
, ";\n");
891 if (event_class
->fields
) {
892 g_string_append(context
->string
, "\tfields := ");
893 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
895 BT_LOGE("Cannot serialize event class's payload field type's metadata: "
899 g_string_append(context
->string
, ";\n");
902 g_string_append(context
->string
, "};\n\n");
904 context
->current_indentation_level
= 0;