Allow NULL (unset) packet, stream and event headers, contexts
[babeltrace.git] / formats / ctf / ir / event.c
1 /*
2 * event.c
3 *
4 * Babeltrace CTF IR - Event
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 #include <babeltrace/ctf-ir/fields-internal.h>
30 #include <babeltrace/ctf-ir/field-types-internal.h>
31 #include <babeltrace/ctf-ir/clock-internal.h>
32 #include <babeltrace/ctf-ir/event-internal.h>
33 #include <babeltrace/ctf-ir/event-class.h>
34 #include <babeltrace/ctf-ir/event-class-internal.h>
35 #include <babeltrace/ctf-ir/stream-class.h>
36 #include <babeltrace/ctf-ir/stream-class-internal.h>
37 #include <babeltrace/ctf-ir/stream-internal.h>
38 #include <babeltrace/ctf-ir/packet.h>
39 #include <babeltrace/ctf-ir/packet-internal.h>
40 #include <babeltrace/ctf-ir/trace-internal.h>
41 #include <babeltrace/ctf-ir/validation-internal.h>
42 #include <babeltrace/ctf-ir/packet-internal.h>
43 #include <babeltrace/ctf-ir/utils.h>
44 #include <babeltrace/ref.h>
45 #include <babeltrace/ctf-ir/attributes-internal.h>
46 #include <babeltrace/compiler.h>
47
48 static
49 void bt_ctf_event_destroy(struct bt_object *obj);
50 static
51 int set_integer_field_value(struct bt_ctf_field *field, uint64_t value);
52
53 struct bt_ctf_event *bt_ctf_event_create(struct bt_ctf_event_class *event_class)
54 {
55 int ret;
56 enum bt_ctf_validation_flag validation_flags =
57 BT_CTF_VALIDATION_FLAG_STREAM |
58 BT_CTF_VALIDATION_FLAG_EVENT;
59 struct bt_ctf_event *event = NULL;
60 struct bt_ctf_trace *trace = NULL;
61 struct bt_ctf_stream_class *stream_class = NULL;
62 struct bt_ctf_field_type *packet_header_type = NULL;
63 struct bt_ctf_field_type *packet_context_type = NULL;
64 struct bt_ctf_field_type *event_header_type = NULL;
65 struct bt_ctf_field_type *stream_event_ctx_type = NULL;
66 struct bt_ctf_field_type *event_context_type = NULL;
67 struct bt_ctf_field_type *event_payload_type = NULL;
68 struct bt_ctf_field *event_header = NULL;
69 struct bt_ctf_field *stream_event_context = NULL;
70 struct bt_ctf_field *event_context = NULL;
71 struct bt_ctf_field *event_payload = NULL;
72 struct bt_value *environment = NULL;
73 struct bt_ctf_validation_output validation_output = { 0 };
74 int trace_valid = 0;
75
76 if (!event_class) {
77 goto error;
78 }
79
80 stream_class = bt_ctf_event_class_get_stream_class(event_class);
81
82 /*
83 * We disallow the creation of an event if its event class has not been
84 * associated to a stream class.
85 */
86 if (!stream_class) {
87 goto error;
88 }
89
90 /* A stream class should always have an existing event header type */
91 assert(stream_class->event_header_type);
92
93 /* The event class was frozen when added to its stream class */
94 assert(event_class->frozen);
95
96 /* Validate the trace (if any), the stream class, and the event class */
97 trace = bt_ctf_stream_class_get_trace(stream_class);
98 if (trace) {
99 packet_header_type = bt_ctf_trace_get_packet_header_type(trace);
100 trace_valid = trace->valid;
101 assert(trace_valid);
102 environment = trace->environment;
103 }
104
105 packet_context_type = bt_ctf_stream_class_get_packet_context_type(
106 stream_class);
107 event_header_type = bt_ctf_stream_class_get_event_header_type(
108 stream_class);
109 stream_event_ctx_type = bt_ctf_stream_class_get_event_context_type(
110 stream_class);
111 event_context_type = bt_ctf_event_class_get_context_type(event_class);
112 event_payload_type = bt_ctf_event_class_get_payload_type(event_class);
113 ret = bt_ctf_validate_class_types(environment, packet_header_type,
114 packet_context_type, event_header_type, stream_event_ctx_type,
115 event_context_type, event_payload_type, trace_valid,
116 stream_class->valid, event_class->valid,
117 &validation_output, validation_flags);
118 BT_PUT(packet_header_type);
119 BT_PUT(packet_context_type);
120 BT_PUT(event_header_type);
121 BT_PUT(stream_event_ctx_type);
122 BT_PUT(event_context_type);
123 BT_PUT(event_payload_type);
124 if (ret) {
125 /*
126 * This means something went wrong during the validation
127 * process, not that the objects are invalid.
128 */
129 goto error;
130 }
131
132 if ((validation_output.valid_flags & validation_flags) !=
133 validation_flags) {
134 /* Invalid trace/stream class/event class */
135 goto error;
136 }
137
138 /*
139 * At this point we know the trace (if associated to the stream
140 * class), the stream class, and the event class, with their
141 * current types, are valid. We may proceed with creating
142 * the event.
143 */
144 event = g_new0(struct bt_ctf_event, 1);
145 if (!event) {
146 goto error;
147 }
148
149 bt_object_init(event, bt_ctf_event_destroy);
150
151 /*
152 * event does not share a common ancestor with the event class; it has
153 * to guarantee its existence by holding a reference. This reference
154 * shall be released once the event is associated to a stream since,
155 * from that point, the event and its class will share the same
156 * lifetime.
157 */
158 event->event_class = bt_get(event_class);
159 event->clock_values = g_hash_table_new_full(g_direct_hash,
160 g_direct_equal, bt_put, bt_put);
161 event_header =
162 bt_ctf_field_create(validation_output.event_header_type);
163 if (!event_header) {
164 goto error;
165 }
166
167 if (validation_output.stream_event_ctx_type) {
168 stream_event_context = bt_ctf_field_create(
169 validation_output.stream_event_ctx_type);
170 if (!stream_event_context) {
171 goto error;
172 }
173 }
174
175 if (validation_output.event_context_type) {
176 event_context = bt_ctf_field_create(
177 validation_output.event_context_type);
178 if (!event_context) {
179 goto error;
180 }
181 }
182
183 if (validation_output.event_payload_type) {
184 event_payload = bt_ctf_field_create(
185 validation_output.event_payload_type);
186 if (!event_payload) {
187 goto error;
188 }
189 }
190
191 /*
192 * At this point all the fields are created, potentially from
193 * validated copies of field types, so that the field types and
194 * fields can be replaced in the trace, stream class,
195 * event class, and created event.
196 */
197 bt_ctf_validation_replace_types(trace, stream_class,
198 event_class, &validation_output, validation_flags);
199 BT_MOVE(event->event_header, event_header);
200 BT_MOVE(event->stream_event_context, stream_event_context);
201 BT_MOVE(event->context_payload, event_context);
202 BT_MOVE(event->fields_payload, event_payload);
203
204 /*
205 * Put what was not moved in bt_ctf_validation_replace_types().
206 */
207 bt_ctf_validation_output_put_types(&validation_output);
208
209 /*
210 * Freeze the stream class since the event header must not be changed
211 * anymore.
212 */
213 bt_ctf_stream_class_freeze(stream_class);
214
215 /*
216 * Mark stream class, and event class as valid since
217 * they're all frozen now.
218 */
219 stream_class->valid = 1;
220 event_class->valid = 1;
221
222 /* Put stuff we borrowed from the event class */
223 BT_PUT(stream_class);
224 BT_PUT(trace);
225
226 return event;
227
228 error:
229 bt_ctf_validation_output_put_types(&validation_output);
230 BT_PUT(event);
231 BT_PUT(stream_class);
232 BT_PUT(trace);
233 BT_PUT(event_header);
234 BT_PUT(stream_event_context);
235 BT_PUT(event_context);
236 BT_PUT(event_payload);
237 assert(!packet_header_type);
238 assert(!packet_context_type);
239 assert(!event_header_type);
240 assert(!stream_event_ctx_type);
241 assert(!event_context_type);
242 assert(!event_payload_type);
243
244 return event;
245 }
246
247 struct bt_ctf_event_class *bt_ctf_event_get_class(struct bt_ctf_event *event)
248 {
249 struct bt_ctf_event_class *event_class = NULL;
250
251 if (!event) {
252 goto end;
253 }
254
255 event_class = event->event_class;
256 bt_get(event_class);
257 end:
258 return event_class;
259 }
260
261 struct bt_ctf_stream *bt_ctf_event_get_stream(struct bt_ctf_event *event)
262 {
263 struct bt_ctf_stream *stream = NULL;
264
265 if (!event) {
266 goto end;
267 }
268
269 /*
270 * If the event has a parent, then this is its (writer) stream.
271 * If the event has no parent, then if it has a packet, this
272 * is its (non-writer) stream.
273 */
274 if (event->base.parent) {
275 stream = (struct bt_ctf_stream *) bt_object_get_parent(event);
276 } else {
277 if (event->packet) {
278 stream = bt_get(event->packet->stream);
279 }
280 }
281
282 end:
283 return stream;
284 }
285
286 int bt_ctf_event_set_payload(struct bt_ctf_event *event,
287 const char *name,
288 struct bt_ctf_field *payload)
289 {
290 int ret = 0;
291
292 if (!event || !payload || event->frozen) {
293 ret = -1;
294 goto end;
295 }
296
297 if (name) {
298 ret = bt_ctf_field_structure_set_field(event->fields_payload,
299 name, payload);
300 } else {
301 struct bt_ctf_field_type *payload_type;
302
303 payload_type = bt_ctf_field_get_type(payload);
304
305 if (bt_ctf_field_type_compare(payload_type,
306 event->event_class->fields) == 0) {
307 bt_put(event->fields_payload);
308 bt_get(payload);
309 event->fields_payload = payload;
310 } else {
311 ret = -1;
312 }
313
314 bt_put(payload_type);
315 }
316 end:
317 return ret;
318 }
319
320 struct bt_ctf_field *bt_ctf_event_get_payload_field(struct bt_ctf_event *event)
321 {
322 struct bt_ctf_field *payload = NULL;
323
324 if (!event || !event->fields_payload) {
325 goto end;
326 }
327
328 payload = event->fields_payload;
329 bt_get(payload);
330 end:
331 return payload;
332 }
333
334 int bt_ctf_event_set_payload_field(struct bt_ctf_event *event,
335 struct bt_ctf_field *payload)
336 {
337 int ret = 0;
338 struct bt_ctf_field_type *payload_type = NULL;
339
340 if (!event || event->frozen) {
341 ret = -1;
342 goto end;
343 }
344
345 payload_type = bt_ctf_field_get_type(payload);
346 if (!payload_type) {
347 ret = -1;
348 goto end;
349 }
350
351 if (bt_ctf_field_type_get_type_id(payload_type) !=
352 BT_CTF_TYPE_ID_STRUCT) {
353 ret = -1;
354 goto end;
355 }
356
357 bt_put(event->fields_payload);
358 event->fields_payload = bt_get(payload);
359 end:
360 bt_put(payload_type);
361 return ret;
362 }
363
364 struct bt_ctf_field *bt_ctf_event_get_payload(struct bt_ctf_event *event,
365 const char *name)
366 {
367 struct bt_ctf_field *field = NULL;
368
369 if (!event) {
370 goto end;
371 }
372
373 if (name) {
374 field = bt_ctf_field_structure_get_field(event->fields_payload,
375 name);
376 } else {
377 field = event->fields_payload;
378 bt_get(field);
379 }
380 end:
381 return field;
382 }
383
384 struct bt_ctf_field *bt_ctf_event_get_payload_by_index(
385 struct bt_ctf_event *event, int index)
386 {
387 struct bt_ctf_field *field = NULL;
388
389 if (!event || index < 0) {
390 goto end;
391 }
392
393 field = bt_ctf_field_structure_get_field_by_index(event->fields_payload,
394 index);
395 end:
396 return field;
397 }
398
399 struct bt_ctf_field *bt_ctf_event_get_header(
400 struct bt_ctf_event *event)
401 {
402 struct bt_ctf_field *header = NULL;
403
404 if (!event || !event->event_header) {
405 goto end;
406 }
407
408 header = event->event_header;
409 bt_get(header);
410 end:
411 return header;
412 }
413
414 int bt_ctf_event_set_header(struct bt_ctf_event *event,
415 struct bt_ctf_field *header)
416 {
417 int ret = 0;
418 struct bt_ctf_field_type *field_type = NULL;
419 struct bt_ctf_stream_class *stream_class = NULL;
420
421 if (!event || event->frozen) {
422 ret = -1;
423 goto end;
424 }
425
426 stream_class = (struct bt_ctf_stream_class *) bt_object_get_parent(
427 event->event_class);
428 /*
429 * Ensure the provided header's type matches the one registered to the
430 * stream class.
431 */
432 field_type = bt_ctf_field_get_type(header);
433 if (bt_ctf_field_type_compare(field_type,
434 stream_class->event_header_type)) {
435 ret = -1;
436 goto end;
437 }
438
439 bt_put(event->event_header);
440 event->event_header = bt_get(header);
441 end:
442 bt_put(stream_class);
443 bt_put(field_type);
444 return ret;
445 }
446
447 struct bt_ctf_field *bt_ctf_event_get_event_context(
448 struct bt_ctf_event *event)
449 {
450 struct bt_ctf_field *context = NULL;
451
452 if (!event || !event->context_payload) {
453 goto end;
454 }
455
456 context = event->context_payload;
457 bt_get(context);
458 end:
459 return context;
460 }
461
462 int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
463 struct bt_ctf_field *context)
464 {
465 int ret = 0;
466 struct bt_ctf_field_type *field_type = NULL;
467
468 if (!event || event->frozen) {
469 ret = -1;
470 goto end;
471 }
472
473 field_type = bt_ctf_field_get_type(context);
474 if (bt_ctf_field_type_compare(field_type,
475 event->event_class->context)) {
476 ret = -1;
477 goto end;
478 }
479
480 bt_put(event->context_payload);
481 event->context_payload = bt_get(context);
482 end:
483 bt_put(field_type);
484 return ret;
485 }
486
487 struct bt_ctf_field *bt_ctf_event_get_stream_event_context(
488 struct bt_ctf_event *event)
489 {
490 struct bt_ctf_field *stream_event_context = NULL;
491
492 if (!event || !event->stream_event_context) {
493 goto end;
494 }
495
496 stream_event_context = event->stream_event_context;
497 end:
498 return bt_get(stream_event_context);
499 }
500
501 int bt_ctf_event_set_stream_event_context(struct bt_ctf_event *event,
502 struct bt_ctf_field *stream_event_context)
503 {
504 int ret = 0;
505 struct bt_ctf_field_type *field_type = NULL;
506 struct bt_ctf_stream_class *stream_class = NULL;
507
508 if (!event || event->frozen) {
509 ret = -1;
510 goto end;
511 }
512
513 stream_class = bt_ctf_event_class_get_stream_class(event->event_class);
514 /*
515 * We should not have been able to create the event without associating
516 * the event class to a stream class.
517 */
518 assert(stream_class);
519
520 field_type = bt_ctf_field_get_type(stream_event_context);
521 if (bt_ctf_field_type_compare(field_type,
522 stream_class->event_context_type)) {
523 ret = -1;
524 goto end;
525 }
526
527 bt_get(stream_event_context);
528 BT_MOVE(event->stream_event_context, stream_event_context);
529 end:
530 BT_PUT(stream_class);
531 bt_put(field_type);
532 return ret;
533 }
534
535 void bt_ctf_event_get(struct bt_ctf_event *event)
536 {
537 bt_get(event);
538 }
539
540 void bt_ctf_event_put(struct bt_ctf_event *event)
541 {
542 bt_put(event);
543 }
544
545 void bt_ctf_event_destroy(struct bt_object *obj)
546 {
547 struct bt_ctf_event *event;
548
549 event = container_of(obj, struct bt_ctf_event, base);
550 if (!event->base.parent) {
551 /*
552 * Event was keeping a reference to its class since it shared no
553 * common ancestor with it to guarantee they would both have the
554 * same lifetime.
555 */
556 bt_put(event->event_class);
557 }
558 g_hash_table_destroy(event->clock_values);
559 bt_put(event->event_header);
560 bt_put(event->stream_event_context);
561 bt_put(event->context_payload);
562 bt_put(event->fields_payload);
563 bt_put(event->packet);
564 g_free(event);
565 }
566
567 struct bt_ctf_clock_value *bt_ctf_event_get_clock_value(
568 struct bt_ctf_event *event, struct bt_ctf_clock *clock)
569 {
570 struct bt_ctf_clock_value *clock_value = NULL;
571
572 if (!event || !clock) {
573 goto end;
574 }
575
576 clock_value = g_hash_table_lookup(event->clock_values, clock);
577 if (!clock_value) {
578 goto end;
579 }
580
581 bt_get(clock_value);
582 end:
583 return clock_value;
584 }
585
586 int bt_ctf_event_set_clock_value(struct bt_ctf_event *event,
587 struct bt_ctf_clock *clock, struct bt_ctf_clock_value *value)
588 {
589 int ret = 0;
590
591 if (!event || !clock || !value || event->frozen) {
592 ret = -1;
593 goto end;
594 }
595
596 g_hash_table_insert(event->clock_values, bt_get(clock), bt_get(value));
597 end:
598 return ret;
599 }
600
601 static
602 int set_integer_field_value(struct bt_ctf_field* field, uint64_t value)
603 {
604 int ret = 0;
605 struct bt_ctf_field_type *field_type = NULL;
606
607 if (!field) {
608 ret = -1;
609 goto end;
610 }
611
612 field_type = bt_ctf_field_get_type(field);
613 assert(field_type);
614
615 if (bt_ctf_field_type_get_type_id(field_type) !=
616 BT_CTF_TYPE_ID_INTEGER) {
617 /* Not an integer and the value is unset, error. */
618 ret = -1;
619 goto end;
620 }
621
622 if (bt_ctf_field_type_integer_get_signed(field_type)) {
623 ret = bt_ctf_field_signed_integer_set_value(field, (int64_t) value);
624 if (ret) {
625 /* Value is out of range, error. */
626 goto end;
627 }
628 } else {
629 ret = bt_ctf_field_unsigned_integer_set_value(field, value);
630 if (ret) {
631 /* Value is out of range, error. */
632 goto end;
633 }
634 }
635 end:
636 bt_put(field_type);
637 return ret;
638 }
639
640 BT_HIDDEN
641 int bt_ctf_event_validate(struct bt_ctf_event *event)
642 {
643 /* Make sure each field's payload has been set */
644 int ret;
645 struct bt_ctf_stream_class *stream_class = NULL;
646
647 assert(event);
648 ret = bt_ctf_field_validate(event->event_header);
649 if (ret) {
650 goto end;
651 }
652
653 stream_class = bt_ctf_event_class_get_stream_class(event->event_class);
654 /*
655 * We should not have been able to create the event without associating
656 * the event class to a stream class.
657 */
658 assert(stream_class);
659 if (stream_class->event_context_type) {
660 ret = bt_ctf_field_validate(event->stream_event_context);
661 if (ret) {
662 goto end;
663 }
664 }
665
666 ret = bt_ctf_field_validate(event->fields_payload);
667 if (ret) {
668 goto end;
669 }
670
671 if (event->event_class->context) {
672 ret = bt_ctf_field_validate(event->context_payload);
673 }
674 end:
675 bt_put(stream_class);
676 return ret;
677 }
678
679 BT_HIDDEN
680 int bt_ctf_event_serialize(struct bt_ctf_event *event,
681 struct ctf_stream_pos *pos)
682 {
683 int ret = 0;
684
685 assert(event);
686 assert(pos);
687 if (event->context_payload) {
688 ret = bt_ctf_field_serialize(event->context_payload, pos);
689 if (ret) {
690 goto end;
691 }
692 }
693
694 if (event->fields_payload) {
695 ret = bt_ctf_field_serialize(event->fields_payload, pos);
696 if (ret) {
697 goto end;
698 }
699 }
700 end:
701 return ret;
702 }
703
704 BT_HIDDEN
705 int bt_ctf_event_populate_event_header(struct bt_ctf_event *event)
706 {
707 int ret = 0;
708 struct bt_ctf_field *id_field = NULL, *timestamp_field = NULL;
709 struct bt_ctf_clock *mapped_clock = NULL;
710
711 if (!event || event->frozen) {
712 ret = -1;
713 goto end;
714 }
715
716 id_field = bt_ctf_field_structure_get_field(event->event_header, "id");
717 if (id_field && !bt_ctf_field_is_set(id_field)) {
718 ret = set_integer_field_value(id_field,
719 (uint64_t) bt_ctf_event_class_get_id(
720 event->event_class));
721 if (ret) {
722 goto end;
723 }
724 }
725
726 timestamp_field = bt_ctf_field_structure_get_field(event->event_header,
727 "timestamp");
728 if (timestamp_field && !bt_ctf_field_is_set(timestamp_field)) {
729 struct bt_ctf_field_type *timestamp_field_type =
730 bt_ctf_field_get_type(timestamp_field);
731
732 assert(timestamp_field_type);
733 mapped_clock = bt_ctf_field_type_integer_get_mapped_clock(
734 timestamp_field_type);
735 bt_put(timestamp_field_type);
736 if (mapped_clock) {
737 /*
738 * Babeltrace 2.0 introduced a notion of per-event clock
739 * values which can be queried using a "clock" instance.
740 *
741 * However, the original CTF-Writer (BT 1.x) had a
742 * notion of per-stream clock which is sampled on
743 * a call to append an event to a stream.
744 *
745 * If the event has a clock value associated with the
746 * mapped clock, we ignore the pre-2.0 behaviour and
747 * populate the timestamp field using the clock value.
748 */
749 uint64_t timestamp = 0;
750 struct bt_ctf_clock_value *clock_value;
751
752 clock_value = bt_ctf_event_get_clock_value(event,
753 mapped_clock);
754 if (clock_value) {
755 ret = bt_ctf_clock_value_get_value(clock_value,
756 &timestamp);
757 bt_put(clock_value);
758 if (ret) {
759 goto end;
760 }
761 } else {
762 ret = bt_ctf_clock_get_value(mapped_clock,
763 &timestamp);
764 if (ret) {
765 goto end;
766 }
767 }
768
769 ret = set_integer_field_value(timestamp_field,
770 timestamp);
771 if (ret) {
772 goto end;
773 }
774 }
775 }
776 end:
777 bt_put(id_field);
778 bt_put(timestamp_field);
779 bt_put(mapped_clock);
780 return ret;
781 }
782
783 struct bt_ctf_packet *bt_ctf_event_get_packet(struct bt_ctf_event *event)
784 {
785 struct bt_ctf_packet *packet = NULL;
786
787 if (!event || !event->packet) {
788 goto end;
789 }
790
791 packet = bt_get(event->packet);
792 end:
793 return packet;
794 }
795
796 int bt_ctf_event_set_packet(struct bt_ctf_event *event,
797 struct bt_ctf_packet *packet)
798 {
799 struct bt_ctf_stream_class *event_stream_class = NULL;
800 struct bt_ctf_stream_class *packet_stream_class = NULL;
801 struct bt_ctf_stream *stream = NULL;
802 int ret = 0;
803
804 if (!event || !packet || event->frozen) {
805 ret = -1;
806 goto end;
807 }
808
809 /*
810 * Make sure the new packet was created by this event's
811 * stream, if it is set.
812 */
813 stream = bt_ctf_event_get_stream(event);
814 if (stream) {
815 if (packet->stream != stream) {
816 ret = -1;
817 goto end;
818 }
819 } else {
820 event_stream_class =
821 bt_ctf_event_class_get_stream_class(event->event_class);
822 packet_stream_class =
823 bt_ctf_stream_get_class(packet->stream);
824
825 assert(event_stream_class);
826 assert(packet_stream_class);
827
828 if (event_stream_class != packet_stream_class) {
829 ret = -1;
830 goto end;
831 }
832 }
833
834 bt_get(packet);
835 BT_MOVE(event->packet, packet);
836
837 end:
838 BT_PUT(stream);
839 BT_PUT(event_stream_class);
840 BT_PUT(packet_stream_class);
841
842 return ret;
843 }
844
845 BT_HIDDEN
846 void bt_ctf_event_freeze(struct bt_ctf_event *event)
847 {
848 assert(event);
849 bt_ctf_packet_freeze(event->packet);
850 bt_ctf_field_freeze(event->event_header);
851 bt_ctf_field_freeze(event->stream_event_context);
852 bt_ctf_field_freeze(event->context_payload);
853 bt_ctf_field_freeze(event->fields_payload);
854 event->frozen = 1;
855 }
This page took 0.046911 seconds and 4 git commands to generate.