2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
15 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-DEF-CC"
18 #include <babeltrace2/babeltrace.h>
19 #include "common/babeltrace.h"
20 #include "common/assert.h"
26 #include "ctf-meta-visitors.h"
29 int find_mapped_clock_class(struct ctf_field_class
*fc
,
30 struct ctf_clock_class
**clock_class
)
40 case CTF_FIELD_CLASS_TYPE_INT
:
41 case CTF_FIELD_CLASS_TYPE_ENUM
:
43 struct ctf_field_class_int
*int_fc
= (void *) fc
;
45 if (int_fc
->mapped_clock_class
) {
46 if (*clock_class
&& *clock_class
!=
47 int_fc
->mapped_clock_class
) {
48 BT_LOGE("Stream class contains more than one "
49 "clock class: expected-cc-name=\"%s\", "
50 "other-cc-name=\"%s\"",
51 (*clock_class
)->name
->str
,
52 int_fc
->mapped_clock_class
->name
->str
);
57 *clock_class
= int_fc
->mapped_clock_class
;
62 case CTF_FIELD_CLASS_TYPE_STRUCT
:
64 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
66 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
67 struct ctf_named_field_class
*named_fc
=
68 ctf_field_class_struct_borrow_member_by_index(
71 ret
= find_mapped_clock_class(named_fc
->fc
,
80 case CTF_FIELD_CLASS_TYPE_VARIANT
:
82 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
84 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
85 struct ctf_named_field_class
*named_fc
=
86 ctf_field_class_variant_borrow_option_by_index(
89 ret
= find_mapped_clock_class(named_fc
->fc
,
98 case CTF_FIELD_CLASS_TYPE_ARRAY
:
99 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
101 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
103 ret
= find_mapped_clock_class(array_fc
->elem_fc
, clock_class
);
119 int update_stream_class_default_clock_class(
120 struct ctf_stream_class
*stream_class
)
123 struct ctf_clock_class
*clock_class
=
124 stream_class
->default_clock_class
;
127 ret
= find_mapped_clock_class(stream_class
->packet_context_fc
,
133 ret
= find_mapped_clock_class(stream_class
->event_header_fc
,
139 ret
= find_mapped_clock_class(stream_class
->event_common_context_fc
,
145 for (i
= 0; i
< stream_class
->event_classes
->len
; i
++) {
146 struct ctf_event_class
*event_class
=
147 stream_class
->event_classes
->pdata
[i
];
149 ret
= find_mapped_clock_class(event_class
->spec_context_fc
,
155 ret
= find_mapped_clock_class(event_class
->payload_fc
,
162 if (!stream_class
->default_clock_class
) {
163 stream_class
->default_clock_class
= clock_class
;
171 int ctf_trace_class_update_default_clock_classes(struct ctf_trace_class
*ctf_tc
)
175 struct ctf_clock_class
*clock_class
= NULL
;
177 ret
= find_mapped_clock_class(ctf_tc
->packet_header_fc
, &clock_class
);
187 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
188 struct ctf_stream_class
*sc
=
189 ctf_tc
->stream_classes
->pdata
[i
];
191 ret
= update_stream_class_default_clock_class(
192 ctf_tc
->stream_classes
->pdata
[i
]);
194 BT_LOGE("Stream class contains more than one "
195 "clock class: stream-class-id=%" PRIu64
,