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
->context
= bt_ctf_field_type_structure_create();
83 if (!event_class
->context
) {
84 BT_LOGE_STR("Cannot create event class's initial context field type object.");
88 event_class
->attributes
= bt_ctf_attributes_create();
89 if (!event_class
->attributes
) {
90 BT_LOGE_STR("Cannot create event class's attributes object.");
94 obj
= bt_value_integer_create_init(-1);
96 BT_LOGE_STR("Cannot create integer value object.");
100 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
103 BT_LOGE("Cannot set event class's attributes's `id` field: ret=%d",
110 obj
= bt_value_string_create_init(name
);
112 BT_LOGE_STR("Cannot create string value object.");
116 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
119 BT_LOGE("Cannot set event class's attributes's `name` field: ret=%d",
125 BT_LOGD("Created event class object: addr=%p, name=\"%s\"",
126 event_class
, bt_ctf_event_class_get_name(event_class
));
135 const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class
*event_class
)
137 struct bt_value
*obj
= NULL
;
138 const char *name
= NULL
;
142 BT_LOGW_STR("Invalid parameter: event class is NULL.");
146 if (event_class
->name
) {
147 name
= event_class
->name
;
151 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
152 BT_CTF_EVENT_CLASS_ATTR_NAME_INDEX
);
154 ret
= bt_value_string_get(obj
, &name
);
162 int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class
*event_class
)
164 struct bt_value
*obj
= NULL
;
169 BT_LOGW_STR("Invalid parameter: event class is NULL.");
174 if (event_class
->id
>= 0) {
175 ret
= (int64_t) event_class
->id
;
179 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
180 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
182 int_ret
= bt_value_integer_get(obj
, &ret
);
183 assert(int_ret
== 0);
185 /* means ID is not set */
186 BT_LOGV("Event class's ID is not set: addr=%p, name=\"%s\"",
187 event_class
, bt_ctf_event_class_get_name(event_class
));
197 int bt_ctf_event_class_set_id(struct bt_ctf_event_class
*event_class
,
201 struct bt_value
*obj
= NULL
;
202 int64_t id
= (int64_t) id_param
;
205 BT_LOGW_STR("Invalid parameter: event class is NULL.");
210 if (event_class
->frozen
) {
211 BT_LOGW("Invalid parameter: event class is frozen: "
212 "addr=%p, name=\"%s\", id=%" PRId64
,
213 event_class
, bt_ctf_event_class_get_name(event_class
),
214 bt_ctf_event_class_get_id(event_class
));
220 BT_LOGW("Invalid parameter: invalid event class's ID: "
221 "addr=%p, name=\"%s\", id=%" PRIu64
,
222 event_class
, bt_ctf_event_class_get_name(event_class
),
228 obj
= bt_ctf_attributes_get_field_value(event_class
->attributes
,
229 BT_CTF_EVENT_CLASS_ATTR_ID_INDEX
);
231 ret
= bt_value_integer_set(obj
, id
);
233 BT_LOGV("Set event class's ID: "
234 "addr=%p, name=\"%s\", id=%" PRId64
,
235 event_class
, bt_ctf_event_class_get_name(event_class
), id
);
242 int bt_ctf_event_class_set_attribute(
243 struct bt_ctf_event_class
*event_class
, const char *name
,
244 struct bt_value
*value
)
248 if (!event_class
|| !name
|| !value
) {
249 BT_LOGW("Invalid parameter: event class, name, or value is NULL: "
250 "event-class-addr=%p, name-addr=%p, value-addr=%p",
251 event_class
, name
, value
);
256 if (event_class
->frozen
) {
257 BT_LOGW("Invalid parameter: event class is frozen: "
258 "addr=%p, name=\"%s\", id=%" PRId64
", attr-name=\"%s\"",
259 event_class
, bt_ctf_event_class_get_name(event_class
),
260 bt_ctf_event_class_get_id(event_class
), name
);
265 if (!strcmp(name
, "id") || !strcmp(name
, "loglevel") ||
266 !strcmp(name
, "stream_id")) {
267 if (!bt_value_is_integer(value
)) {
268 BT_LOGW("Invalid parameter: this event class's attribute must have an integer value: "
269 "event-class-addr=%p, event-class-name=\"%s\", "
270 "event-class-id=%" PRId64
", attr-name=\"%s\", "
271 "attr-type=%s", event_class
,
272 bt_ctf_event_class_get_name(event_class
),
273 bt_ctf_event_class_get_id(event_class
), name
,
274 bt_value_type_string(bt_value_get_type(value
)));
278 } else if (!strcmp(name
, "name") || !strcmp(name
, "model.emf.uri") ||
279 !strcmp(name
, "loglevel_string")) {
280 if (!bt_value_is_string(value
)) {
281 BT_LOGW("Invalid parameter: this event class's attribute must have a string value: "
282 "event-class-addr=%p, event-class-name=\"%s\", "
283 "event-class-id=%" PRId64
", attr-name=\"%s\", "
284 "attr-type=%s", event_class
,
285 bt_ctf_event_class_get_name(event_class
),
286 bt_ctf_event_class_get_id(event_class
), name
,
287 bt_value_type_string(bt_value_get_type(value
)));
292 /* unknown attribute */
293 BT_LOGW("Invalid parameter: unknown event class's attribute name: "
294 "event-class-addr=%p, event-class-name=\"%s\", "
295 "event-class-id=%" PRId64
", attr-name=\"%s\"",
296 event_class
, bt_ctf_event_class_get_name(event_class
),
297 bt_ctf_event_class_get_id(event_class
), name
);
302 /* "id" special case: >= 0 */
303 if (!strcmp(name
, "id")) {
306 ret
= bt_value_integer_get(value
, &val
);
308 BT_LOGV("Setting event's ID: id=%" PRId64
, val
);
309 ret
= bt_ctf_event_class_set_id(event_class
, (uint64_t) val
);
315 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
319 if (BT_LOG_ON_VERBOSE
) {
320 if (bt_value_is_integer(value
)) {
323 ret
= bt_value_integer_get(value
, &val
);
325 BT_LOGV("Set event class's integer attribute: "
326 "event-class-addr=%p, event-class-name=\"%s\", "
327 "event-class-id=%" PRId64
", attr-name=\"%s\", "
328 "attr-value=%" PRId64
,
329 event_class
, bt_ctf_event_class_get_name(event_class
),
330 bt_ctf_event_class_get_id(event_class
), name
,
332 } else if (bt_value_is_string(value
)) {
335 ret
= bt_value_string_get(value
, &val
);
337 BT_LOGV("Set event class's string attribute: "
338 "event-class-addr=%p, event-class-name=\"%s\", "
339 "event-class-id=%" PRId64
", attr-name=\"%s\", "
341 event_class
, bt_ctf_event_class_get_name(event_class
),
342 bt_ctf_event_class_get_id(event_class
), name
,
351 int64_t bt_ctf_event_class_get_attribute_count(
352 struct bt_ctf_event_class
*event_class
)
357 BT_LOGW_STR("Invalid parameter: event class is NULL.");
362 ret
= bt_ctf_attributes_get_count(event_class
->attributes
);
370 bt_ctf_event_class_get_attribute_name_by_index(
371 struct bt_ctf_event_class
*event_class
, uint64_t index
)
376 BT_LOGW_STR("Invalid parameter: event class is NULL.");
381 ret
= bt_ctf_attributes_get_field_name(event_class
->attributes
, index
);
383 BT_LOGW("Cannot get event class's attribute name by index: "
384 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
385 event_class
, bt_ctf_event_class_get_name(event_class
),
386 bt_ctf_event_class_get_id(event_class
), index
);
394 bt_ctf_event_class_get_attribute_value_by_index(
395 struct bt_ctf_event_class
*event_class
, uint64_t index
)
397 struct bt_value
*ret
;
400 BT_LOGW_STR("Invalid parameter: event class is NULL.");
405 ret
= bt_ctf_attributes_get_field_value(event_class
->attributes
, index
);
407 BT_LOGW("Cannot get event class's attribute value by index: "
408 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
409 event_class
, bt_ctf_event_class_get_name(event_class
),
410 bt_ctf_event_class_get_id(event_class
), index
);
418 bt_ctf_event_class_get_attribute_value_by_name(
419 struct bt_ctf_event_class
*event_class
, const char *name
)
421 struct bt_value
*ret
;
423 if (!event_class
|| !name
) {
424 BT_LOGW("Invalid parameter: event class or name is NULL: "
425 "event-class-addr=%p, name-addr=%p",
431 ret
= bt_ctf_attributes_get_field_value_by_name(event_class
->attributes
,
434 BT_LOGV("Cannot find event class's attribute: "
435 "addr=%p, event-class-name=\"%s\", id=%" PRId64
", "
437 event_class
, bt_ctf_event_class_get_name(event_class
),
438 bt_ctf_event_class_get_id(event_class
), name
);
446 struct bt_ctf_stream_class
*bt_ctf_event_class_get_stream_class(
447 struct bt_ctf_event_class
*event_class
)
450 bt_get(bt_ctf_event_class_borrow_stream_class(event_class
)) :
454 struct bt_ctf_field_type
*bt_ctf_event_class_get_payload_type(
455 struct bt_ctf_event_class
*event_class
)
457 struct bt_ctf_field_type
*payload
= NULL
;
460 BT_LOGW_STR("Invalid parameter: event class is NULL.");
464 bt_get(event_class
->fields
);
465 payload
= event_class
->fields
;
470 int bt_ctf_event_class_set_payload_type(struct bt_ctf_event_class
*event_class
,
471 struct bt_ctf_field_type
*payload
)
476 BT_LOGW_STR("Invalid parameter: event class is NULL.");
481 if (payload
&& bt_ctf_field_type_get_type_id(payload
) !=
482 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
483 BT_LOGW("Invalid parameter: event class's payload field type must be a structure: "
484 "addr=%p, name=\"%s\", id=%" PRId64
", "
485 "payload-ft-addr=%p, payload-ft-id=%s",
486 event_class
, bt_ctf_event_class_get_name(event_class
),
487 bt_ctf_event_class_get_id(event_class
), payload
,
488 bt_ctf_field_type_id_string(
489 bt_ctf_field_type_get_type_id(payload
)));
494 bt_put(event_class
->fields
);
495 event_class
->fields
= bt_get(payload
);
496 BT_LOGV("Set event class's payload field type: "
497 "event-class-addr=%p, event-class-name=\"%s\", "
498 "event-class-id=%" PRId64
", payload-ft-addr=%p",
499 event_class
, bt_ctf_event_class_get_name(event_class
),
500 bt_ctf_event_class_get_id(event_class
), payload
);
505 int bt_ctf_event_class_add_field(struct bt_ctf_event_class
*event_class
,
506 struct bt_ctf_field_type
*type
,
511 if (!event_class
|| !type
) {
512 BT_LOGW("Invalid parameter: event class or field type is NULL: "
513 "event-class-addr=%p, field-type-addr=%p",
519 if (bt_ctf_validate_identifier(name
)) {
520 BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: "
521 "addr=%p, name=\"%s\", id=%" PRId64
", field-name=\"%s\"",
522 event_class
, bt_ctf_event_class_get_name(event_class
),
523 bt_ctf_event_class_get_id(event_class
),
529 if (event_class
->frozen
) {
530 BT_LOGW("Invalid parameter: event class is frozen: "
531 "addr=%p, name=\"%s\", id=%" PRId64
,
532 event_class
, bt_ctf_event_class_get_name(event_class
),
533 bt_ctf_event_class_get_id(event_class
));
538 if (!event_class
->fields
) {
539 BT_LOGW("Event class has no payload field type: "
540 "addr=%p, name=\"%s\", id=%" PRId64
,
541 event_class
, bt_ctf_event_class_get_name(event_class
),
542 bt_ctf_event_class_get_id(event_class
));
547 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
548 BT_CTF_FIELD_TYPE_ID_STRUCT
);
549 ret
= bt_ctf_field_type_structure_add_field(event_class
->fields
,
551 BT_LOGV("Added field to event class's payload field type: "
552 "event-class-addr=%p, event-class-name=\"%s\", "
553 "event-class-id=%" PRId64
", field-name=\"%s\", ft-addr=%p",
554 event_class
, bt_ctf_event_class_get_name(event_class
),
555 bt_ctf_event_class_get_id(event_class
), name
, type
);
560 int64_t bt_ctf_event_class_get_payload_type_field_count(
561 struct bt_ctf_event_class
*event_class
)
566 BT_LOGW_STR("Invalid parameter: event class is NULL.");
571 if (!event_class
->fields
) {
572 BT_LOGV("Event class has no payload field type: "
573 "addr=%p, name=\"%s\", id=%" PRId64
,
574 event_class
, bt_ctf_event_class_get_name(event_class
),
575 bt_ctf_event_class_get_id(event_class
));
580 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
581 BT_CTF_FIELD_TYPE_ID_STRUCT
);
582 ret
= bt_ctf_field_type_structure_get_field_count(event_class
->fields
);
587 int bt_ctf_event_class_get_payload_type_field_by_index(
588 struct bt_ctf_event_class
*event_class
,
589 const char **field_name
, struct bt_ctf_field_type
**field_type
,
595 BT_LOGW_STR("Invalid parameter: event class is NULL.");
600 if (!event_class
->fields
) {
601 BT_LOGV("Event class has no payload field type: "
602 "addr=%p, name=\"%s\", id=%" PRId64
", index=%" PRIu64
,
603 event_class
, bt_ctf_event_class_get_name(event_class
),
604 bt_ctf_event_class_get_id(event_class
), index
);
609 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
610 BT_CTF_FIELD_TYPE_ID_STRUCT
);
611 ret
= bt_ctf_field_type_structure_get_field(event_class
->fields
,
612 field_name
, field_type
, index
);
617 struct bt_ctf_field_type
*
618 bt_ctf_event_class_get_payload_type_field_type_by_name(
619 struct bt_ctf_event_class
*event_class
, const char *name
)
622 struct bt_ctf_field_type
*field_type
= NULL
;
624 if (!event_class
|| !name
) {
625 BT_LOGW("Invalid parameter: event class or name is NULL: "
626 "event-class-addr=%p, name-addr=%p",
631 if (!event_class
->fields
) {
632 BT_LOGV("Event class has no payload field type: "
633 "addr=%p, name=\"%s\", id=%" PRId64
,
634 event_class
, bt_ctf_event_class_get_name(event_class
),
635 bt_ctf_event_class_get_id(event_class
));
639 assert(bt_ctf_field_type_get_type_id(event_class
->fields
) ==
640 BT_CTF_FIELD_TYPE_ID_STRUCT
);
641 name_quark
= g_quark_try_string(name
);
643 BT_LOGE("Cannot get GQuark: string=\"%s\"", name
);
648 * No need to increment field_type's reference count since getting it
649 * from the structure already does.
651 field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
652 event_class
->fields
, name
);
657 struct bt_ctf_field_type
*bt_ctf_event_class_get_context_type(
658 struct bt_ctf_event_class
*event_class
)
660 struct bt_ctf_field_type
*context_type
= NULL
;
663 BT_LOGW_STR("Invalid parameter: event class is NULL.");
667 if (!event_class
->context
) {
668 BT_LOGV("Event class has no context field type: "
669 "addr=%p, name=\"%s\", id=%" PRId64
,
670 event_class
, bt_ctf_event_class_get_name(event_class
),
671 bt_ctf_event_class_get_id(event_class
));
675 bt_get(event_class
->context
);
676 context_type
= event_class
->context
;
681 int bt_ctf_event_class_set_context_type(
682 struct bt_ctf_event_class
*event_class
,
683 struct bt_ctf_field_type
*context
)
688 BT_LOGW_STR("Invalid parameter: event class is NULL.");
693 if (event_class
->frozen
) {
694 BT_LOGW("Invalid parameter: event class is frozen: "
695 "addr=%p, name=\"%s\", id=%" PRId64
,
696 event_class
, bt_ctf_event_class_get_name(event_class
),
697 bt_ctf_event_class_get_id(event_class
));
702 if (context
&& bt_ctf_field_type_get_type_id(context
) !=
703 BT_CTF_FIELD_TYPE_ID_STRUCT
) {
704 BT_LOGW("Invalid parameter: event class's context field type must be a structure: "
705 "addr=%p, name=\"%s\", id=%" PRId64
", "
707 event_class
, bt_ctf_event_class_get_name(event_class
),
708 bt_ctf_event_class_get_id(event_class
),
709 bt_ctf_field_type_id_string(
710 bt_ctf_field_type_get_type_id(context
)));
715 bt_put(event_class
->context
);
716 event_class
->context
= bt_get(context
);
717 BT_LOGV("Set event class's context field type: "
718 "event-class-addr=%p, event-class-name=\"%s\", "
719 "event-class-id=%" PRId64
", context-ft-addr=%p",
720 event_class
, bt_ctf_event_class_get_name(event_class
),
721 bt_ctf_event_class_get_id(event_class
), context
);
727 /* Pre-2.0 CTF writer backward compatibility */
728 void bt_ctf_event_class_get(struct bt_ctf_event_class
*event_class
)
733 /* Pre-2.0 CTF writer backward compatibility */
734 void bt_ctf_event_class_put(struct bt_ctf_event_class
*event_class
)
740 int bt_ctf_event_class_set_stream_id(struct bt_ctf_event_class
*event_class
,
741 uint64_t stream_id_param
)
744 struct bt_value
*obj
= NULL
;
745 int64_t stream_id
= (int64_t) stream_id_param
;
748 assert(stream_id
>= 0);
749 obj
= bt_value_integer_create_init(stream_id
);
751 BT_LOGE_STR("Cannot create integer value object.");
756 ret
= bt_ctf_attributes_set_field_value(event_class
->attributes
,
759 BT_LOGE("Cannot set event class's attributes's `stream_id` field: "
760 "addr=%p, name=\"%s\", id=%" PRId64
", ret=%d",
761 event_class
, bt_ctf_event_class_get_name(event_class
),
762 bt_ctf_event_class_get_id(event_class
), ret
);
766 if (event_class
->frozen
) {
767 BT_LOGV_STR("Freezing event class's attributes because event class is frozen.");
768 bt_ctf_attributes_freeze(event_class
->attributes
);
771 BT_LOGV("Set event class's stream class ID: "
772 "event-class-addr=%p, event-class-name=\"%s\", "
773 "event-class-id=%" PRId64
", stream-class-id=%" PRId64
,
774 event_class
, bt_ctf_event_class_get_name(event_class
),
775 bt_ctf_event_class_get_id(event_class
), stream_id
);
783 void bt_ctf_event_class_destroy(struct bt_object
*obj
)
785 struct bt_ctf_event_class
*event_class
;
787 event_class
= container_of(obj
, struct bt_ctf_event_class
, base
);
788 BT_LOGD("Destroying event class: addr=%p, name=\"%s\", id=%" PRId64
,
789 event_class
, bt_ctf_event_class_get_name(event_class
),
790 bt_ctf_event_class_get_id(event_class
));
791 BT_LOGD_STR("Destroying event class's attributes.");
792 bt_ctf_attributes_destroy(event_class
->attributes
);
793 BT_LOGD_STR("Putting context field type.");
794 bt_put(event_class
->context
);
795 BT_LOGD_STR("Putting payload field type.");
796 bt_put(event_class
->fields
);
801 void bt_ctf_event_class_freeze(struct bt_ctf_event_class
*event_class
)
805 if (event_class
->frozen
) {
809 BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64
,
810 event_class
, bt_ctf_event_class_get_name(event_class
),
811 bt_ctf_event_class_get_id(event_class
));
812 event_class
->frozen
= 1;
813 event_class
->name
= bt_ctf_event_class_get_name(event_class
);
814 event_class
->id
= bt_ctf_event_class_get_id(event_class
);
815 BT_LOGD_STR("Freezing event class's context field type.");
816 bt_ctf_field_type_freeze(event_class
->context
);
817 BT_LOGD_STR("Freezing event class's payload field type.");
818 bt_ctf_field_type_freeze(event_class
->fields
);
819 BT_LOGD_STR("Freezing event class's attributes.");
820 bt_ctf_attributes_freeze(event_class
->attributes
);
824 int bt_ctf_event_class_serialize(struct bt_ctf_event_class
*event_class
,
825 struct metadata_context
*context
)
830 struct bt_value
*attr_value
= NULL
;
834 BT_LOGD("Serializing event class's metadata: "
835 "event-class-addr=%p, event-class-name=\"%s\", "
836 "event-class-id=%" PRId64
", metadata-context-addr=%p",
837 event_class
, bt_ctf_event_class_get_name(event_class
),
838 bt_ctf_event_class_get_id(event_class
), context
);
839 context
->current_indentation_level
= 1;
840 g_string_assign(context
->field_name
, "");
841 g_string_append(context
->string
, "event {\n");
842 count
= bt_ctf_event_class_get_attribute_count(event_class
);
845 for (i
= 0; i
< count
; ++i
) {
846 const char *attr_name
= NULL
;
848 attr_name
= bt_ctf_event_class_get_attribute_name_by_index(
851 attr_value
= bt_ctf_event_class_get_attribute_value_by_index(
855 switch (bt_value_get_type(attr_value
)) {
856 case BT_VALUE_TYPE_INTEGER
:
860 ret
= bt_value_integer_get(attr_value
, &value
);
862 g_string_append_printf(context
->string
,
863 "\t%s = %" PRId64
";\n", attr_name
, value
);
867 case BT_VALUE_TYPE_STRING
:
871 ret
= bt_value_string_get(attr_value
, &value
);
873 g_string_append_printf(context
->string
,
874 "\t%s = \"%s\";\n", attr_name
, value
);
879 /* should never happen */
887 if (event_class
->context
) {
888 g_string_append(context
->string
, "\tcontext := ");
889 BT_LOGD_STR("Serializing event class's context field type metadata.");
890 ret
= bt_ctf_field_type_serialize(event_class
->context
,
893 BT_LOGW("Cannot serialize event class's context field type's metadata: "
897 g_string_append(context
->string
, ";\n");
900 if (event_class
->fields
) {
901 g_string_append(context
->string
, "\tfields := ");
902 BT_LOGD_STR("Serializing event class's payload field type metadata.");
903 ret
= bt_ctf_field_type_serialize(event_class
->fields
, context
);
905 BT_LOGW("Cannot serialize event class's payload field type's metadata: "
909 g_string_append(context
->string
, ";\n");
912 g_string_append(context
->string
, "};\n\n");
914 context
->current_indentation_level
= 0;