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