lib: allow a single mapped clock class within a stream class
[babeltrace.git] / lib / ctf-ir / stream-class.c
1 /*
2 * stream-class.c
3 *
4 * Babeltrace CTF IR - Stream Class
5 *
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
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:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
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
26 * SOFTWARE.
27 */
28
29 #define BT_LOG_TAG "STREAM-CLASS"
30 #include <babeltrace/lib-logging-internal.h>
31
32 #include <babeltrace/ctf-writer/clock.h>
33 #include <babeltrace/ctf-writer/clock-internal.h>
34 #include <babeltrace/ctf-ir/clock-class-internal.h>
35 #include <babeltrace/ctf-writer/event.h>
36 #include <babeltrace/ctf-ir/event-class-internal.h>
37 #include <babeltrace/ctf-ir/event-internal.h>
38 #include <babeltrace/ctf-ir/field-types-internal.h>
39 #include <babeltrace/ctf-ir/fields-internal.h>
40 #include <babeltrace/ctf-writer/stream.h>
41 #include <babeltrace/ctf-ir/stream-class-internal.h>
42 #include <babeltrace/ctf-ir/validation-internal.h>
43 #include <babeltrace/ctf-ir/visitor-internal.h>
44 #include <babeltrace/ctf-writer/functor-internal.h>
45 #include <babeltrace/ctf-ir/utils.h>
46 #include <babeltrace/ctf-ir/utils-internal.h>
47 #include <babeltrace/ref.h>
48 #include <babeltrace/compiler-internal.h>
49 #include <babeltrace/align-internal.h>
50 #include <babeltrace/endian-internal.h>
51 #include <inttypes.h>
52 #include <stdint.h>
53 #include <stdbool.h>
54
55 static
56 void bt_stream_class_destroy(struct bt_object *obj);
57 static
58 int init_event_header(struct bt_stream_class *stream_class);
59 static
60 int init_packet_context(struct bt_stream_class *stream_class);
61
62 struct bt_stream_class *bt_stream_class_create(const char *name)
63 {
64 struct bt_stream_class *stream_class;
65 int ret;
66
67 BT_LOGD("Creating default stream class object: name=\"%s\"", name);
68 stream_class = bt_stream_class_create_empty(name);
69 if (!stream_class) {
70 BT_LOGD_STR("Cannot create empty stream class.");
71 goto error;
72 }
73
74 ret = init_event_header(stream_class);
75 if (ret) {
76 BT_LOGE_STR("Cannot initialize stream class's event header field type.");
77 goto error;
78 }
79
80 ret = init_packet_context(stream_class);
81 if (ret) {
82 BT_LOGE_STR("Cannot initialize stream class's packet context field type.");
83 goto error;
84 }
85
86 BT_LOGD("Created default stream class object: addr=%p, name=\"%s\"",
87 stream_class, name);
88 return stream_class;
89
90 error:
91 BT_PUT(stream_class);
92 return stream_class;
93 }
94
95 struct bt_stream_class *bt_stream_class_create_empty(const char *name)
96 {
97 struct bt_stream_class *stream_class = NULL;
98
99 BT_LOGD("Creating empty stream class object: name=\"%s\"", name);
100
101 stream_class = g_new0(struct bt_stream_class, 1);
102 if (!stream_class) {
103 BT_LOGE_STR("Failed to allocate one stream class.");
104 goto error;
105 }
106
107 stream_class->name = g_string_new(name);
108 stream_class->event_classes = g_ptr_array_new_with_free_func(
109 (GDestroyNotify) bt_object_release);
110 if (!stream_class->event_classes) {
111 BT_LOGE_STR("Failed to allocate a GPtrArray.");
112 goto error;
113 }
114
115 stream_class->event_classes_ht = g_hash_table_new_full(g_int64_hash,
116 g_int64_equal, g_free, NULL);
117 if (!stream_class->event_classes_ht) {
118 BT_LOGE_STR("Failed to allocate a GHashTable.");
119 goto error;
120 }
121
122 bt_object_init(stream_class, bt_stream_class_destroy);
123 BT_LOGD("Created empty stream class object: addr=%p, name=\"%s\"",
124 stream_class, name);
125 return stream_class;
126
127 error:
128 BT_PUT(stream_class);
129 return stream_class;
130 }
131
132 struct bt_trace *bt_stream_class_get_trace(
133 struct bt_stream_class *stream_class)
134 {
135 return stream_class ?
136 bt_get(bt_stream_class_borrow_trace(stream_class)) :
137 NULL;
138 }
139
140 const char *bt_stream_class_get_name(
141 struct bt_stream_class *stream_class)
142 {
143 const char *name = NULL;
144
145 if (!stream_class) {
146 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
147 goto end;
148 }
149
150 name = stream_class->name->len > 0 ? stream_class->name->str : NULL;
151 end:
152 return name;
153 }
154
155 int bt_stream_class_set_name(struct bt_stream_class *stream_class,
156 const char *name)
157 {
158 int ret = 0;
159
160 if (!stream_class) {
161 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
162 ret = -1;
163 goto end;
164 }
165
166 if (stream_class->frozen) {
167 BT_LOGW("Invalid parameter: stream class is frozen: "
168 "addr=%p, name=\"%s\", id=%" PRId64,
169 stream_class, bt_stream_class_get_name(stream_class),
170 bt_stream_class_get_id(stream_class));
171 ret = -1;
172 goto end;
173 }
174
175 if (!name) {
176 g_string_assign(stream_class->name, "");
177 } else {
178 if (strlen(name) == 0) {
179 BT_LOGW("Invalid parameter: name is empty.");
180 ret = -1;
181 goto end;
182 }
183
184 g_string_assign(stream_class->name, name);
185 }
186
187 BT_LOGV("Set stream class's name: "
188 "addr=%p, name=\"%s\", id=%" PRId64,
189 stream_class, bt_stream_class_get_name(stream_class),
190 bt_stream_class_get_id(stream_class));
191 end:
192 return ret;
193 }
194
195 struct bt_ctf_clock *bt_stream_class_get_clock(
196 struct bt_stream_class *stream_class)
197 {
198 struct bt_ctf_clock *clock = NULL;
199
200 if (!stream_class) {
201 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
202 goto end;
203 }
204
205 if (!stream_class->clock) {
206 BT_LOGV("Stream class has no clock: "
207 "addr=%p, name=\"%s\", id=%" PRId64,
208 stream_class, bt_stream_class_get_name(stream_class),
209 bt_stream_class_get_id(stream_class));
210 goto end;
211 }
212
213 clock = bt_get(stream_class->clock);
214 end:
215 return clock;
216 }
217
218 int bt_stream_class_set_clock(struct bt_stream_class *stream_class,
219 struct bt_ctf_clock *clock)
220 {
221 int ret = 0;
222 struct bt_field_type *timestamp_field = NULL;
223
224 if (!stream_class || !clock) {
225 BT_LOGW("Invalid parameter: stream class or clock is NULL: "
226 "stream-class-addr=%p, clock-addr=%p",
227 stream_class, clock);
228 ret = -1;
229 goto end;
230 }
231
232 if (stream_class->frozen) {
233 BT_LOGW("Invalid parameter: stream class is frozen: "
234 "addr=%p, name=\"%s\", id=%" PRId64,
235 stream_class, bt_stream_class_get_name(stream_class),
236 bt_stream_class_get_id(stream_class));
237 ret = -1;
238 goto end;
239 }
240
241 /* Replace the current clock of this stream class. */
242 bt_put(stream_class->clock);
243 stream_class->clock = bt_get(clock);
244 BT_LOGV("Set stream class's clock: "
245 "addr=%p, name=\"%s\", id=%" PRId64 ", "
246 "clock-addr=%p, clock-name=\"%s\"",
247 stream_class, bt_stream_class_get_name(stream_class),
248 bt_stream_class_get_id(stream_class),
249 stream_class->clock,
250 bt_ctf_clock_get_name(stream_class->clock));
251
252 end:
253 bt_put(timestamp_field);
254 return ret;
255 }
256
257 int64_t bt_stream_class_get_id(struct bt_stream_class *stream_class)
258 {
259 int64_t ret;
260
261 if (!stream_class) {
262 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
263 ret = (int64_t) -1;
264 goto end;
265 }
266
267 if (!stream_class->id_set) {
268 BT_LOGV("Stream class's ID is not set: addr=%p, name=\"%s\"",
269 stream_class,
270 bt_stream_class_get_name(stream_class));
271 ret = (int64_t) -1;
272 goto end;
273 }
274
275 ret = stream_class->id;
276 end:
277 return ret;
278 }
279
280 BT_HIDDEN
281 void _bt_stream_class_set_id(
282 struct bt_stream_class *stream_class, int64_t id)
283 {
284 assert(stream_class);
285 stream_class->id = id;
286 stream_class->id_set = 1;
287 BT_LOGV("Set stream class's ID (internal): "
288 "addr=%p, name=\"%s\", id=%" PRId64,
289 stream_class, bt_stream_class_get_name(stream_class),
290 bt_stream_class_get_id(stream_class));
291 }
292
293 struct event_class_set_stream_class_id_data {
294 int64_t stream_class_id;
295 int ret;
296 };
297
298 BT_HIDDEN
299 int bt_stream_class_set_id_no_check(
300 struct bt_stream_class *stream_class, int64_t id)
301 {
302 _bt_stream_class_set_id(stream_class, id);
303 return 0;
304 }
305
306 int bt_stream_class_set_id(struct bt_stream_class *stream_class,
307 uint64_t id_param)
308 {
309 int ret = 0;
310 int64_t id = (int64_t) id_param;
311
312 if (!stream_class) {
313 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
314 ret = -1;
315 goto end;
316 }
317
318 if (stream_class->frozen) {
319 BT_LOGW("Invalid parameter: stream class is frozen: "
320 "addr=%p, name=\"%s\", id=%" PRId64,
321 stream_class, bt_stream_class_get_name(stream_class),
322 bt_stream_class_get_id(stream_class));
323 ret = -1;
324 goto end;
325 }
326
327 if (id < 0) {
328 BT_LOGW("Invalid parameter: invalid stream class's ID: "
329 "stream-class-addr=%p, stream-class-name=\"%s\", "
330 "stream-class-id=%" PRId64 ", id=%" PRIu64,
331 stream_class, bt_stream_class_get_name(stream_class),
332 bt_stream_class_get_id(stream_class),
333 id_param);
334 ret = -1;
335 goto end;
336 }
337
338 ret = bt_stream_class_set_id_no_check(stream_class, id);
339 if (ret == 0) {
340 BT_LOGV("Set stream class's ID: "
341 "addr=%p, name=\"%s\", id=%" PRId64,
342 stream_class, bt_stream_class_get_name(stream_class),
343 bt_stream_class_get_id(stream_class));
344 }
345 end:
346 return ret;
347 }
348
349 static
350 void event_class_exists(gpointer element, gpointer query)
351 {
352 struct bt_event_class *event_class_a = element;
353 struct search_query *search_query = query;
354 struct bt_event_class *event_class_b = search_query->value;
355 int64_t id_a, id_b;
356
357 if (search_query->value == element) {
358 search_query->found = 1;
359 goto end;
360 }
361
362 /*
363 * Two event classes cannot share the same ID in a given
364 * stream class.
365 */
366 id_a = bt_event_class_get_id(event_class_a);
367 id_b = bt_event_class_get_id(event_class_b);
368
369 if (id_a < 0 || id_b < 0) {
370 /* at least one ID is not set: will be automatically set later */
371 goto end;
372 }
373
374 if (id_a == id_b) {
375 BT_LOGW("Event class with this ID already exists in the stream class: "
376 "id=%" PRId64 ", name=\"%s\"",
377 id_a, bt_event_class_get_name(event_class_a));
378 search_query->found = 1;
379 goto end;
380 }
381
382 end:
383 return;
384 }
385
386 int bt_stream_class_add_event_class(
387 struct bt_stream_class *stream_class,
388 struct bt_event_class *event_class)
389 {
390 int ret = 0;
391 int64_t *event_id = NULL;
392 struct bt_trace *trace = NULL;
393 struct bt_stream_class *old_stream_class = NULL;
394 struct bt_validation_output validation_output = { 0 };
395 struct bt_field_type *packet_header_type = NULL;
396 struct bt_field_type *packet_context_type = NULL;
397 struct bt_field_type *event_header_type = NULL;
398 struct bt_field_type *stream_event_ctx_type = NULL;
399 struct bt_field_type *event_context_type = NULL;
400 struct bt_field_type *event_payload_type = NULL;
401 const enum bt_validation_flag validation_flags =
402 BT_VALIDATION_FLAG_EVENT;
403 struct bt_clock_class *expected_clock_class = NULL;
404
405 if (!stream_class || !event_class) {
406 BT_LOGW("Invalid parameter: stream class or event class is NULL: "
407 "stream-class-addr=%p, event-class-addr=%p",
408 stream_class, event_class);
409 ret = -1;
410 goto end;
411 }
412
413 BT_LOGD("Adding event class to stream class: "
414 "stream-class-addr=%p, stream-class-name=\"%s\", "
415 "stream-class-id=%" PRId64 ", event-class-addr=%p, "
416 "event-class-name=\"%s\", event-class-id=%" PRId64,
417 stream_class, bt_stream_class_get_name(stream_class),
418 bt_stream_class_get_id(stream_class),
419 event_class,
420 bt_event_class_get_name(event_class),
421 bt_event_class_get_id(event_class));
422
423 trace = bt_stream_class_get_trace(stream_class);
424 if (trace && trace->is_static) {
425 BT_LOGW("Invalid parameter: stream class's trace is static: "
426 "trace-addr=%p, trace-name=\"%s\"",
427 trace, bt_trace_get_name(trace));
428 ret = -1;
429 goto end;
430 }
431
432 if (stream_class->frozen) {
433 /*
434 * We only check that the event class to be added has a
435 * single class which matches the stream class's
436 * expected clock class if the stream class is frozen.
437 * If it's not, then this event class is added "as is"
438 * and the validation will be performed when calling
439 * either bt_trace_add_stream_class() or
440 * bt_event_create(). This is because the stream class's
441 * field types (packet context, event header, event
442 * context) could change before the next call to one of
443 * those two functions.
444 */
445 expected_clock_class = bt_get(stream_class->clock_class);
446
447 /*
448 * At this point, `expected_clock_class` can be NULL,
449 * and bt_event_class_validate_single_clock_class()
450 * below can set it.
451 */
452 ret = bt_event_class_validate_single_clock_class(
453 event_class, &expected_clock_class);
454 if (ret) {
455 BT_LOGW("Event class contains a field type which is not "
456 "recursively mapped to its stream class's "
457 "expected clock class: "
458 "stream-class-addr=%p, "
459 "stream-class-id=%" PRId64 ", "
460 "stream-class-name=\"%s\", "
461 "expected-clock-class-addr=%p, "
462 "expected-clock-class-name=\"%s\"",
463 stream_class,
464 bt_stream_class_get_id(stream_class),
465 bt_stream_class_get_name(stream_class),
466 expected_clock_class,
467 expected_clock_class ?
468 bt_clock_class_get_name(expected_clock_class) :
469 NULL);
470 goto end;
471 }
472 }
473
474 event_id = g_new(int64_t, 1);
475 if (!event_id) {
476 BT_LOGE_STR("Failed to allocate one int64_t.");
477 ret = -1;
478 goto end;
479 }
480
481 /* Check for duplicate event classes */
482 struct search_query query = { .value = event_class, .found = 0 };
483 g_ptr_array_foreach(stream_class->event_classes, event_class_exists,
484 &query);
485 if (query.found) {
486 BT_LOGW_STR("Another event class part of this stream class has the same ID.");
487 ret = -1;
488 goto end;
489 }
490
491 old_stream_class = bt_event_class_get_stream_class(event_class);
492 if (old_stream_class) {
493 /* Event class is already associated to a stream class. */
494 BT_LOGW("Event class is already part of another stream class: "
495 "event-class-stream-class-addr=%p, "
496 "event-class-stream-class-name=\"%s\", "
497 "event-class-stream-class-id=%" PRId64,
498 old_stream_class,
499 bt_stream_class_get_name(old_stream_class),
500 bt_stream_class_get_id(old_stream_class));
501 ret = -1;
502 goto end;
503 }
504
505 if (trace) {
506 /*
507 * If the stream class is associated with a trace, then
508 * both those objects are frozen. Also, this event class
509 * is about to be frozen.
510 *
511 * Therefore the event class must be validated here.
512 * The trace and stream class should be valid at this
513 * point.
514 */
515 assert(trace->valid);
516 assert(stream_class->valid);
517 packet_header_type =
518 bt_trace_get_packet_header_type(trace);
519 packet_context_type =
520 bt_stream_class_get_packet_context_type(
521 stream_class);
522 event_header_type =
523 bt_stream_class_get_event_header_type(stream_class);
524 stream_event_ctx_type =
525 bt_stream_class_get_event_context_type(
526 stream_class);
527 event_context_type =
528 bt_event_class_get_context_type(event_class);
529 event_payload_type =
530 bt_event_class_get_payload_type(event_class);
531 ret = bt_validate_class_types(
532 trace->environment, packet_header_type,
533 packet_context_type, event_header_type,
534 stream_event_ctx_type, event_context_type,
535 event_payload_type, trace->valid,
536 stream_class->valid, event_class->valid,
537 &validation_output, validation_flags);
538 BT_PUT(packet_header_type);
539 BT_PUT(packet_context_type);
540 BT_PUT(event_header_type);
541 BT_PUT(stream_event_ctx_type);
542 BT_PUT(event_context_type);
543 BT_PUT(event_payload_type);
544
545 if (ret) {
546 /*
547 * This means something went wrong during the
548 * validation process, not that the objects are
549 * invalid.
550 */
551 BT_LOGE("Failed to validate event class: ret=%d", ret);
552 goto end;
553 }
554
555 if ((validation_output.valid_flags & validation_flags) !=
556 validation_flags) {
557 /* Invalid event class */
558 BT_LOGW("Invalid trace, stream class, or event class: "
559 "valid-flags=0x%x",
560 validation_output.valid_flags);
561 ret = -1;
562 goto end;
563 }
564 }
565
566 /* Only set an event ID if none was explicitly set before */
567 *event_id = bt_event_class_get_id(event_class);
568 if (*event_id < 0) {
569 BT_LOGV("Event class has no ID: automatically setting it: "
570 "id=%" PRId64, stream_class->next_event_id);
571
572 if (bt_event_class_set_id(event_class,
573 stream_class->next_event_id)) {
574 BT_LOGE("Cannot set event class's ID: id=%" PRId64,
575 stream_class->next_event_id);
576 ret = -1;
577 goto end;
578 }
579 stream_class->next_event_id++;
580 *event_id = stream_class->next_event_id;
581 }
582
583 bt_object_set_parent(event_class, stream_class);
584
585 if (trace) {
586 /*
587 * At this point we know that the function will be
588 * successful. Therefore we can replace the event
589 * class's field types with what's in the validation
590 * output structure and mark this event class as valid.
591 */
592 bt_validation_replace_types(NULL, NULL, event_class,
593 &validation_output, validation_flags);
594 event_class->valid = 1;
595
596 /*
597 * Put what was not moved in
598 * bt_validation_replace_types().
599 */
600 bt_validation_output_put_types(&validation_output);
601 }
602
603 /* Add to the event classes of the stream class */
604 g_ptr_array_add(stream_class->event_classes, event_class);
605 g_hash_table_insert(stream_class->event_classes_ht, event_id,
606 event_class);
607 event_id = NULL;
608
609 /* Freeze the event class */
610 bt_event_class_freeze(event_class);
611
612 /*
613 * It is safe to set the stream class's unique clock class
614 * now if the stream class is frozen.
615 */
616 if (stream_class->frozen && expected_clock_class) {
617 assert(!stream_class->clock_class ||
618 stream_class->clock_class == expected_clock_class);
619 BT_MOVE(stream_class->clock_class, expected_clock_class);
620 }
621
622 /* Notifiy listeners of the trace's schema modification. */
623 if (trace) {
624 struct bt_visitor_object obj = { .object = event_class,
625 .type = BT_VISITOR_OBJECT_TYPE_EVENT_CLASS };
626
627 (void) bt_trace_object_modification(&obj, trace);
628 }
629
630 BT_LOGD("Added event class to stream class: "
631 "stream-class-addr=%p, stream-class-name=\"%s\", "
632 "stream-class-id=%" PRId64 ", event-class-addr=%p, "
633 "event-class-name=\"%s\", event-class-id=%" PRId64,
634 stream_class, bt_stream_class_get_name(stream_class),
635 bt_stream_class_get_id(stream_class),
636 event_class,
637 bt_event_class_get_name(event_class),
638 bt_event_class_get_id(event_class));
639
640 end:
641 BT_PUT(trace);
642 BT_PUT(old_stream_class);
643 bt_validation_output_put_types(&validation_output);
644 bt_put(expected_clock_class);
645 assert(!packet_header_type);
646 assert(!packet_context_type);
647 assert(!event_header_type);
648 assert(!stream_event_ctx_type);
649 assert(!event_context_type);
650 assert(!event_payload_type);
651 g_free(event_id);
652
653 return ret;
654 }
655
656 int64_t bt_stream_class_get_event_class_count(
657 struct bt_stream_class *stream_class)
658 {
659 int64_t ret;
660
661 if (!stream_class) {
662 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
663 ret = (int64_t) -1;
664 goto end;
665 }
666
667 ret = (int64_t) stream_class->event_classes->len;
668 end:
669 return ret;
670 }
671
672 struct bt_event_class *bt_stream_class_get_event_class_by_index(
673 struct bt_stream_class *stream_class, uint64_t index)
674 {
675 struct bt_event_class *event_class = NULL;
676
677 if (!stream_class) {
678 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
679 goto end;
680 }
681
682 if (index >= stream_class->event_classes->len) {
683 BT_LOGW("Invalid parameter: index is out of bounds: "
684 "addr=%p, name=\"%s\", id=%" PRId64 ", "
685 "index=%" PRIu64 ", count=%u",
686 stream_class, bt_stream_class_get_name(stream_class),
687 bt_stream_class_get_id(stream_class),
688 index, stream_class->event_classes->len);
689 goto end;
690 }
691
692 event_class = g_ptr_array_index(stream_class->event_classes, index);
693 bt_get(event_class);
694 end:
695 return event_class;
696 }
697
698 struct bt_event_class *bt_stream_class_get_event_class_by_id(
699 struct bt_stream_class *stream_class, uint64_t id)
700 {
701 int64_t id_key = (int64_t) id;
702 struct bt_event_class *event_class = NULL;
703
704 if (!stream_class) {
705 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
706 goto end;
707 }
708
709 if (id_key < 0) {
710 BT_LOGW("Invalid parameter: invalid event class's ID: "
711 "stream-class-addr=%p, stream-class-name=\"%s\", "
712 "stream-class-id=%" PRId64 ", event-class-id=%" PRIu64,
713 stream_class,
714 bt_stream_class_get_name(stream_class),
715 bt_stream_class_get_id(stream_class), id);
716 goto end;
717 }
718
719 event_class = g_hash_table_lookup(stream_class->event_classes_ht,
720 &id_key);
721 bt_get(event_class);
722 end:
723 return event_class;
724 }
725
726 struct bt_field_type *bt_stream_class_get_packet_context_type(
727 struct bt_stream_class *stream_class)
728 {
729 struct bt_field_type *ret = NULL;
730
731 if (!stream_class) {
732 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
733 goto end;
734 }
735
736 bt_get(stream_class->packet_context_type);
737 ret = stream_class->packet_context_type;
738 end:
739 return ret;
740 }
741
742 int bt_stream_class_set_packet_context_type(
743 struct bt_stream_class *stream_class,
744 struct bt_field_type *packet_context_type)
745 {
746 int ret = 0;
747
748 if (!stream_class) {
749 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
750 ret = -1;
751 goto end;
752 }
753
754 if (stream_class->frozen) {
755 BT_LOGW("Invalid parameter: stream class is frozen: "
756 "addr=%p, name=\"%s\", id=%" PRId64,
757 stream_class, bt_stream_class_get_name(stream_class),
758 bt_stream_class_get_id(stream_class));
759 ret = -1;
760 goto end;
761 }
762
763 if (packet_context_type &&
764 bt_field_type_get_type_id(packet_context_type) !=
765 BT_FIELD_TYPE_ID_STRUCT) {
766 /* A packet context must be a structure. */
767 BT_LOGW("Invalid parameter: stream class's packet context field type must be a structure: "
768 "addr=%p, name=\"%s\", id=%" PRId64 ", "
769 "packet-context-ft-addr=%p, packet-context-ft-id=%s",
770 stream_class, bt_stream_class_get_name(stream_class),
771 bt_stream_class_get_id(stream_class),
772 packet_context_type,
773 bt_field_type_id_string(
774 bt_field_type_get_type_id(packet_context_type)));
775 ret = -1;
776 goto end;
777 }
778
779 bt_put(stream_class->packet_context_type);
780 bt_get(packet_context_type);
781 stream_class->packet_context_type = packet_context_type;
782 BT_LOGV("Set stream class's packet context field type: "
783 "addr=%p, name=\"%s\", id=%" PRId64 ", "
784 "packet-context-ft-addr=%p",
785 stream_class, bt_stream_class_get_name(stream_class),
786 bt_stream_class_get_id(stream_class),
787 packet_context_type);
788
789 end:
790 return ret;
791 }
792
793 struct bt_field_type *bt_stream_class_get_event_header_type(
794 struct bt_stream_class *stream_class)
795 {
796 struct bt_field_type *ret = NULL;
797
798 if (!stream_class) {
799 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
800 goto end;
801 }
802
803 if (!stream_class->event_header_type) {
804 BT_LOGV("Stream class has no event header field type: "
805 "addr=%p, name=\"%s\", id=%" PRId64,
806 stream_class, bt_stream_class_get_name(stream_class),
807 bt_stream_class_get_id(stream_class));
808 goto end;
809 }
810
811 bt_get(stream_class->event_header_type);
812 ret = stream_class->event_header_type;
813 end:
814 return ret;
815 }
816
817 int bt_stream_class_set_event_header_type(
818 struct bt_stream_class *stream_class,
819 struct bt_field_type *event_header_type)
820 {
821 int ret = 0;
822
823 if (!stream_class) {
824 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
825 ret = -1;
826 goto end;
827 }
828
829 if (stream_class->frozen) {
830 BT_LOGW("Invalid parameter: stream class is frozen: "
831 "addr=%p, name=\"%s\", id=%" PRId64,
832 stream_class, bt_stream_class_get_name(stream_class),
833 bt_stream_class_get_id(stream_class));
834 ret = -1;
835 goto end;
836 }
837
838 if (event_header_type &&
839 bt_field_type_get_type_id(event_header_type) !=
840 BT_FIELD_TYPE_ID_STRUCT) {
841 /* An event header must be a structure. */
842 BT_LOGW("Invalid parameter: stream class's event header field type must be a structure: "
843 "addr=%p, name=\"%s\", id=%" PRId64 ", "
844 "event-header-ft-addr=%p, event-header-ft-id=%s",
845 stream_class, bt_stream_class_get_name(stream_class),
846 bt_stream_class_get_id(stream_class),
847 event_header_type,
848 bt_field_type_id_string(
849 bt_field_type_get_type_id(event_header_type)));
850 ret = -1;
851 goto end;
852 }
853
854 bt_put(stream_class->event_header_type);
855 stream_class->event_header_type = bt_get(event_header_type);
856 BT_LOGV("Set stream class's event header field type: "
857 "addr=%p, name=\"%s\", id=%" PRId64 ", "
858 "event-header-ft-addr=%p",
859 stream_class, bt_stream_class_get_name(stream_class),
860 bt_stream_class_get_id(stream_class),
861 event_header_type);
862 end:
863 return ret;
864 }
865
866 struct bt_field_type *bt_stream_class_get_event_context_type(
867 struct bt_stream_class *stream_class)
868 {
869 struct bt_field_type *ret = NULL;
870
871 if (!stream_class) {
872 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
873 goto end;
874 }
875
876 if (!stream_class->event_context_type) {
877 goto end;
878 }
879
880 bt_get(stream_class->event_context_type);
881 ret = stream_class->event_context_type;
882 end:
883 return ret;
884 }
885
886 int bt_stream_class_set_event_context_type(
887 struct bt_stream_class *stream_class,
888 struct bt_field_type *event_context_type)
889 {
890 int ret = 0;
891
892 if (!stream_class) {
893 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
894 ret = -1;
895 goto end;
896 }
897
898 if (stream_class->frozen) {
899 BT_LOGW("Invalid parameter: stream class is frozen: "
900 "addr=%p, name=\"%s\", id=%" PRId64,
901 stream_class, bt_stream_class_get_name(stream_class),
902 bt_stream_class_get_id(stream_class));
903 ret = -1;
904 goto end;
905 }
906
907 if (event_context_type &&
908 bt_field_type_get_type_id(event_context_type) !=
909 BT_FIELD_TYPE_ID_STRUCT) {
910 /* A packet context must be a structure. */
911 BT_LOGW("Invalid parameter: stream class's event context field type must be a structure: "
912 "addr=%p, name=\"%s\", id=%" PRId64 ", "
913 "event-context-ft-addr=%p, event-context-ft-id=%s",
914 stream_class, bt_stream_class_get_name(stream_class),
915 bt_stream_class_get_id(stream_class),
916 event_context_type,
917 bt_field_type_id_string(
918 bt_field_type_get_type_id(event_context_type)));
919 ret = -1;
920 goto end;
921 }
922
923 bt_put(stream_class->event_context_type);
924 stream_class->event_context_type = bt_get(event_context_type);
925 BT_LOGV("Set stream class's event context field type: "
926 "addr=%p, name=\"%s\", id=%" PRId64 ", "
927 "event-context-ft-addr=%p",
928 stream_class, bt_stream_class_get_name(stream_class),
929 bt_stream_class_get_id(stream_class),
930 event_context_type);
931 end:
932 return ret;
933 }
934
935 /* Pre-2.0 CTF writer backward compatibility */
936 void bt_ctf_stream_class_get(struct bt_stream_class *stream_class)
937 {
938 bt_get(stream_class);
939 }
940
941 /* Pre-2.0 CTF writer backward compatibility */
942 void bt_ctf_stream_class_put(struct bt_stream_class *stream_class)
943 {
944 bt_put(stream_class);
945 }
946
947 static
948 int64_t get_event_class_count(void *element)
949 {
950 return bt_stream_class_get_event_class_count(
951 (struct bt_stream_class *) element);
952 }
953
954 static
955 void *get_event_class(void *element, int i)
956 {
957 return bt_stream_class_get_event_class_by_index(
958 (struct bt_stream_class *) element, i);
959 }
960
961 static
962 int visit_event_class(void *object, bt_visitor visitor,void *data)
963 {
964 struct bt_visitor_object obj =
965 { .object = object,
966 .type = BT_VISITOR_OBJECT_TYPE_EVENT_CLASS };
967
968 return visitor(&obj, data);
969 }
970
971 int bt_stream_class_visit(struct bt_stream_class *stream_class,
972 bt_visitor visitor, void *data)
973 {
974 int ret;
975 struct bt_visitor_object obj =
976 { .object = stream_class,
977 .type = BT_VISITOR_OBJECT_TYPE_STREAM_CLASS };
978
979 if (!stream_class || !visitor) {
980 BT_LOGW("Invalid parameter: stream class or visitor is NULL: "
981 "stream-class-addr=%p, visitor=%p",
982 stream_class, visitor);
983 ret = -1;
984 goto end;
985 }
986
987 ret = visitor_helper(&obj, get_event_class_count,
988 get_event_class,
989 visit_event_class, visitor, data);
990 BT_LOGV("visitor_helper() returned: ret=%d", ret);
991 end:
992 return ret;
993 }
994
995 BT_HIDDEN
996 void bt_stream_class_freeze(struct bt_stream_class *stream_class)
997 {
998 if (!stream_class || stream_class->frozen) {
999 return;
1000 }
1001
1002 BT_LOGD("Freezing stream class: addr=%p, name=\"%s\", id=%" PRId64,
1003 stream_class, bt_stream_class_get_name(stream_class),
1004 bt_stream_class_get_id(stream_class));
1005 stream_class->frozen = 1;
1006 bt_field_type_freeze(stream_class->event_header_type);
1007 bt_field_type_freeze(stream_class->packet_context_type);
1008 bt_field_type_freeze(stream_class->event_context_type);
1009
1010 if (stream_class->clock) {
1011 bt_clock_class_freeze(stream_class->clock->clock_class);
1012 }
1013 }
1014
1015 BT_HIDDEN
1016 int bt_stream_class_serialize(struct bt_stream_class *stream_class,
1017 struct metadata_context *context)
1018 {
1019 int ret = 0;
1020 size_t i;
1021 struct bt_trace *trace;
1022 struct bt_field_type *packet_header_type = NULL;
1023
1024 BT_LOGD("Serializing stream class's metadata: "
1025 "stream-class-addr=%p, stream-class-name=\"%s\", "
1026 "stream-class-id=%" PRId64 ", metadata-context-addr=%p",
1027 stream_class, bt_stream_class_get_name(stream_class),
1028 bt_stream_class_get_id(stream_class), context);
1029 g_string_assign(context->field_name, "");
1030 context->current_indentation_level = 1;
1031 if (!stream_class->id_set) {
1032 BT_LOGW_STR("Stream class's ID is not set.");
1033 ret = -1;
1034 goto end;
1035 }
1036
1037 g_string_append(context->string, "stream {\n");
1038
1039 /*
1040 * The reference to the trace is only borrowed since the
1041 * serialization of the stream class might have been triggered
1042 * by the trace's destruction. In such a case, the trace's
1043 * reference count would, unexepectedly, go through the sequence
1044 * 1 -> 0 -> 1 -> 0 -> ..., provoking an endless loop of destruction
1045 * and serialization.
1046 */
1047 trace = bt_stream_class_borrow_trace(stream_class);
1048 assert(trace);
1049 packet_header_type = bt_trace_get_packet_header_type(trace);
1050 trace = NULL;
1051 if (packet_header_type) {
1052 struct bt_field_type *stream_id_type;
1053
1054 stream_id_type =
1055 bt_field_type_structure_get_field_type_by_name(
1056 packet_header_type, "stream_id");
1057 if (stream_id_type) {
1058 /*
1059 * Only set the stream's id if the trace's packet header
1060 * contains a stream_id field. This field is only
1061 * needed if the trace contains only one stream
1062 * class.
1063 */
1064 g_string_append_printf(context->string,
1065 "\tid = %" PRId64 ";\n", stream_class->id);
1066 }
1067 bt_put(stream_id_type);
1068 }
1069 if (stream_class->event_header_type) {
1070 BT_LOGD_STR("Serializing stream class's event header field type's metadata.");
1071 g_string_append(context->string, "\tevent.header := ");
1072 ret = bt_field_type_serialize(stream_class->event_header_type,
1073 context);
1074 if (ret) {
1075 BT_LOGW("Cannot serialize stream class's event header field type's metadata: "
1076 "ret=%d", ret);
1077 goto end;
1078 }
1079 g_string_append(context->string, ";");
1080 }
1081
1082
1083 if (stream_class->packet_context_type) {
1084 BT_LOGD_STR("Serializing stream class's packet context field type's metadata.");
1085 g_string_append(context->string, "\n\n\tpacket.context := ");
1086 ret = bt_field_type_serialize(stream_class->packet_context_type,
1087 context);
1088 if (ret) {
1089 BT_LOGW("Cannot serialize stream class's packet context field type's metadata: "
1090 "ret=%d", ret);
1091 goto end;
1092 }
1093 g_string_append(context->string, ";");
1094 }
1095
1096 if (stream_class->event_context_type) {
1097 BT_LOGD_STR("Serializing stream class's event context field type's metadata.");
1098 g_string_append(context->string, "\n\n\tevent.context := ");
1099 ret = bt_field_type_serialize(
1100 stream_class->event_context_type, context);
1101 if (ret) {
1102 BT_LOGW("Cannot serialize stream class's event context field type's metadata: "
1103 "ret=%d", ret);
1104 goto end;
1105 }
1106 g_string_append(context->string, ";");
1107 }
1108
1109 g_string_append(context->string, "\n};\n\n");
1110
1111 for (i = 0; i < stream_class->event_classes->len; i++) {
1112 struct bt_event_class *event_class =
1113 stream_class->event_classes->pdata[i];
1114
1115 ret = bt_event_class_serialize(event_class, context);
1116 if (ret) {
1117 BT_LOGW("Cannot serialize event class's metadata: "
1118 "event-class-addr=%p, event-class-name=\"%s\", "
1119 "event-class-id=%" PRId64,
1120 event_class,
1121 bt_event_class_get_name(event_class),
1122 bt_event_class_get_id(event_class));
1123 goto end;
1124 }
1125 }
1126 end:
1127 bt_put(packet_header_type);
1128 context->current_indentation_level = 0;
1129 return ret;
1130 }
1131
1132 static
1133 void bt_stream_class_destroy(struct bt_object *obj)
1134 {
1135 struct bt_stream_class *stream_class;
1136
1137 stream_class = container_of(obj, struct bt_stream_class, base);
1138 BT_LOGD("Destroying stream class: addr=%p, name=\"%s\", id=%" PRId64,
1139 stream_class, bt_stream_class_get_name(stream_class),
1140 bt_stream_class_get_id(stream_class));
1141 bt_put(stream_class->clock);
1142 bt_put(stream_class->clock_class);
1143
1144 if (stream_class->event_classes_ht) {
1145 g_hash_table_destroy(stream_class->event_classes_ht);
1146 }
1147 if (stream_class->event_classes) {
1148 BT_LOGD_STR("Destroying event classes.");
1149 g_ptr_array_free(stream_class->event_classes, TRUE);
1150 }
1151
1152 if (stream_class->name) {
1153 g_string_free(stream_class->name, TRUE);
1154 }
1155
1156 BT_LOGD_STR("Putting event header field type.");
1157 bt_put(stream_class->event_header_type);
1158 BT_LOGD_STR("Putting packet context field type.");
1159 bt_put(stream_class->packet_context_type);
1160 BT_LOGD_STR("Putting event context field type.");
1161 bt_put(stream_class->event_context_type);
1162 g_free(stream_class);
1163 }
1164
1165 static
1166 int init_event_header(struct bt_stream_class *stream_class)
1167 {
1168 int ret = 0;
1169 struct bt_field_type *event_header_type =
1170 bt_field_type_structure_create();
1171 struct bt_field_type *_uint32_t =
1172 get_field_type(FIELD_TYPE_ALIAS_UINT32_T);
1173 struct bt_field_type *_uint64_t =
1174 get_field_type(FIELD_TYPE_ALIAS_UINT64_T);
1175
1176 if (!event_header_type) {
1177 BT_LOGE_STR("Cannot create empty structure field type.");
1178 ret = -1;
1179 goto end;
1180 }
1181
1182 ret = bt_field_type_structure_add_field(event_header_type,
1183 _uint32_t, "id");
1184 if (ret) {
1185 BT_LOGE_STR("Cannot add `id` field to event header field type.");
1186 goto end;
1187 }
1188
1189 ret = bt_field_type_structure_add_field(event_header_type,
1190 _uint64_t, "timestamp");
1191 if (ret) {
1192 BT_LOGE_STR("Cannot add `timestamp` field to event header field type.");
1193 goto end;
1194 }
1195
1196 BT_MOVE(stream_class->event_header_type, event_header_type);
1197 end:
1198 if (ret) {
1199 bt_put(event_header_type);
1200 }
1201
1202 bt_put(_uint32_t);
1203 bt_put(_uint64_t);
1204 return ret;
1205 }
1206
1207 static
1208 int init_packet_context(struct bt_stream_class *stream_class)
1209 {
1210 int ret = 0;
1211 struct bt_field_type *packet_context_type =
1212 bt_field_type_structure_create();
1213 struct bt_field_type *_uint64_t =
1214 get_field_type(FIELD_TYPE_ALIAS_UINT64_T);
1215 struct bt_field_type *ts_begin_end_uint64_t;
1216
1217 if (!packet_context_type) {
1218 BT_LOGE_STR("Cannot create empty structure field type.");
1219 ret = -1;
1220 goto end;
1221 }
1222
1223 ts_begin_end_uint64_t = bt_field_type_copy(_uint64_t);
1224 if (!ts_begin_end_uint64_t) {
1225 BT_LOGE_STR("Cannot copy integer field type for `timestamp_begin` and `timestamp_end` fields.");
1226 ret = -1;
1227 goto end;
1228 }
1229
1230 /*
1231 * We create a stream packet context as proposed in the CTF
1232 * specification.
1233 */
1234 ret = bt_field_type_structure_add_field(packet_context_type,
1235 ts_begin_end_uint64_t, "timestamp_begin");
1236 if (ret) {
1237 BT_LOGE_STR("Cannot add `timestamp_begin` field to event header field type.");
1238 goto end;
1239 }
1240
1241 ret = bt_field_type_structure_add_field(packet_context_type,
1242 ts_begin_end_uint64_t, "timestamp_end");
1243 if (ret) {
1244 BT_LOGE_STR("Cannot add `timestamp_end` field to event header field type.");
1245 goto end;
1246 }
1247
1248 ret = bt_field_type_structure_add_field(packet_context_type,
1249 _uint64_t, "content_size");
1250 if (ret) {
1251 BT_LOGE_STR("Cannot add `content_size` field to event header field type.");
1252 goto end;
1253 }
1254
1255 ret = bt_field_type_structure_add_field(packet_context_type,
1256 _uint64_t, "packet_size");
1257 if (ret) {
1258 BT_LOGE_STR("Cannot add `packet_size` field to event header field type.");
1259 goto end;
1260 }
1261
1262 ret = bt_field_type_structure_add_field(packet_context_type,
1263 _uint64_t, "events_discarded");
1264 if (ret) {
1265 BT_LOGE_STR("Cannot add `events_discarded` field to event header field type.");
1266 goto end;
1267 }
1268
1269 BT_MOVE(stream_class->packet_context_type, packet_context_type);
1270 end:
1271 if (ret) {
1272 bt_put(packet_context_type);
1273 goto end;
1274 }
1275
1276 bt_put(_uint64_t);
1277 bt_put(ts_begin_end_uint64_t);
1278 return ret;
1279 }
1280
1281 static
1282 int try_map_clock_class(struct bt_stream_class *stream_class,
1283 struct bt_field_type *ft)
1284 {
1285 struct bt_clock_class *mapped_clock_class = NULL;
1286 int ret = 0;
1287
1288 if (!ft) {
1289 /* Field does not exist: not an error */
1290 goto end;
1291 }
1292
1293 assert(bt_field_type_is_integer(ft));
1294 mapped_clock_class =
1295 bt_field_type_integer_get_mapped_clock_class(ft);
1296 if (!mapped_clock_class) {
1297 if (!stream_class->clock) {
1298 BT_LOGW("Cannot automatically set field's type mapped clock class: stream class's clock is not set: "
1299 "stream-class-addr=%p, stream-class-name=\"%s\", "
1300 "stream-class-id=%" PRId64 ", ft-addr=%p",
1301 stream_class, bt_stream_class_get_name(stream_class),
1302 bt_stream_class_get_id(stream_class), ft);
1303 ret = -1;
1304 goto end;
1305 }
1306
1307 ret = bt_field_type_integer_set_mapped_clock_class_no_check(
1308 ft, stream_class->clock->clock_class);
1309 if (ret) {
1310 BT_LOGW("Cannot set field type's mapped clock class: "
1311 "stream-class-addr=%p, stream-class-name=\"%s\", "
1312 "stream-class-id=%" PRId64 ", ft-addr=%p",
1313 stream_class, bt_stream_class_get_name(stream_class),
1314 bt_stream_class_get_id(stream_class), ft);
1315 goto end;
1316 }
1317
1318 BT_LOGV("Automatically mapped field type to stream class's clock class: "
1319 "stream-class-addr=%p, stream-class-name=\"%s\", "
1320 "stream-class-id=%" PRId64 ", ft-addr=%p",
1321 stream_class, bt_stream_class_get_name(stream_class),
1322 bt_stream_class_get_id(stream_class), ft);
1323 }
1324
1325 end:
1326 bt_put(mapped_clock_class);
1327 return ret;
1328 }
1329
1330 BT_HIDDEN
1331 int bt_stream_class_map_clock_class(
1332 struct bt_stream_class *stream_class,
1333 struct bt_field_type *packet_context_type,
1334 struct bt_field_type *event_header_type)
1335 {
1336 struct bt_field_type *ft = NULL;
1337 int ret = 0;
1338
1339 assert(stream_class);
1340
1341 if (packet_context_type) {
1342 ft = bt_field_type_structure_get_field_type_by_name(
1343 packet_context_type, "timestamp_begin");
1344 if (try_map_clock_class(stream_class, ft)) {
1345 BT_LOGE_STR("Cannot automatically set stream class's packet context field type's `timestamp_begin` field's mapped clock class.");
1346 ret = -1;
1347 goto end;
1348 }
1349
1350 bt_put(ft);
1351 ft = bt_field_type_structure_get_field_type_by_name(
1352 packet_context_type, "timestamp_end");
1353 if (try_map_clock_class(stream_class, ft)) {
1354 BT_LOGE_STR("Cannot automatically set stream class's packet context field type's `timestamp_end` field's mapped clock class.");
1355 ret = -1;
1356 goto end;
1357 }
1358
1359 BT_PUT(ft);
1360 }
1361
1362 if (event_header_type) {
1363 ft = bt_field_type_structure_get_field_type_by_name(
1364 event_header_type, "timestamp");
1365 if (try_map_clock_class(stream_class, ft)) {
1366 BT_LOGE_STR("Cannot automatically set stream class's event header field type's `timestamp` field's mapped clock class.");
1367 ret = -1;
1368 goto end;
1369 }
1370
1371 BT_PUT(ft);
1372 }
1373
1374 end:
1375 return ret;
1376 }
1377
1378 BT_HIDDEN
1379 int bt_stream_class_validate_single_clock_class(
1380 struct bt_stream_class *stream_class,
1381 struct bt_clock_class **expected_clock_class)
1382 {
1383 int ret;
1384 uint64_t i;
1385
1386 assert(stream_class);
1387 assert(expected_clock_class);
1388 ret = bt_validate_single_clock_class(stream_class->packet_context_type,
1389 expected_clock_class);
1390 if (ret) {
1391 BT_LOGW("Stream class's packet context field type "
1392 "is not recursively mapped to the "
1393 "expected clock class: "
1394 "stream-class-addr=%p, "
1395 "stream-class-name=\"%s\", "
1396 "stream-class-id=%" PRId64 ", "
1397 "ft-addr=%p",
1398 stream_class,
1399 bt_stream_class_get_name(stream_class),
1400 stream_class->id,
1401 stream_class->packet_context_type);
1402 goto end;
1403 }
1404
1405 ret = bt_validate_single_clock_class(stream_class->event_header_type,
1406 expected_clock_class);
1407 if (ret) {
1408 BT_LOGW("Stream class's event header field type "
1409 "is not recursively mapped to the "
1410 "expected clock class: "
1411 "stream-class-addr=%p, "
1412 "stream-class-name=\"%s\", "
1413 "stream-class-id=%" PRId64 ", "
1414 "ft-addr=%p",
1415 stream_class,
1416 bt_stream_class_get_name(stream_class),
1417 stream_class->id,
1418 stream_class->event_header_type);
1419 goto end;
1420 }
1421
1422 ret = bt_validate_single_clock_class(stream_class->event_context_type,
1423 expected_clock_class);
1424 if (ret) {
1425 BT_LOGW("Stream class's event context field type "
1426 "is not recursively mapped to the "
1427 "expected clock class: "
1428 "stream-class-addr=%p, "
1429 "stream-class-name=\"%s\", "
1430 "stream-class-id=%" PRId64 ", "
1431 "ft-addr=%p",
1432 stream_class,
1433 bt_stream_class_get_name(stream_class),
1434 stream_class->id,
1435 stream_class->event_context_type);
1436 goto end;
1437 }
1438
1439 for (i = 0; i < stream_class->event_classes->len; i++) {
1440 struct bt_event_class *event_class =
1441 g_ptr_array_index(stream_class->event_classes, i);
1442
1443 assert(event_class);
1444 ret = bt_event_class_validate_single_clock_class(event_class,
1445 expected_clock_class);
1446 if (ret) {
1447 BT_LOGW("Stream class's event class contains a "
1448 "field type which is not recursively mapped to "
1449 "the expected clock class: "
1450 "stream-class-addr=%p, "
1451 "stream-class-name=\"%s\", "
1452 "stream-class-id=%" PRId64,
1453 stream_class,
1454 bt_stream_class_get_name(stream_class),
1455 stream_class->id);
1456 goto end;
1457 }
1458 }
1459
1460 end:
1461 return ret;
1462 }
This page took 0.079644 seconds and 5 git commands to generate.