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