ctf: notif-iter: ensure that all packets refer to the same stream class
[babeltrace.git] / plugins / ctf / common / notif-iter / notif-iter.c
1 /*
2 * Babeltrace - CTF notification iterator
3 *
4 * Copyright (c) 2015-2016 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015-2016 Philippe Proulx <pproulx@efficios.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #define BT_LOG_TAG "PLUGIN-CTF-NOTIF-ITER"
27 #include "logging.h"
28
29 #include <stdint.h>
30 #include <inttypes.h>
31 #include <stdio.h>
32 #include <stddef.h>
33 #include <stdbool.h>
34 #include <assert.h>
35 #include <string.h>
36 #include <babeltrace/ctf-ir/field-types.h>
37 #include <babeltrace/ctf-ir/field-types-internal.h>
38 #include <babeltrace/ctf-ir/field-path.h>
39 #include <babeltrace/ctf-ir/field-path-internal.h>
40 #include <babeltrace/ctf-ir/fields.h>
41 #include <babeltrace/ctf-ir/stream-class.h>
42 #include <babeltrace/ctf-ir/packet.h>
43 #include <babeltrace/ctf-ir/stream.h>
44 #include <babeltrace/ctf-ir/clock-class.h>
45 #include <babeltrace/ctf-ir/event-class.h>
46 #include <babeltrace/graph/notification-packet.h>
47 #include <babeltrace/graph/notification-event.h>
48 #include <babeltrace/graph/notification-stream.h>
49 #include <babeltrace/graph/clock-class-priority-map.h>
50 #include <babeltrace/ref.h>
51 #include <glib.h>
52 #include <stdlib.h>
53
54 #include "notif-iter.h"
55 #include "../btr/btr.h"
56
57 struct bt_ctf_notif_iter;
58
59 /* A visit stack entry */
60 struct stack_entry {
61 /*
62 * Current base field, one of:
63 *
64 * * string
65 * * structure
66 * * array
67 * * sequence
68 * * variant
69 *
70 * Field is owned by this.
71 */
72 struct bt_ctf_field *base;
73
74 /* index of next field to set */
75 size_t index;
76 };
77
78 /* Visit stack */
79 struct stack {
80 /* Entries (struct stack_entry *) (top is last element) */
81 GPtrArray *entries;
82 };
83
84 /* State */
85 enum state {
86 STATE_INIT,
87 STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN,
88 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE,
89 STATE_AFTER_TRACE_PACKET_HEADER,
90 STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN,
91 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
92 STATE_AFTER_STREAM_PACKET_CONTEXT,
93 STATE_EMIT_NOTIF_NEW_PACKET,
94 STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN,
95 STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE,
96 STATE_AFTER_STREAM_EVENT_HEADER,
97 STATE_DSCOPE_STREAM_EVENT_CONTEXT_BEGIN,
98 STATE_DSCOPE_STREAM_EVENT_CONTEXT_CONTINUE,
99 STATE_DSCOPE_EVENT_CONTEXT_BEGIN,
100 STATE_DSCOPE_EVENT_CONTEXT_CONTINUE,
101 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN,
102 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
103 STATE_EMIT_NOTIF_EVENT,
104 STATE_EMIT_NOTIF_END_OF_PACKET,
105 STATE_SKIP_PACKET_PADDING,
106 };
107
108 struct trace_field_path_cache {
109 /*
110 * Indexes of the stream_id and stream_instance_id field in the packet
111 * header structure, -1 if unset.
112 */
113 int stream_id;
114 int stream_instance_id;
115 };
116
117 struct stream_class_field_path_cache {
118 /*
119 * Indexes of the v and id fields in the stream event header structure,
120 * -1 if unset.
121 */
122 int v;
123 int id;
124
125 /*
126 * index of the timestamp_end, packet_size and content_size fields in
127 * the stream packet context structure. Set to -1 if the fields were
128 * not found.
129 */
130 int timestamp_end;
131 int packet_size;
132 int content_size;
133 };
134
135 struct field_cb_override {
136 enum bt_ctf_btr_status (* func)(void *value,
137 struct bt_ctf_field_type *type, void *data);
138 void *data;
139 };
140
141 /* CTF notification iterator */
142 struct bt_ctf_notif_iter {
143 /* Visit stack */
144 struct stack *stack;
145
146 /*
147 * Current dynamic scope field pointer.
148 *
149 * This is set when a dynamic scope field is first created by
150 * btr_compound_begin_cb(). It points to one of the fields in
151 * dscopes below.
152 */
153 struct bt_ctf_field **cur_dscope_field;
154
155 /* Trace and classes (owned by this) */
156 struct {
157 struct bt_ctf_trace *trace;
158 struct bt_ctf_stream_class *stream_class;
159 struct bt_ctf_event_class *event_class;
160 } meta;
161
162 /* Current packet (NULL if not created yet) */
163 struct bt_ctf_packet *packet;
164
165 /* Current stream (NULL if not set yet) */
166 struct bt_ctf_stream *stream;
167
168 /*
169 * Current timestamp_end field (to consider before switching packets).
170 */
171 struct bt_ctf_field *cur_timestamp_end;
172
173 /* Database of current dynamic scopes (owned by this) */
174 struct {
175 struct bt_ctf_field *trace_packet_header;
176 struct bt_ctf_field *stream_packet_context;
177 struct bt_ctf_field *stream_event_header;
178 struct bt_ctf_field *stream_event_context;
179 struct bt_ctf_field *event_context;
180 struct bt_ctf_field *event_payload;
181 } dscopes;
182
183 /*
184 * Special field overrides.
185 *
186 * Overrides are used to implement the behaviours of special fields such
187 * as "timestamp_end" (which must be ignored until the end of the
188 * packet), "id" (event id) which can be present multiple times and must
189 * be updated multiple time.
190 *
191 * This should be used to implement the behaviour of integer fields
192 * mapped to clocks and other "tagged" fields (in CTF 2).
193 *
194 * bt_ctf_field_type to struct field_cb_override
195 */
196 GHashTable *field_overrides;
197
198 /* Current state */
199 enum state state;
200
201 /* Current medium buffer data */
202 struct {
203 /* Last address provided by medium */
204 const uint8_t *addr;
205
206 /* Buffer size provided by medium (bytes) */
207 size_t sz;
208
209 /* Offset within whole packet of addr (bits) */
210 size_t packet_offset;
211
212 /* Current position from addr (bits) */
213 size_t at;
214 } buf;
215
216 /* Binary type reader */
217 struct bt_ctf_btr *btr;
218
219 /* Current medium data */
220 struct {
221 struct bt_ctf_notif_iter_medium_ops medops;
222 size_t max_request_sz;
223 void *data;
224 } medium;
225
226 /* Current packet size (bits) (-1 if unknown) */
227 int64_t cur_packet_size;
228
229 /* Current content size (bits) (-1 if unknown) */
230 int64_t cur_content_size;
231
232 /* bt_ctf_clock_class to uint64_t. */
233 GHashTable *clock_states;
234
235 /*
236 * Cache of the trace-constant field paths (event header type)
237 * associated to the current trace.
238 */
239 struct trace_field_path_cache trace_field_path_cache;
240
241 /*
242 * Field path cache associated with the current stream class.
243 * Ownership of this structure belongs to the field_path_caches HT.
244 */
245 struct stream_class_field_path_cache *cur_sc_field_path_cache;
246
247 /* bt_ctf_stream_class to struct stream_class_field_path_cache. */
248 GHashTable *sc_field_path_caches;
249 };
250
251 static inline
252 const char *state_string(enum state state)
253 {
254 switch (state) {
255 case STATE_INIT:
256 return "STATE_INIT";
257 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
258 return "STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN";
259 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
260 return "STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE";
261 case STATE_AFTER_TRACE_PACKET_HEADER:
262 return "STATE_AFTER_TRACE_PACKET_HEADER";
263 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
264 return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN";
265 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
266 return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE";
267 case STATE_AFTER_STREAM_PACKET_CONTEXT:
268 return "STATE_AFTER_STREAM_PACKET_CONTEXT";
269 case STATE_EMIT_NOTIF_NEW_PACKET:
270 return "STATE_EMIT_NOTIF_NEW_PACKET";
271 case STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN:
272 return "STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN";
273 case STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE:
274 return "STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE";
275 case STATE_AFTER_STREAM_EVENT_HEADER:
276 return "STATE_AFTER_STREAM_EVENT_HEADER";
277 case STATE_DSCOPE_STREAM_EVENT_CONTEXT_BEGIN:
278 return "STATE_DSCOPE_STREAM_EVENT_CONTEXT_BEGIN";
279 case STATE_DSCOPE_STREAM_EVENT_CONTEXT_CONTINUE:
280 return "STATE_DSCOPE_STREAM_EVENT_CONTEXT_CONTINUE";
281 case STATE_DSCOPE_EVENT_CONTEXT_BEGIN:
282 return "STATE_DSCOPE_EVENT_CONTEXT_BEGIN";
283 case STATE_DSCOPE_EVENT_CONTEXT_CONTINUE:
284 return "STATE_DSCOPE_EVENT_CONTEXT_CONTINUE";
285 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN:
286 return "STATE_DSCOPE_EVENT_PAYLOAD_BEGIN";
287 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE:
288 return "STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE";
289 case STATE_EMIT_NOTIF_EVENT:
290 return "STATE_EMIT_NOTIF_EVENT";
291 case STATE_EMIT_NOTIF_END_OF_PACKET:
292 return "STATE_EMIT_NOTIF_END_OF_PACKET";
293 case STATE_SKIP_PACKET_PADDING:
294 return "STATE_SKIP_PACKET_PADDING";
295 default:
296 return "(unknown)";
297 }
298 }
299
300 static
301 int bt_ctf_notif_iter_switch_packet(struct bt_ctf_notif_iter *notit);
302
303 static
304 enum bt_ctf_btr_status btr_timestamp_end_cb(void *value,
305 struct bt_ctf_field_type *type, void *data);
306
307 static
308 void stack_entry_free_func(gpointer data)
309 {
310 struct stack_entry *entry = data;
311
312 bt_put(entry->base);
313 g_free(entry);
314 }
315
316 static
317 struct stack *stack_new(struct bt_ctf_notif_iter *notit)
318 {
319 struct stack *stack = NULL;
320
321 stack = g_new0(struct stack, 1);
322 if (!stack) {
323 BT_LOGE_STR("Failed to allocate one stack.");
324 goto error;
325 }
326
327 stack->entries = g_ptr_array_new_with_free_func(stack_entry_free_func);
328 if (!stack->entries) {
329 BT_LOGE_STR("Failed to allocate a GPtrArray.");
330 goto error;
331 }
332
333 BT_LOGD("Created stack: notit-addr=%p, stack-addr=%p", notit, stack);
334 return stack;
335
336 error:
337 g_free(stack);
338 return NULL;
339 }
340
341 static
342 void stack_destroy(struct stack *stack)
343 {
344 assert(stack);
345 BT_LOGD("Destroying stack: addr=%p", stack);
346 g_ptr_array_free(stack->entries, TRUE);
347 g_free(stack);
348 }
349
350 static
351 int stack_push(struct stack *stack, struct bt_ctf_field *base)
352 {
353 int ret = 0;
354 struct stack_entry *entry;
355
356 assert(stack);
357 assert(base);
358 BT_LOGV("Pushing base field on stack: stack-addr=%p, "
359 "stack-size-before=%u, stack-size-after=%u",
360 stack, stack->entries->len, stack->entries->len + 1);
361 entry = g_new0(struct stack_entry, 1);
362 if (!entry) {
363 BT_LOGE_STR("Failed to allocate one stack entry.");
364 ret = -1;
365 goto end;
366 }
367
368 entry->base = bt_get(base);
369 g_ptr_array_add(stack->entries, entry);
370
371 end:
372 return ret;
373 }
374
375 static inline
376 unsigned int stack_size(struct stack *stack)
377 {
378 assert(stack);
379
380 return stack->entries->len;
381 }
382
383 static
384 void stack_pop(struct stack *stack)
385 {
386 assert(stack);
387 assert(stack_size(stack));
388 BT_LOGV("Popping from stack: "
389 "stack-addr=%p, stack-size-before=%u, stack-size-after=%u",
390 stack, stack->entries->len, stack->entries->len - 1);
391 g_ptr_array_remove_index(stack->entries, stack->entries->len - 1);
392 }
393
394 static inline
395 struct stack_entry *stack_top(struct stack *stack)
396 {
397 assert(stack);
398 assert(stack_size(stack));
399
400 return g_ptr_array_index(stack->entries, stack->entries->len - 1);
401 }
402
403 static inline
404 bool stack_empty(struct stack *stack)
405 {
406 return stack_size(stack) == 0;
407 }
408
409 static
410 void stack_clear(struct stack *stack)
411 {
412 assert(stack);
413
414 if (!stack_empty(stack)) {
415 BT_LOGV("Clearing stack: stack-addr=%p, stack-size=%u",
416 stack, stack->entries->len);
417 g_ptr_array_remove_range(stack->entries, 0, stack_size(stack));
418 }
419
420 assert(stack_empty(stack));
421 }
422
423 static inline
424 enum bt_ctf_notif_iter_status notif_iter_status_from_m_status(
425 enum bt_ctf_notif_iter_medium_status m_status)
426 {
427 return (int) m_status;
428 }
429
430 static inline
431 size_t buf_size_bits(struct bt_ctf_notif_iter *notit)
432 {
433 return notit->buf.sz * 8;
434 }
435
436 static inline
437 size_t buf_available_bits(struct bt_ctf_notif_iter *notit)
438 {
439 return buf_size_bits(notit) - notit->buf.at;
440 }
441
442 static inline
443 size_t packet_at(struct bt_ctf_notif_iter *notit)
444 {
445 return notit->buf.packet_offset + notit->buf.at;
446 }
447
448 static inline
449 void buf_consume_bits(struct bt_ctf_notif_iter *notit, size_t incr)
450 {
451 BT_LOGV("Advancing cursor: notit-addr=%p, cur-before=%zu, cur-after=%zu",
452 notit, notit->buf.at, notit->buf.at + incr);
453 notit->buf.at += incr;
454 }
455
456 static
457 enum bt_ctf_notif_iter_status request_medium_bytes(
458 struct bt_ctf_notif_iter *notit)
459 {
460 uint8_t *buffer_addr = NULL;
461 size_t buffer_sz = 0;
462 enum bt_ctf_notif_iter_medium_status m_status;
463
464 BT_LOGV("Calling user function (request bytes): notit-addr=%p, "
465 "request-size=%zu", notit, notit->medium.max_request_sz);
466 m_status = notit->medium.medops.request_bytes(
467 notit->medium.max_request_sz, &buffer_addr,
468 &buffer_sz, notit->medium.data);
469 BT_LOGV("User function returned: status=%s, buf-addr=%p, buf-size=%zu",
470 bt_ctf_notif_iter_medium_status_string(m_status),
471 buffer_addr, buffer_sz);
472 if (m_status == BT_CTF_NOTIF_ITER_MEDIUM_STATUS_OK) {
473 assert(buffer_sz != 0);
474
475 /* New packet offset is old one + old size (in bits) */
476 notit->buf.packet_offset += buf_size_bits(notit);
477
478 /* Restart at the beginning of the new medium buffer */
479 notit->buf.at = 0;
480
481 /* New medium buffer size */
482 notit->buf.sz = buffer_sz;
483
484 /* New medium buffer address */
485 notit->buf.addr = buffer_addr;
486
487 BT_LOGV("User function returned new bytes: "
488 "packet-offset=%zu, cur=%zu, size=%zu, addr=%p",
489 notit->buf.packet_offset, notit->buf.at,
490 notit->buf.sz, notit->buf.addr);
491 BT_LOGV_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:",
492 buffer_addr);
493 } else if (m_status < 0) {
494 BT_LOGW("User function failed: status=%s",
495 bt_ctf_notif_iter_medium_status_string(m_status));
496 }
497
498 return notif_iter_status_from_m_status(m_status);
499 }
500
501 static inline
502 enum bt_ctf_notif_iter_status buf_ensure_available_bits(
503 struct bt_ctf_notif_iter *notit)
504 {
505 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
506
507 if (buf_available_bits(notit) == 0) {
508 /*
509 * This _cannot_ return BT_CTF_NOTIF_ITER_STATUS_OK
510 * _and_ no bits.
511 */
512 status = request_medium_bytes(notit);
513 }
514
515 return status;
516 }
517
518 static
519 enum bt_ctf_notif_iter_status read_dscope_begin_state(
520 struct bt_ctf_notif_iter *notit,
521 struct bt_ctf_field_type *dscope_field_type,
522 enum state done_state, enum state continue_state,
523 struct bt_ctf_field **dscope_field)
524 {
525 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
526 enum bt_ctf_btr_status btr_status;
527 size_t consumed_bits;
528
529 status = buf_ensure_available_bits(notit);
530 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
531 if (status < 0) {
532 BT_LOGW("Cannot ensure that buffer has at least one byte: "
533 "notif-addr=%p, status=%s",
534 notit, bt_ctf_notif_iter_status_string(status));
535 } else {
536 BT_LOGV("Cannot ensure that buffer has at least one byte: "
537 "notif-addr=%p, status=%s",
538 notit, bt_ctf_notif_iter_status_string(status));
539 }
540
541 goto end;
542 }
543
544 bt_put(*dscope_field);
545 notit->cur_dscope_field = dscope_field;
546 BT_LOGV("Starting BTR: notit-addr=%p, btr-addr=%p, ft-addr=%p",
547 notit, notit->btr, dscope_field_type);
548 consumed_bits = bt_ctf_btr_start(notit->btr, dscope_field_type,
549 notit->buf.addr, notit->buf.at, packet_at(notit),
550 notit->buf.sz, &btr_status);
551 BT_LOGV("BTR consumed bits: size=%zu", consumed_bits);
552
553 switch (btr_status) {
554 case BT_CTF_BTR_STATUS_OK:
555 /* type was read completely */
556 BT_LOGV_STR("Field was completely decoded.");
557 notit->state = done_state;
558 break;
559 case BT_CTF_BTR_STATUS_EOF:
560 BT_LOGV_STR("BTR needs more data to decode field completely.");
561 notit->state = continue_state;
562 break;
563 default:
564 BT_LOGW("BTR failed to start: notit-addr=%p, btr-addr=%p, "
565 "status=%s", notit, notit->btr,
566 bt_ctf_btr_status_string(btr_status));
567 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
568 goto end;
569 }
570
571 /* Consume bits now since we know we're not in an error state */
572 buf_consume_bits(notit, consumed_bits);
573
574 end:
575 return status;
576 }
577
578 static
579 enum bt_ctf_notif_iter_status read_dscope_continue_state(
580 struct bt_ctf_notif_iter *notit, enum state done_state)
581 {
582 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
583 enum bt_ctf_btr_status btr_status;
584 size_t consumed_bits;
585
586 status = buf_ensure_available_bits(notit);
587 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
588 if (status < 0) {
589 BT_LOGW("Cannot ensure that buffer has at least one byte: "
590 "notif-addr=%p, status=%s",
591 notit, bt_ctf_notif_iter_status_string(status));
592 } else {
593 BT_LOGV("Cannot ensure that buffer has at least one byte: "
594 "notif-addr=%p, status=%s",
595 notit, bt_ctf_notif_iter_status_string(status));
596 }
597
598 goto end;
599 }
600
601 BT_LOGV("Continuing BTR: notit-addr=%p, btr-addr=%p",
602 notit, notit->btr);
603 consumed_bits = bt_ctf_btr_continue(notit->btr, notit->buf.addr,
604 notit->buf.sz, &btr_status);
605 BT_LOGV("BTR consumed bits: size=%zu", consumed_bits);
606
607 switch (btr_status) {
608 case BT_CTF_BTR_STATUS_OK:
609 /* Type was read completely. */
610 BT_LOGV_STR("Field was completely decoded.");
611 notit->state = done_state;
612 break;
613 case BT_CTF_BTR_STATUS_EOF:
614 /* Stay in this continue state. */
615 BT_LOGV_STR("BTR needs more data to decode field completely.");
616 break;
617 default:
618 BT_LOGW("BTR failed to continue: notit-addr=%p, btr-addr=%p, "
619 "status=%s", notit, notit->btr,
620 bt_ctf_btr_status_string(btr_status));
621 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
622 goto end;
623 }
624
625 /* Consume bits now since we know we're not in an error state. */
626 buf_consume_bits(notit, consumed_bits);
627 end:
628 return status;
629 }
630
631 static
632 void put_event_dscopes(struct bt_ctf_notif_iter *notit)
633 {
634 BT_LOGV_STR("Putting event header field.");
635 BT_PUT(notit->dscopes.stream_event_header);
636 BT_LOGV_STR("Putting stream event context field.");
637 BT_PUT(notit->dscopes.stream_event_context);
638 BT_LOGV_STR("Putting event context field.");
639 BT_PUT(notit->dscopes.event_context);
640 BT_LOGV_STR("Putting event payload field.");
641 BT_PUT(notit->dscopes.event_payload);
642 }
643
644 static
645 void put_all_dscopes(struct bt_ctf_notif_iter *notit)
646 {
647 BT_LOGV_STR("Putting packet header field.");
648 BT_PUT(notit->dscopes.trace_packet_header);
649 BT_LOGV_STR("Putting packet context field.");
650 BT_PUT(notit->dscopes.stream_packet_context);
651 put_event_dscopes(notit);
652 }
653
654 static
655 enum bt_ctf_notif_iter_status read_packet_header_begin_state(
656 struct bt_ctf_notif_iter *notit)
657 {
658 struct bt_ctf_field_type *packet_header_type = NULL;
659 enum bt_ctf_notif_iter_status ret = BT_CTF_NOTIF_ITER_STATUS_OK;
660
661 if (bt_ctf_notif_iter_switch_packet(notit)) {
662 BT_LOGW("Cannot switch packet: notit-addr=%p", notit);
663 ret = BT_CTF_NOTIF_ITER_STATUS_ERROR;
664 goto end;
665 }
666
667 /* Packet header type is common to the whole trace. */
668 packet_header_type = bt_ctf_trace_get_packet_header_type(
669 notit->meta.trace);
670 if (!packet_header_type) {
671 notit->state = STATE_AFTER_TRACE_PACKET_HEADER;
672 goto end;
673 }
674
675 BT_LOGV("Decoding packet header field:"
676 "notit-addr=%p, trace-addr=%p, trace-name=\"%s\", ft-addr=%p",
677 notit, notit->meta.trace,
678 bt_ctf_trace_get_name(notit->meta.trace), packet_header_type);
679 ret = read_dscope_begin_state(notit, packet_header_type,
680 STATE_AFTER_TRACE_PACKET_HEADER,
681 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE,
682 &notit->dscopes.trace_packet_header);
683 if (ret < 0) {
684 BT_LOGW("Cannot decode packet header field: "
685 "notit-addr=%p, trace-addr=%p, "
686 "trace-name=\"%s\", ft-addr=%p",
687 notit, notit->meta.trace,
688 bt_ctf_trace_get_name(notit->meta.trace),
689 packet_header_type);
690 }
691 end:
692 BT_PUT(packet_header_type);
693 return ret;
694 }
695
696 static
697 enum bt_ctf_notif_iter_status read_packet_header_continue_state(
698 struct bt_ctf_notif_iter *notit)
699 {
700 return read_dscope_continue_state(notit,
701 STATE_AFTER_TRACE_PACKET_HEADER);
702 }
703
704 static inline
705 bool is_struct_type(struct bt_ctf_field_type *field_type)
706 {
707 return bt_ctf_field_type_get_type_id(field_type) ==
708 BT_CTF_FIELD_TYPE_ID_STRUCT;
709 }
710
711 static inline
712 bool is_variant_type(struct bt_ctf_field_type *field_type)
713 {
714 return bt_ctf_field_type_get_type_id(field_type) ==
715 BT_CTF_FIELD_TYPE_ID_VARIANT;
716 }
717
718 static
719 struct stream_class_field_path_cache *
720 create_stream_class_field_path_cache_entry(
721 struct bt_ctf_notif_iter *notit,
722 struct bt_ctf_stream_class *stream_class)
723 {
724 int v = -1;
725 int id = -1;
726 int timestamp_end = -1;
727 int packet_size = -1;
728 int content_size = -1;
729 struct stream_class_field_path_cache *cache_entry = g_new0(
730 struct stream_class_field_path_cache, 1);
731 struct bt_ctf_field_type *event_header = NULL, *packet_context = NULL;
732
733 if (!cache_entry) {
734 BT_LOGE_STR("Failed to allocate one stream class field path cache.");
735 goto end;
736 }
737
738 event_header = bt_ctf_stream_class_get_event_header_type(stream_class);
739 if (event_header && bt_ctf_field_type_is_structure(event_header)) {
740 int i, count;
741
742 count = bt_ctf_field_type_structure_get_field_count(
743 event_header);
744 assert(count >= 0);
745
746 for (i = 0; i < count; i++) {
747 int ret;
748 const char *name;
749
750 ret = bt_ctf_field_type_structure_get_field(
751 event_header, &name, NULL, i);
752 if (ret) {
753 BT_LOGE("Cannot get event header structure field type's field: "
754 "notit-addr=%p, stream-class-addr=%p, "
755 "stream-class-name=\"%s\", "
756 "stream-class-id=%" PRId64 ", "
757 "ft-addr=%p, index=%d",
758 notit, stream_class,
759 bt_ctf_stream_class_get_name(stream_class),
760 bt_ctf_stream_class_get_id(stream_class),
761 event_header, i);
762 goto error;
763 }
764
765 if (v != -1 && id != -1) {
766 break;
767 }
768
769 if (v == -1 && strcmp(name, "v") == 0) {
770 v = i;
771 } else if (id == -1 && !strcmp(name, "id")) {
772 id = i;
773 }
774 }
775 }
776
777 packet_context = bt_ctf_stream_class_get_packet_context_type(
778 stream_class);
779 if (packet_context && bt_ctf_field_type_is_structure(packet_context)) {
780 int i, count;
781
782 count = bt_ctf_field_type_structure_get_field_count(
783 packet_context);
784 assert(count >= 0);
785
786 for (i = 0; i < count; i++) {
787 int ret;
788 const char *name;
789 struct bt_ctf_field_type *field_type;
790
791 if (timestamp_end != -1 && packet_size != -1 &&
792 content_size != -1) {
793 break;
794 }
795
796 ret = bt_ctf_field_type_structure_get_field(
797 packet_context, &name, &field_type, i);
798 if (ret) {
799 BT_LOGE("Cannot get packet context structure field type's field: "
800 "notit-addr=%p, stream-class-addr=%p, "
801 "stream-class-name=\"%s\", "
802 "stream-class-id=%" PRId64 ", "
803 "ft-addr=%p, index=%d",
804 notit, stream_class,
805 bt_ctf_stream_class_get_name(stream_class),
806 bt_ctf_stream_class_get_id(stream_class),
807 event_header, i);
808 goto error;
809 }
810
811 if (timestamp_end == -1 &&
812 strcmp(name, "timestamp_end") == 0) {
813 struct field_cb_override *override = g_new0(
814 struct field_cb_override, 1);
815
816 if (!override) {
817 BT_PUT(field_type);
818 goto error;
819 }
820
821 override->func = btr_timestamp_end_cb;
822 override->data = notit;
823 g_hash_table_insert(notit->field_overrides,
824 bt_get(field_type), override);
825 timestamp_end = i;
826 } else if (packet_size == -1 &&
827 !strcmp(name, "packet_size")) {
828 packet_size = i;
829 } else if (content_size == -1 &&
830 !strcmp(name, "content_size")) {
831 content_size = i;
832 }
833 BT_PUT(field_type);
834 }
835 }
836
837 cache_entry->v = v;
838 cache_entry->id = id;
839 cache_entry->timestamp_end = timestamp_end;
840 cache_entry->packet_size = packet_size;
841 cache_entry->content_size = content_size;
842 end:
843 BT_PUT(event_header);
844 BT_PUT(packet_context);
845 return cache_entry;
846 error:
847 g_free(cache_entry);
848 cache_entry = NULL;
849 goto end;
850 }
851
852 static
853 struct stream_class_field_path_cache *get_stream_class_field_path_cache(
854 struct bt_ctf_notif_iter *notit,
855 struct bt_ctf_stream_class *stream_class)
856 {
857 bool cache_entry_found;
858 struct stream_class_field_path_cache *cache_entry;
859
860 cache_entry_found = g_hash_table_lookup_extended(
861 notit->sc_field_path_caches,
862 stream_class, NULL, (gpointer) &cache_entry);
863 if (unlikely(!cache_entry_found)) {
864 cache_entry = create_stream_class_field_path_cache_entry(notit,
865 stream_class);
866 g_hash_table_insert(notit->sc_field_path_caches,
867 bt_get(stream_class), (gpointer) cache_entry);
868 }
869
870 return cache_entry;
871 }
872
873 static inline
874 enum bt_ctf_notif_iter_status set_current_stream_class(
875 struct bt_ctf_notif_iter *notit)
876 {
877 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
878 struct bt_ctf_field_type *packet_header_type = NULL;
879 struct bt_ctf_field_type *stream_id_field_type = NULL;
880 struct bt_ctf_stream_class *new_stream_class = NULL;
881 uint64_t stream_id;
882
883 /* Clear the current stream class field path cache. */
884 notit->cur_sc_field_path_cache = NULL;
885
886 /* Is there any "stream_id" field in the packet header? */
887 packet_header_type = bt_ctf_trace_get_packet_header_type(
888 notit->meta.trace);
889 if (!packet_header_type) {
890 /*
891 * No packet header, therefore no `stream_id` field,
892 * therefore only one stream class.
893 */
894 goto single_stream_class;
895 }
896
897 assert(is_struct_type(packet_header_type));
898
899 // TODO: optimalize!
900 stream_id_field_type =
901 bt_ctf_field_type_structure_get_field_type_by_name(
902 packet_header_type, "stream_id");
903 if (stream_id_field_type) {
904 /* Find appropriate stream class using current stream ID */
905 int ret;
906 struct bt_ctf_field *stream_id_field = NULL;
907
908 assert(notit->dscopes.trace_packet_header);
909
910 // TODO: optimalize!
911 stream_id_field = bt_ctf_field_structure_get_field(
912 notit->dscopes.trace_packet_header, "stream_id");
913 assert(stream_id_field);
914 ret = bt_ctf_field_unsigned_integer_get_value(
915 stream_id_field, &stream_id);
916 assert(!ret);
917 BT_PUT(stream_id_field);
918 } else {
919 single_stream_class:
920 /* Only one stream: pick the first stream class */
921 assert(bt_ctf_trace_get_stream_class_count(
922 notit->meta.trace) == 1);
923 stream_id = 0;
924 }
925
926 BT_LOGV("Found stream class ID to use: notit-addr=%p, "
927 "stream-class-id=%" PRIu64 ", "
928 "trace-addr=%p, trace-name=\"%s\"",
929 notit, stream_id, notit->meta.trace,
930 bt_ctf_trace_get_name(notit->meta.trace));
931
932 new_stream_class = bt_ctf_trace_get_stream_class_by_id(
933 notit->meta.trace, stream_id);
934 if (!new_stream_class) {
935 BT_LOGW("No stream class with ID of stream class ID to use in trace: "
936 "notit-addr=%p, stream-class-id=%" PRIu64 ", "
937 "trace-addr=%p, trace-name=\"%s\"",
938 notit, stream_id, notit->meta.trace,
939 bt_ctf_trace_get_name(notit->meta.trace));
940 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
941 goto end;
942 }
943
944 if (notit->meta.stream_class) {
945 if (new_stream_class != notit->meta.stream_class) {
946 BT_LOGW("Two packets refer to two different stream classes within the same packet sequence: "
947 "notit-addr=%p, prev-stream-class-addr=%p, "
948 "prev-stream-class-name=\"%s\", "
949 "prev-stream-class-id=%" PRId64 ", "
950 "next-stream-class-addr=%p, "
951 "next-stream-class-name=\"%s\", "
952 "next-stream-class-id=%" PRId64 ", "
953 "trace-addr=%p, trace-name=\"%s\"",
954 notit, notit->meta.stream_class,
955 bt_ctf_stream_class_get_name(notit->meta.stream_class),
956 bt_ctf_stream_class_get_id(notit->meta.stream_class),
957 new_stream_class,
958 bt_ctf_stream_class_get_name(new_stream_class),
959 bt_ctf_stream_class_get_id(new_stream_class),
960 notit->meta.trace,
961 bt_ctf_trace_get_name(notit->meta.trace));
962 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
963 goto end;
964 }
965 } else {
966 BT_MOVE(notit->meta.stream_class, new_stream_class);
967 }
968
969 BT_LOGV("Set current stream class: "
970 "notit-addr=%p, stream-class-addr=%p, "
971 "stream-class-name=\"%s\", stream-class-id=%" PRId64,
972 notit, notit->meta.stream_class,
973 bt_ctf_stream_class_get_name(notit->meta.stream_class),
974 bt_ctf_stream_class_get_id(notit->meta.stream_class));
975
976 /*
977 * Retrieve (or lazily create) the current stream class field path
978 * cache.
979 */
980 notit->cur_sc_field_path_cache = get_stream_class_field_path_cache(
981 notit, notit->meta.stream_class);
982 if (!notit->cur_sc_field_path_cache) {
983 BT_LOGW("Cannot retrieve stream class field path from cache: "
984 "notit-addr=%p, stream-class-addr=%p, "
985 "stream-class-name=\"%s\", stream-class-id=%" PRId64,
986 notit, notit->meta.stream_class,
987 bt_ctf_stream_class_get_name(notit->meta.stream_class),
988 bt_ctf_stream_class_get_id(notit->meta.stream_class));
989 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
990 goto end;
991 }
992 end:
993 BT_PUT(packet_header_type);
994 BT_PUT(stream_id_field_type);
995 bt_put(new_stream_class);
996 return status;
997 }
998
999 static
1000 enum bt_ctf_notif_iter_status after_packet_header_state(
1001 struct bt_ctf_notif_iter *notit)
1002 {
1003 enum bt_ctf_notif_iter_status status;
1004
1005 status = set_current_stream_class(notit);
1006 if (status == BT_CTF_NOTIF_ITER_STATUS_OK) {
1007 notit->state = STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN;
1008 }
1009
1010 return status;
1011 }
1012
1013 static
1014 enum bt_ctf_notif_iter_status read_packet_context_begin_state(
1015 struct bt_ctf_notif_iter *notit)
1016 {
1017 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1018 struct bt_ctf_field_type *packet_context_type;
1019
1020 assert(notit->meta.stream_class);
1021 packet_context_type = bt_ctf_stream_class_get_packet_context_type(
1022 notit->meta.stream_class);
1023 if (!packet_context_type) {
1024 BT_LOGV("No packet packet context field type in stream class: continuing: "
1025 "notit-addr=%p, stream-class-addr=%p, "
1026 "stream-class-name=\"%s\", stream-class-id=%" PRId64,
1027 notit, notit->meta.stream_class,
1028 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1029 bt_ctf_stream_class_get_id(notit->meta.stream_class));
1030 notit->state = STATE_AFTER_STREAM_PACKET_CONTEXT;
1031 goto end;
1032 }
1033
1034 BT_LOGV("Decoding packet context field: "
1035 "notit-addr=%p, stream-class-addr=%p, "
1036 "stream-class-name=\"%s\", stream-class-id=%" PRId64 ", "
1037 "ft-addr=%p",
1038 notit, notit->meta.stream_class,
1039 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1040 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1041 packet_context_type);
1042 status = read_dscope_begin_state(notit, packet_context_type,
1043 STATE_AFTER_STREAM_PACKET_CONTEXT,
1044 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
1045 &notit->dscopes.stream_packet_context);
1046 if (status < 0) {
1047 BT_LOGW("Cannot decode packet context field: "
1048 "notit-addr=%p, stream-class-addr=%p, "
1049 "stream-class-name=\"%s\", "
1050 "stream-class-id=%" PRId64 ", ft-addr=%p",
1051 notit, notit->meta.stream_class,
1052 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1053 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1054 packet_context_type);
1055 }
1056
1057 end:
1058 BT_PUT(packet_context_type);
1059 return status;
1060 }
1061
1062 static
1063 enum bt_ctf_notif_iter_status read_packet_context_continue_state(
1064 struct bt_ctf_notif_iter *notit)
1065 {
1066 return read_dscope_continue_state(notit,
1067 STATE_AFTER_STREAM_PACKET_CONTEXT);
1068 }
1069
1070 static
1071 enum bt_ctf_notif_iter_status set_current_packet_content_sizes(
1072 struct bt_ctf_notif_iter *notit)
1073 {
1074 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1075 struct bt_ctf_field *packet_size_field = NULL;
1076 struct bt_ctf_field *content_size_field = NULL;
1077 uint64_t content_size = -1, packet_size = -1;
1078
1079 if (!notit->dscopes.stream_packet_context) {
1080 goto end;
1081 }
1082
1083 packet_size_field = bt_ctf_field_structure_get_field(
1084 notit->dscopes.stream_packet_context, "packet_size");
1085 content_size_field = bt_ctf_field_structure_get_field(
1086 notit->dscopes.stream_packet_context, "content_size");
1087 if (packet_size_field) {
1088 int ret = bt_ctf_field_unsigned_integer_get_value(
1089 packet_size_field, &packet_size);
1090
1091 assert(ret == 0);
1092 if (packet_size == 0) {
1093 BT_LOGW("Invalid packet size: packet context field indicates packet size is zero: "
1094 "notit-addr=%p, packet-context-field-addr=%p",
1095 notit, notit->dscopes.stream_packet_context);
1096 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
1097 goto end;
1098 } else if ((packet_size % 8) != 0) {
1099 BT_LOGW("Invalid packet size: packet context field indicates packet size is not a multiple of 8: "
1100 "notit-addr=%p, packet-context-field-addr=%p, "
1101 "packet-size=%" PRIu64,
1102 notit, notit->dscopes.stream_packet_context,
1103 packet_size);
1104 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
1105 goto end;
1106 }
1107 }
1108
1109 if (content_size_field) {
1110 int ret = bt_ctf_field_unsigned_integer_get_value(
1111 content_size_field, &content_size);
1112
1113 assert(ret == 0);
1114 } else {
1115 content_size = packet_size;
1116 }
1117
1118 if (content_size > packet_size) {
1119 BT_LOGW("Invalid packet or content size: packet context field indicates content size is greater than packet size: "
1120 "notit-addr=%p, packet-context-field-addr=%p, "
1121 "packet-size=%" PRIu64 ", content-size=%" PRIu64,
1122 notit, notit->dscopes.stream_packet_context,
1123 packet_size, content_size);
1124 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
1125 goto end;
1126 }
1127
1128 notit->cur_packet_size = packet_size;
1129 notit->cur_content_size = content_size;
1130 BT_LOGV("Set current packet and content sizes: "
1131 "notit-addr=%p, packet-size=%" PRIu64 ", content-size=%" PRIu64,
1132 notit, packet_size, content_size);
1133 end:
1134 BT_PUT(packet_size_field);
1135 BT_PUT(content_size_field);
1136 return status;
1137 }
1138
1139 static
1140 enum bt_ctf_notif_iter_status after_packet_context_state(
1141 struct bt_ctf_notif_iter *notit)
1142 {
1143 enum bt_ctf_notif_iter_status status;
1144
1145 status = set_current_packet_content_sizes(notit);
1146 if (status == BT_CTF_NOTIF_ITER_STATUS_OK) {
1147 notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
1148 }
1149
1150 return status;
1151 }
1152
1153 static
1154 enum bt_ctf_notif_iter_status read_event_header_begin_state(
1155 struct bt_ctf_notif_iter *notit)
1156 {
1157 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1158 struct bt_ctf_field_type *event_header_type = NULL;
1159
1160 /* Check if we have some content left */
1161 if (notit->cur_content_size >= 0) {
1162 if (packet_at(notit) == notit->cur_content_size) {
1163 /* No more events! */
1164 BT_LOGV("Reached end of packet: notit-addr=%p, "
1165 "cur=%zu", notit, packet_at(notit));
1166 notit->state = STATE_EMIT_NOTIF_END_OF_PACKET;
1167 goto end;
1168 } else if (packet_at(notit) > notit->cur_content_size) {
1169 /* That's not supposed to happen */
1170 BT_LOGV("Before decoding event header field: cursor is passed the packet's content: "
1171 "notit-addr=%p, content-size=%zu, "
1172 "cur=%zu", notit, notit->cur_content_size,
1173 packet_at(notit));
1174 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
1175 goto end;
1176 }
1177 }
1178
1179 event_header_type = bt_ctf_stream_class_get_event_header_type(
1180 notit->meta.stream_class);
1181 if (!event_header_type) {
1182 notit->state = STATE_AFTER_STREAM_EVENT_HEADER;
1183 goto end;
1184 }
1185
1186 put_event_dscopes(notit);
1187 BT_LOGV("Decoding event header field: "
1188 "notit-addr=%p, stream-class-addr=%p, "
1189 "stream-class-name=\"%s\", stream-class-id=%" PRId64 ", "
1190 "ft-addr=%p",
1191 notit, notit->meta.stream_class,
1192 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1193 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1194 event_header_type);
1195 status = read_dscope_begin_state(notit, event_header_type,
1196 STATE_AFTER_STREAM_EVENT_HEADER,
1197 STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE,
1198 &notit->dscopes.stream_event_header);
1199 if (status < 0) {
1200 BT_LOGW("Cannot decode event header field: "
1201 "notit-addr=%p, stream-class-addr=%p, "
1202 "stream-class-name=\"%s\", "
1203 "stream-class-id=%" PRId64 ", ft-addr=%p",
1204 notit, notit->meta.stream_class,
1205 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1206 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1207 event_header_type);
1208 }
1209 end:
1210 BT_PUT(event_header_type);
1211
1212 return status;
1213 }
1214
1215 static
1216 enum bt_ctf_notif_iter_status read_event_header_continue_state(
1217 struct bt_ctf_notif_iter *notit)
1218 {
1219 return read_dscope_continue_state(notit,
1220 STATE_AFTER_STREAM_EVENT_HEADER);
1221 }
1222
1223 static inline
1224 enum bt_ctf_notif_iter_status set_current_event_class(struct bt_ctf_notif_iter *notit)
1225 {
1226 /*
1227 * The assert() calls in this function are okay because it is
1228 * assumed here that all the metadata objects have been
1229 * validated for CTF correctness before decoding actual streams.
1230 */
1231
1232 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1233 struct bt_ctf_field_type *event_header_type;
1234 struct bt_ctf_field_type *id_field_type = NULL;
1235 struct bt_ctf_field_type *v_field_type = NULL;
1236 uint64_t event_id = -1ULL;
1237 int ret;
1238
1239 event_header_type = bt_ctf_stream_class_get_event_header_type(
1240 notit->meta.stream_class);
1241 if (!event_header_type) {
1242 /*
1243 * No event header, therefore no event class ID field,
1244 * therefore only one event class.
1245 */
1246 goto single_event_class;
1247 }
1248
1249 /* Is there any "id"/"v" field in the event header? */
1250 assert(is_struct_type(event_header_type));
1251 id_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
1252 event_header_type, "id");
1253 v_field_type = bt_ctf_field_type_structure_get_field_type_by_name(
1254 event_header_type, "v");
1255 assert(notit->dscopes.stream_event_header);
1256 if (v_field_type) {
1257 /*
1258 * _ _____ _____
1259 * | | |_ _|_ _| __ __ _
1260 * | | | | | || '_ \ / _` |
1261 * | |___| | | || | | | (_| | S P E C I A L
1262 * |_____|_| |_||_| |_|\__, | C A S E â„¢
1263 * |___/
1264 */
1265 struct bt_ctf_field *v_field = NULL;
1266 struct bt_ctf_field *v_struct_field = NULL;
1267 struct bt_ctf_field *v_struct_id_field = NULL;
1268
1269 // TODO: optimalize!
1270 v_field = bt_ctf_field_structure_get_field(
1271 notit->dscopes.stream_event_header, "v");
1272 assert(v_field);
1273
1274 v_struct_field =
1275 bt_ctf_field_variant_get_current_field(v_field);
1276 if (!v_struct_field) {
1277 goto end_v_field_type;
1278 }
1279
1280 // TODO: optimalize!
1281 v_struct_id_field =
1282 bt_ctf_field_structure_get_field(v_struct_field, "id");
1283 if (!v_struct_id_field) {
1284 goto end_v_field_type;
1285 }
1286
1287 if (bt_ctf_field_is_integer(v_struct_id_field)) {
1288 ret = bt_ctf_field_unsigned_integer_get_value(
1289 v_struct_id_field, &event_id);
1290 if (ret) {
1291 BT_LOGV("Cannot get value of unsigned integer field (`id`): continuing: "
1292 "notit=%p, field-addr=%p",
1293 notit, v_struct_id_field);
1294 event_id = -1ULL;
1295 }
1296 }
1297
1298 end_v_field_type:
1299 BT_PUT(v_field);
1300 BT_PUT(v_struct_field);
1301 BT_PUT(v_struct_id_field);
1302 }
1303
1304 if (id_field_type && event_id == -1ULL) {
1305 /* Check "id" field */
1306 struct bt_ctf_field *id_field = NULL;
1307 int ret = 0;
1308
1309 // TODO: optimalize!
1310 id_field = bt_ctf_field_structure_get_field(
1311 notit->dscopes.stream_event_header, "id");
1312 if (!id_field) {
1313 goto check_event_id;
1314 }
1315
1316 if (bt_ctf_field_is_integer(id_field)) {
1317 ret = bt_ctf_field_unsigned_integer_get_value(
1318 id_field, &event_id);
1319 } else if (bt_ctf_field_is_enumeration(id_field)) {
1320 struct bt_ctf_field *container;
1321
1322 container = bt_ctf_field_enumeration_get_container(
1323 id_field);
1324 assert(container);
1325 ret = bt_ctf_field_unsigned_integer_get_value(
1326 container, &event_id);
1327 BT_PUT(container);
1328 }
1329
1330 assert(ret == 0);
1331 BT_PUT(id_field);
1332 }
1333
1334 check_event_id:
1335 if (event_id == -1ULL) {
1336 single_event_class:
1337 /* Event ID not found: single event? */
1338 assert(bt_ctf_stream_class_get_event_class_count(
1339 notit->meta.stream_class) == 1);
1340 event_id = 0;
1341 }
1342
1343 BT_LOGV("Found event class ID to use: notit-addr=%p, "
1344 "stream-class-addr=%p, stream-class-name=\"%s\", "
1345 "stream-class-id=%" PRId64 ", "
1346 "event-class-id=%" PRIu64,
1347 notit, notit->meta.stream_class,
1348 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1349 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1350 event_id);
1351 BT_PUT(notit->meta.event_class);
1352 notit->meta.event_class = bt_ctf_stream_class_get_event_class_by_id(
1353 notit->meta.stream_class, event_id);
1354 if (!notit->meta.event_class) {
1355 BT_LOGW("No event class with ID of event class ID to use in stream class: "
1356 "notit-addr=%p, stream-class-addr=%p, "
1357 "stream-class-name=\"%s\", "
1358 "stream-class-id=%" PRId64 ", "
1359 "event-class-id=%" PRIu64,
1360 notit, notit->meta.stream_class,
1361 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1362 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1363 event_id);
1364 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
1365 goto end;
1366 }
1367
1368 BT_LOGV("Set current event class: "
1369 "notit-addr=%p, event-class-addr=%p, "
1370 "event-class-name=\"%s\", event-class-id=%" PRId64,
1371 notit, notit->meta.event_class,
1372 bt_ctf_event_class_get_name(notit->meta.event_class),
1373 bt_ctf_event_class_get_id(notit->meta.event_class));
1374
1375 end:
1376 BT_PUT(event_header_type);
1377 BT_PUT(id_field_type);
1378 BT_PUT(v_field_type);
1379
1380 return status;
1381 }
1382
1383 static
1384 enum bt_ctf_notif_iter_status after_event_header_state(
1385 struct bt_ctf_notif_iter *notit)
1386 {
1387 enum bt_ctf_notif_iter_status status;
1388
1389 status = set_current_event_class(notit);
1390 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
1391 goto end;
1392 }
1393
1394 notit->state = STATE_DSCOPE_STREAM_EVENT_CONTEXT_BEGIN;
1395
1396 end:
1397 return status;
1398 }
1399
1400 static
1401 enum bt_ctf_notif_iter_status read_stream_event_context_begin_state(
1402 struct bt_ctf_notif_iter *notit)
1403 {
1404 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1405 struct bt_ctf_field_type *stream_event_context_type;
1406
1407 stream_event_context_type = bt_ctf_stream_class_get_event_context_type(
1408 notit->meta.stream_class);
1409 if (!stream_event_context_type) {
1410 notit->state = STATE_DSCOPE_EVENT_CONTEXT_BEGIN;
1411 goto end;
1412 }
1413
1414 BT_LOGV("Decoding stream event context field: "
1415 "notit-addr=%p, stream-class-addr=%p, "
1416 "stream-class-name=\"%s\", stream-class-id=%" PRId64 ", "
1417 "ft-addr=%p",
1418 notit, notit->meta.stream_class,
1419 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1420 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1421 stream_event_context_type);
1422 status = read_dscope_begin_state(notit, stream_event_context_type,
1423 STATE_DSCOPE_EVENT_CONTEXT_BEGIN,
1424 STATE_DSCOPE_STREAM_EVENT_CONTEXT_CONTINUE,
1425 &notit->dscopes.stream_event_context);
1426 if (status < 0) {
1427 BT_LOGW("Cannot decode stream event context field: "
1428 "notit-addr=%p, stream-class-addr=%p, "
1429 "stream-class-name=\"%s\", "
1430 "stream-class-id=%" PRId64 ", ft-addr=%p",
1431 notit, notit->meta.stream_class,
1432 bt_ctf_stream_class_get_name(notit->meta.stream_class),
1433 bt_ctf_stream_class_get_id(notit->meta.stream_class),
1434 stream_event_context_type);
1435 }
1436
1437 end:
1438 BT_PUT(stream_event_context_type);
1439
1440 return status;
1441 }
1442
1443 static
1444 enum bt_ctf_notif_iter_status read_stream_event_context_continue_state(
1445 struct bt_ctf_notif_iter *notit)
1446 {
1447 return read_dscope_continue_state(notit,
1448 STATE_DSCOPE_EVENT_CONTEXT_BEGIN);
1449 }
1450
1451 static
1452 enum bt_ctf_notif_iter_status read_event_context_begin_state(
1453 struct bt_ctf_notif_iter *notit)
1454 {
1455 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1456 struct bt_ctf_field_type *event_context_type;
1457
1458 event_context_type = bt_ctf_event_class_get_context_type(
1459 notit->meta.event_class);
1460 if (!event_context_type) {
1461 notit->state = STATE_DSCOPE_EVENT_PAYLOAD_BEGIN;
1462 goto end;
1463 }
1464
1465 BT_LOGV("Decoding event context field: "
1466 "notit-addr=%p, event-class-addr=%p, "
1467 "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
1468 "ft-addr=%p",
1469 notit, notit->meta.event_class,
1470 bt_ctf_event_class_get_name(notit->meta.event_class),
1471 bt_ctf_event_class_get_id(notit->meta.event_class),
1472 event_context_type);
1473 status = read_dscope_begin_state(notit, event_context_type,
1474 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN,
1475 STATE_DSCOPE_EVENT_CONTEXT_CONTINUE,
1476 &notit->dscopes.event_context);
1477 if (status < 0) {
1478 BT_LOGW("Cannot decode event context field: "
1479 "notit-addr=%p, event-class-addr=%p, "
1480 "event-class-name=\"%s\", "
1481 "event-class-id=%" PRId64 ", ft-addr=%p",
1482 notit, notit->meta.event_class,
1483 bt_ctf_event_class_get_name(notit->meta.event_class),
1484 bt_ctf_event_class_get_id(notit->meta.event_class),
1485 event_context_type);
1486 }
1487
1488 end:
1489 BT_PUT(event_context_type);
1490
1491 return status;
1492 }
1493
1494 static
1495 enum bt_ctf_notif_iter_status read_event_context_continue_state(
1496 struct bt_ctf_notif_iter *notit)
1497 {
1498 return read_dscope_continue_state(notit,
1499 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN);
1500 }
1501
1502 static
1503 enum bt_ctf_notif_iter_status read_event_payload_begin_state(
1504 struct bt_ctf_notif_iter *notit)
1505 {
1506 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1507 struct bt_ctf_field_type *event_payload_type;
1508
1509 event_payload_type = bt_ctf_event_class_get_payload_type(
1510 notit->meta.event_class);
1511 if (!event_payload_type) {
1512 notit->state = STATE_EMIT_NOTIF_EVENT;
1513 goto end;
1514 }
1515
1516 BT_LOGV("Decoding event payload field: "
1517 "notit-addr=%p, event-class-addr=%p, "
1518 "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
1519 "ft-addr=%p",
1520 notit, notit->meta.event_class,
1521 bt_ctf_event_class_get_name(notit->meta.event_class),
1522 bt_ctf_event_class_get_id(notit->meta.event_class),
1523 event_payload_type);
1524 status = read_dscope_begin_state(notit, event_payload_type,
1525 STATE_EMIT_NOTIF_EVENT,
1526 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
1527 &notit->dscopes.event_payload);
1528 if (status < 0) {
1529 BT_LOGW("Cannot decode event payload field: "
1530 "notit-addr=%p, event-class-addr=%p, "
1531 "event-class-name=\"%s\", "
1532 "event-class-id=%" PRId64 ", ft-addr=%p",
1533 notit, notit->meta.event_class,
1534 bt_ctf_event_class_get_name(notit->meta.event_class),
1535 bt_ctf_event_class_get_id(notit->meta.event_class),
1536 event_payload_type);
1537 }
1538
1539 end:
1540 BT_PUT(event_payload_type);
1541
1542 return status;
1543 }
1544
1545 static
1546 enum bt_ctf_notif_iter_status read_event_payload_continue_state(
1547 struct bt_ctf_notif_iter *notit)
1548 {
1549 return read_dscope_continue_state(notit, STATE_EMIT_NOTIF_EVENT);
1550 }
1551
1552 static
1553 enum bt_ctf_notif_iter_status skip_packet_padding_state(
1554 struct bt_ctf_notif_iter *notit)
1555 {
1556 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1557 size_t bits_to_skip;
1558
1559 assert(notit->cur_packet_size > 0);
1560 bits_to_skip = notit->cur_packet_size - packet_at(notit);
1561 if (bits_to_skip == 0) {
1562 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1563 goto end;
1564 } else {
1565 size_t bits_to_consume;
1566
1567 BT_LOGV("Trying to skip %zu bits of padding: notit-addr=%p, size=%zu",
1568 bits_to_skip, notit, bits_to_skip);
1569 status = buf_ensure_available_bits(notit);
1570 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
1571 goto end;
1572 }
1573
1574 bits_to_consume = MIN(buf_available_bits(notit), bits_to_skip);
1575 BT_LOGV("Skipping %zu bits of padding: notit-addr=%p, size=%zu",
1576 bits_to_consume, notit, bits_to_consume);
1577 buf_consume_bits(notit, bits_to_consume);
1578 bits_to_skip = notit->cur_packet_size - packet_at(notit);
1579 if (bits_to_skip == 0) {
1580 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1581 goto end;
1582 }
1583 }
1584
1585 end:
1586 return status;
1587 }
1588
1589 static inline
1590 enum bt_ctf_notif_iter_status handle_state(struct bt_ctf_notif_iter *notit)
1591 {
1592 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
1593 const enum state state = notit->state;
1594
1595 BT_LOGV("Handling state: notit-addr=%p, state=%s",
1596 notit, state_string(state));
1597
1598 // TODO: optimalize!
1599 switch (state) {
1600 case STATE_INIT:
1601 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1602 break;
1603 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
1604 status = read_packet_header_begin_state(notit);
1605 break;
1606 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
1607 status = read_packet_header_continue_state(notit);
1608 break;
1609 case STATE_AFTER_TRACE_PACKET_HEADER:
1610 status = after_packet_header_state(notit);
1611 break;
1612 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
1613 status = read_packet_context_begin_state(notit);
1614 break;
1615 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
1616 status = read_packet_context_continue_state(notit);
1617 break;
1618 case STATE_AFTER_STREAM_PACKET_CONTEXT:
1619 status = after_packet_context_state(notit);
1620 break;
1621 case STATE_EMIT_NOTIF_NEW_PACKET:
1622 notit->state = STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN;
1623 break;
1624 case STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN:
1625 status = read_event_header_begin_state(notit);
1626 break;
1627 case STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE:
1628 status = read_event_header_continue_state(notit);
1629 break;
1630 case STATE_AFTER_STREAM_EVENT_HEADER:
1631 status = after_event_header_state(notit);
1632 break;
1633 case STATE_DSCOPE_STREAM_EVENT_CONTEXT_BEGIN:
1634 status = read_stream_event_context_begin_state(notit);
1635 break;
1636 case STATE_DSCOPE_STREAM_EVENT_CONTEXT_CONTINUE:
1637 status = read_stream_event_context_continue_state(notit);
1638 break;
1639 case STATE_DSCOPE_EVENT_CONTEXT_BEGIN:
1640 status = read_event_context_begin_state(notit);
1641 break;
1642 case STATE_DSCOPE_EVENT_CONTEXT_CONTINUE:
1643 status = read_event_context_continue_state(notit);
1644 break;
1645 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN:
1646 status = read_event_payload_begin_state(notit);
1647 break;
1648 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE:
1649 status = read_event_payload_continue_state(notit);
1650 break;
1651 case STATE_EMIT_NOTIF_EVENT:
1652 notit->state = STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN;
1653 break;
1654 case STATE_SKIP_PACKET_PADDING:
1655 status = skip_packet_padding_state(notit);
1656 break;
1657 case STATE_EMIT_NOTIF_END_OF_PACKET:
1658 notit->state = STATE_SKIP_PACKET_PADDING;
1659 break;
1660 default:
1661 BT_LOGD("Unknown CTF plugin notification iterator state: "
1662 "notit-addr=%p, state=%d", notit, notit->state);
1663 abort();
1664 }
1665
1666 BT_LOGV("Handled state: notit-addr=%p, status=%s, "
1667 "prev-state=%s, cur-state=%s",
1668 notit, bt_ctf_notif_iter_status_string(status),
1669 state_string(state), state_string(notit->state));
1670 return status;
1671 }
1672
1673 /**
1674 * Resets the internal state of a CTF notification iterator.
1675 */
1676 static
1677 void bt_ctf_notif_iter_reset(struct bt_ctf_notif_iter *notit)
1678 {
1679 assert(notit);
1680 BT_LOGD("Resetting notification iterator: addr=%p", notit);
1681 stack_clear(notit->stack);
1682 BT_PUT(notit->meta.stream_class);
1683 BT_PUT(notit->meta.event_class);
1684 BT_PUT(notit->packet);
1685 BT_PUT(notit->stream);
1686 put_all_dscopes(notit);
1687 notit->buf.addr = NULL;
1688 notit->buf.sz = 0;
1689 notit->buf.at = 0;
1690 notit->buf.packet_offset = 0;
1691 notit->state = STATE_INIT;
1692 notit->cur_content_size = -1;
1693 notit->cur_packet_size = -1;
1694 }
1695
1696 static
1697 int bt_ctf_notif_iter_switch_packet(struct bt_ctf_notif_iter *notit)
1698 {
1699 int ret = 0;
1700
1701 /*
1702 * We don't put the stream class here because we need to make
1703 * sure that all the packets processed by the same notification
1704 * iterator refer to the same stream class (the first one).
1705 */
1706 assert(notit);
1707 BT_LOGV("Switching packet: notit-addr=%p, cur=%zu",
1708 notit, notit->buf.at);
1709 stack_clear(notit->stack);
1710 BT_PUT(notit->meta.event_class);
1711 BT_PUT(notit->packet);
1712 BT_PUT(notit->cur_timestamp_end);
1713 put_all_dscopes(notit);
1714
1715 /*
1716 * Adjust current buffer so that addr points to the beginning of the new
1717 * packet.
1718 */
1719 if (notit->buf.addr) {
1720 size_t consumed_bytes = (size_t) (notit->buf.at / CHAR_BIT);
1721
1722 /* Packets are assumed to start on a byte frontier. */
1723 if (notit->buf.at % CHAR_BIT) {
1724 BT_LOGW("Cannot switch packet: current position is not a multiple of 8: "
1725 "notit-addr=%p, cur=%zu", notit, notit->buf.at);
1726 ret = -1;
1727 goto end;
1728 }
1729
1730 notit->buf.addr += consumed_bytes;
1731 notit->buf.sz -= consumed_bytes;
1732 notit->buf.at = 0;
1733 notit->buf.packet_offset = 0;
1734 BT_LOGV("Adjusted buffer: addr=%p, size=%zu",
1735 notit->buf.addr, notit->buf.sz);
1736 }
1737
1738 notit->cur_content_size = -1;
1739 notit->cur_packet_size = -1;
1740 notit->cur_sc_field_path_cache = NULL;
1741
1742 end:
1743 return ret;
1744 }
1745
1746 static
1747 struct bt_ctf_field *get_next_field(struct bt_ctf_notif_iter *notit)
1748 {
1749 struct bt_ctf_field *next_field = NULL;
1750 struct bt_ctf_field *base_field;
1751 struct bt_ctf_field_type *base_type;
1752 size_t index;
1753
1754 assert(!stack_empty(notit->stack));
1755 index = stack_top(notit->stack)->index;
1756 base_field = stack_top(notit->stack)->base;
1757 assert(base_field);
1758 base_type = bt_ctf_field_get_type(base_field);
1759 assert(base_type);
1760
1761 switch (bt_ctf_field_type_get_type_id(base_type)) {
1762 case BT_CTF_FIELD_TYPE_ID_STRUCT:
1763 next_field = bt_ctf_field_structure_get_field_by_index(
1764 base_field, index);
1765 break;
1766 case BT_CTF_FIELD_TYPE_ID_ARRAY:
1767 next_field = bt_ctf_field_array_get_field(base_field, index);
1768 break;
1769 case BT_CTF_FIELD_TYPE_ID_SEQUENCE:
1770 next_field = bt_ctf_field_sequence_get_field(base_field, index);
1771 break;
1772 case BT_CTF_FIELD_TYPE_ID_VARIANT:
1773 next_field = bt_ctf_field_variant_get_current_field(base_field);
1774 break;
1775 default:
1776 BT_LOGF("Unknown base field type ID: "
1777 "notit-addr=%p, ft-addr=%p, ft-id=%s",
1778 notit, base_type,
1779 bt_ctf_field_type_id_string(
1780 bt_ctf_field_type_get_type_id(base_type)));
1781 abort();
1782 }
1783
1784 BT_PUT(base_type);
1785 return next_field;
1786 }
1787
1788 static
1789 void update_clock_state(uint64_t *state,
1790 struct bt_ctf_field *value_field)
1791 {
1792 struct bt_ctf_field_type *value_type = NULL;
1793 uint64_t requested_new_value;
1794 uint64_t requested_new_value_mask;
1795 uint64_t cur_value_masked;
1796 int requested_new_value_size;
1797 int ret;
1798
1799 value_type = bt_ctf_field_get_type(value_field);
1800 assert(value_type);
1801 assert(bt_ctf_field_type_is_integer(value_type));
1802 requested_new_value_size =
1803 bt_ctf_field_type_integer_get_size(value_type);
1804 assert(requested_new_value_size > 0);
1805 ret = bt_ctf_field_unsigned_integer_get_value(value_field,
1806 &requested_new_value);
1807 assert(!ret);
1808
1809 /*
1810 * Special case for a 64-bit new value, which is the limit
1811 * of a clock value as of this version: overwrite the
1812 * current value directly.
1813 */
1814 if (requested_new_value_size == 64) {
1815 *state = requested_new_value;
1816 goto end;
1817 }
1818
1819 requested_new_value_mask = (1ULL << requested_new_value_size) - 1;
1820 cur_value_masked = *state & requested_new_value_mask;
1821
1822 if (requested_new_value < cur_value_masked) {
1823 /*
1824 * It looks like a wrap happened on the number of bits
1825 * of the requested new value. Assume that the clock
1826 * value wrapped only one time.
1827 */
1828 *state += requested_new_value_mask + 1;
1829 }
1830
1831 /* Clear the low bits of the current clock value. */
1832 *state &= ~requested_new_value_mask;
1833
1834 /* Set the low bits of the current clock value. */
1835 *state |= requested_new_value;
1836 end:
1837 BT_LOGV("Updated clock's value from integer field's value: "
1838 "value=%" PRIu64, *state);
1839 bt_put(value_type);
1840 }
1841
1842 static
1843 enum bt_ctf_btr_status update_clock(struct bt_ctf_notif_iter *notit,
1844 struct bt_ctf_field *int_field)
1845 {
1846 gboolean clock_class_found;
1847 uint64_t *clock_state = NULL;
1848 struct bt_ctf_field_type *int_field_type = NULL;
1849 enum bt_ctf_btr_status ret = BT_CTF_BTR_STATUS_OK;
1850 struct bt_ctf_clock_class *clock_class = NULL;
1851
1852 int_field_type = bt_ctf_field_get_type(int_field);
1853 assert(int_field_type);
1854 clock_class = bt_ctf_field_type_integer_get_mapped_clock_class(
1855 int_field_type);
1856 if (likely(!clock_class)) {
1857 goto end;
1858 }
1859
1860 clock_class_found = g_hash_table_lookup_extended(notit->clock_states,
1861 clock_class, NULL, (gpointer) &clock_state);
1862 if (!clock_class_found) {
1863 clock_state = g_new0(uint64_t, 1);
1864 if (!clock_state) {
1865 BT_LOGE_STR("Failed to allocate a uint64_t.");
1866 ret = BT_CTF_BTR_STATUS_ENOMEM;
1867 goto end;
1868 }
1869
1870 g_hash_table_insert(notit->clock_states, bt_get(clock_class),
1871 clock_state);
1872 }
1873
1874 /* Update the clock's state. */
1875 BT_LOGV("Updating notification iterator's clock's value from integer field: "
1876 "notit-addr=%p, clock-class-addr=%p, "
1877 "clock-class-name=\"%s\", value=%" PRIu64,
1878 notit, clock_class,
1879 bt_ctf_clock_class_get_name(clock_class), *clock_state);
1880 update_clock_state(clock_state, int_field);
1881 end:
1882 bt_put(int_field_type);
1883 bt_put(clock_class);
1884 return ret;
1885 }
1886
1887 static
1888 enum bt_ctf_btr_status btr_unsigned_int_common(uint64_t value,
1889 struct bt_ctf_field_type *type, void *data,
1890 struct bt_ctf_field **out_int_field)
1891 {
1892 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
1893 struct bt_ctf_field *field = NULL;
1894 struct bt_ctf_field *int_field = NULL;
1895 struct bt_ctf_notif_iter *notit = data;
1896 int ret;
1897
1898 BT_LOGV("Common unsigned integer function called from BTR: "
1899 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
1900 "ft-id=%s, value=%" PRIu64,
1901 notit, notit->btr, type,
1902 bt_ctf_field_type_id_string(
1903 bt_ctf_field_type_get_type_id(type)),
1904 value);
1905
1906 /* Create next field */
1907 field = get_next_field(notit);
1908 if (!field) {
1909 BT_LOGW("Cannot get next field: notit-addr=%p", notit);
1910 status = BT_CTF_BTR_STATUS_ERROR;
1911 goto end_no_put;
1912 }
1913
1914 switch(bt_ctf_field_type_get_type_id(type)) {
1915 case BT_CTF_FIELD_TYPE_ID_INTEGER:
1916 /* Integer field is created field */
1917 BT_MOVE(int_field, field);
1918 bt_get(type);
1919 break;
1920 case BT_CTF_FIELD_TYPE_ID_ENUM:
1921 int_field = bt_ctf_field_enumeration_get_container(field);
1922 assert(int_field);
1923 type = bt_ctf_field_get_type(int_field);
1924 assert(type);
1925 break;
1926 default:
1927 BT_LOGF("Unexpected field type ID: "
1928 "notit-addr=%p, ft-addr=%p, ft-id=%s",
1929 notit, type,
1930 bt_ctf_field_type_id_string(
1931 bt_ctf_field_type_get_type_id(type)));
1932 abort();
1933 }
1934
1935 assert(int_field);
1936 ret = bt_ctf_field_unsigned_integer_set_value(int_field, value);
1937 assert(ret == 0);
1938 stack_top(notit->stack)->index++;
1939 *out_int_field = int_field;
1940 BT_PUT(field);
1941 BT_PUT(type);
1942
1943 end_no_put:
1944 return status;
1945 }
1946
1947 static
1948 enum bt_ctf_btr_status btr_timestamp_end_cb(void *value,
1949 struct bt_ctf_field_type *type, void *data)
1950 {
1951 enum bt_ctf_btr_status status;
1952 struct bt_ctf_field *field = NULL;
1953 struct bt_ctf_notif_iter *notit = data;
1954
1955 BT_LOGV("`timestamp_end` unsigned integer function called from BTR: "
1956 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
1957 "ft-id=%s",
1958 notit, notit->btr, type,
1959 bt_ctf_field_type_id_string(
1960 bt_ctf_field_type_get_type_id(type)));
1961 status = btr_unsigned_int_common(*((uint64_t *) value), type, data,
1962 &field);
1963
1964 /* Set as the current packet's timestamp_end field. */
1965 BT_MOVE(notit->cur_timestamp_end, field);
1966 return status;
1967 }
1968
1969 static
1970 enum bt_ctf_btr_status btr_unsigned_int_cb(uint64_t value,
1971 struct bt_ctf_field_type *type, void *data)
1972 {
1973 struct bt_ctf_notif_iter *notit = data;
1974 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
1975 struct bt_ctf_field *field = NULL;
1976 struct field_cb_override *override;
1977
1978 BT_LOGV("Unsigned integer function called from BTR: "
1979 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
1980 "ft-id=%s, value=%" PRIu64,
1981 notit, notit->btr, type,
1982 bt_ctf_field_type_id_string(
1983 bt_ctf_field_type_get_type_id(type)),
1984 value);
1985 override = g_hash_table_lookup(notit->field_overrides, type);
1986 if (unlikely(override)) {
1987 /* Override function logs errors */
1988 status = override->func(&value, type, override->data);
1989 goto end;
1990 }
1991
1992 status = btr_unsigned_int_common(value, type, data, &field);
1993 if (status != BT_CTF_BTR_STATUS_OK) {
1994 /* btr_unsigned_int_common() logs errors */
1995 goto end;
1996 }
1997
1998 status = update_clock(notit, field);
1999 BT_PUT(field);
2000 end:
2001 return status;
2002 }
2003
2004 static
2005 enum bt_ctf_btr_status btr_signed_int_cb(int64_t value,
2006 struct bt_ctf_field_type *type, void *data)
2007 {
2008 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
2009 struct bt_ctf_field *field = NULL;
2010 struct bt_ctf_field *int_field = NULL;
2011 struct bt_ctf_notif_iter *notit = data;
2012 int ret;
2013
2014 BT_LOGV("Signed integer function called from BTR: "
2015 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2016 "ft-id=%s, value=%" PRId64,
2017 notit, notit->btr, type,
2018 bt_ctf_field_type_id_string(
2019 bt_ctf_field_type_get_type_id(type)),
2020 value);
2021
2022 /* create next field */
2023 field = get_next_field(notit);
2024 if (!field) {
2025 BT_LOGW("Cannot get next field: notit-addr=%p", notit);
2026 status = BT_CTF_BTR_STATUS_ERROR;
2027 goto end_no_put;
2028 }
2029
2030 switch(bt_ctf_field_type_get_type_id(type)) {
2031 case BT_CTF_FIELD_TYPE_ID_INTEGER:
2032 /* Integer field is created field */
2033 BT_MOVE(int_field, field);
2034 bt_get(type);
2035 break;
2036 case BT_CTF_FIELD_TYPE_ID_ENUM:
2037 int_field = bt_ctf_field_enumeration_get_container(field);
2038 assert(int_field);
2039 type = bt_ctf_field_get_type(int_field);
2040 assert(type);
2041 break;
2042 default:
2043 BT_LOGF("Unexpected field type ID: "
2044 "notit-addr=%p, ft-addr=%p, ft-id=%s",
2045 notit, type,
2046 bt_ctf_field_type_id_string(
2047 bt_ctf_field_type_get_type_id(type)));
2048 abort();
2049 }
2050
2051 assert(int_field);
2052 ret = bt_ctf_field_signed_integer_set_value(int_field, value);
2053 assert(!ret);
2054 stack_top(notit->stack)->index++;
2055 status = update_clock(notit, int_field);
2056 BT_PUT(field);
2057 BT_PUT(int_field);
2058 BT_PUT(type);
2059
2060 end_no_put:
2061 return status;
2062 }
2063
2064 static
2065 enum bt_ctf_btr_status btr_floating_point_cb(double value,
2066 struct bt_ctf_field_type *type, void *data)
2067 {
2068 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
2069 struct bt_ctf_field *field = NULL;
2070 struct bt_ctf_notif_iter *notit = data;
2071 int ret;
2072
2073 BT_LOGV("Floating point number function called from BTR: "
2074 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2075 "ft-id=%s, value=%f",
2076 notit, notit->btr, type,
2077 bt_ctf_field_type_id_string(
2078 bt_ctf_field_type_get_type_id(type)),
2079 value);
2080
2081 /* Create next field */
2082 field = get_next_field(notit);
2083 if (!field) {
2084 BT_LOGW("Cannot get next field: notit-addr=%p", notit);
2085 status = BT_CTF_BTR_STATUS_ERROR;
2086 goto end;
2087 }
2088
2089 ret = bt_ctf_field_floating_point_set_value(field, value);
2090 assert(!ret);
2091 stack_top(notit->stack)->index++;
2092
2093 end:
2094 BT_PUT(field);
2095 return status;
2096 }
2097
2098 static
2099 enum bt_ctf_btr_status btr_string_begin_cb(
2100 struct bt_ctf_field_type *type, void *data)
2101 {
2102 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
2103 struct bt_ctf_field *field = NULL;
2104 struct bt_ctf_notif_iter *notit = data;
2105 int ret;
2106
2107 BT_LOGV("String (beginning) function called from BTR: "
2108 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2109 "ft-id=%s",
2110 notit, notit->btr, type,
2111 bt_ctf_field_type_id_string(
2112 bt_ctf_field_type_get_type_id(type)));
2113
2114 /* Create next field */
2115 field = get_next_field(notit);
2116 if (!field) {
2117 BT_LOGW("Cannot get next field: notit-addr=%p", notit);
2118 status = BT_CTF_BTR_STATUS_ERROR;
2119 goto end;
2120 }
2121
2122 /*
2123 * Push on stack. Not a compound type per se, but we know that only
2124 * btr_string_cb() may be called between this call and a subsequent
2125 * call to btr_string_end_cb().
2126 */
2127 ret = stack_push(notit->stack, field);
2128 if (ret) {
2129 BT_LOGE("Cannot push string field on stack: "
2130 "notit-addr=%p, field-addr=%p", notit, field);
2131 status = BT_CTF_BTR_STATUS_ERROR;
2132 goto end;
2133 }
2134
2135 /*
2136 * Initialize string field payload to an empty string since in the
2137 * case of a length 0 string the btr_string_cb won't be called and
2138 * we will end up with an unset string payload.
2139 */
2140 ret = bt_ctf_field_string_set_value(field, "");
2141 if (ret) {
2142 BT_LOGE("Cannot initialize string field's value to an empty string: "
2143 "notit-addr=%p, field-addr=%p, ret=%d",
2144 notit, field, ret);
2145 status = BT_CTF_BTR_STATUS_ERROR;
2146 goto end;
2147 }
2148
2149 end:
2150 BT_PUT(field);
2151
2152 return status;
2153 }
2154
2155 static
2156 enum bt_ctf_btr_status btr_string_cb(const char *value,
2157 size_t len, struct bt_ctf_field_type *type, void *data)
2158 {
2159 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
2160 struct bt_ctf_field *field = NULL;
2161 struct bt_ctf_notif_iter *notit = data;
2162 int ret;
2163
2164 BT_LOGV("String (substring) function called from BTR: "
2165 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2166 "ft-id=%s, string-length=%zu",
2167 notit, notit->btr, type,
2168 bt_ctf_field_type_id_string(
2169 bt_ctf_field_type_get_type_id(type)),
2170 len);
2171
2172 /* Get string field */
2173 field = stack_top(notit->stack)->base;
2174 assert(field);
2175
2176 /* Append current string */
2177 ret = bt_ctf_field_string_append_len(field, value, len);
2178 if (ret) {
2179 BT_LOGE("Cannot append substring to string field's value: "
2180 "notit-addr=%p, field-addr=%p, string-length=%zu, "
2181 "ret=%d", notit, field, len, ret);
2182 status = BT_CTF_BTR_STATUS_ERROR;
2183 goto end;
2184 }
2185
2186 end:
2187 return status;
2188 }
2189
2190 static
2191 enum bt_ctf_btr_status btr_string_end_cb(
2192 struct bt_ctf_field_type *type, void *data)
2193 {
2194 struct bt_ctf_notif_iter *notit = data;
2195
2196 BT_LOGV("String (end) function called from BTR: "
2197 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2198 "ft-id=%s",
2199 notit, notit->btr, type,
2200 bt_ctf_field_type_id_string(
2201 bt_ctf_field_type_get_type_id(type)));
2202
2203 /* Pop string field */
2204 stack_pop(notit->stack);
2205
2206 /* Go to next field */
2207 stack_top(notit->stack)->index++;
2208 return BT_CTF_BTR_STATUS_OK;
2209 }
2210
2211 enum bt_ctf_btr_status btr_compound_begin_cb(
2212 struct bt_ctf_field_type *type, void *data)
2213 {
2214 enum bt_ctf_btr_status status = BT_CTF_BTR_STATUS_OK;
2215 struct bt_ctf_notif_iter *notit = data;
2216 struct bt_ctf_field *field;
2217 int ret;
2218
2219 BT_LOGV("Compound (beginning) function called from BTR: "
2220 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2221 "ft-id=%s",
2222 notit, notit->btr, type,
2223 bt_ctf_field_type_id_string(
2224 bt_ctf_field_type_get_type_id(type)));
2225
2226 /* Create field */
2227 if (stack_empty(notit->stack)) {
2228 /* Root: create dynamic scope field */
2229 *notit->cur_dscope_field = bt_ctf_field_create(type);
2230 field = *notit->cur_dscope_field;
2231
2232 /*
2233 * Field will be put at the end of this function
2234 * (stack_push() will take one reference, but this
2235 * reference is lost upon the equivalent stack_pop()
2236 * later), so also get it for our context to own it.
2237 */
2238 bt_get(*notit->cur_dscope_field);
2239
2240 if (!field) {
2241 BT_LOGE("Cannot create compound field: "
2242 "notit-addr=%p, ft-addr=%p, ft-id=%s",
2243 notit, type,
2244 bt_ctf_field_type_id_string(
2245 bt_ctf_field_type_get_type_id(type)));
2246 status = BT_CTF_BTR_STATUS_ERROR;
2247 goto end;
2248 }
2249 } else {
2250 field = get_next_field(notit);
2251 if (!field) {
2252 BT_LOGW("Cannot get next field: notit-addr=%p", notit);
2253 status = BT_CTF_BTR_STATUS_ERROR;
2254 goto end;
2255 }
2256 }
2257
2258 /* Push field */
2259 assert(field);
2260 ret = stack_push(notit->stack, field);
2261 if (ret) {
2262 BT_LOGE("Cannot push compound field onto the stack: "
2263 "notit-addr=%p, ft-addr=%p, ft-id=%s, ret=%d",
2264 notit, type,
2265 bt_ctf_field_type_id_string(
2266 bt_ctf_field_type_get_type_id(type)),
2267 ret);
2268 status = BT_CTF_BTR_STATUS_ERROR;
2269 goto end;
2270 }
2271
2272 end:
2273 BT_PUT(field);
2274
2275 return status;
2276 }
2277
2278 enum bt_ctf_btr_status btr_compound_end_cb(
2279 struct bt_ctf_field_type *type, void *data)
2280 {
2281 struct bt_ctf_notif_iter *notit = data;
2282
2283 BT_LOGV("Compound (end) function called from BTR: "
2284 "notit-addr=%p, btr-addr=%p, ft-addr=%p, "
2285 "ft-id=%s",
2286 notit, notit->btr, type,
2287 bt_ctf_field_type_id_string(
2288 bt_ctf_field_type_get_type_id(type)));
2289 assert(!stack_empty(notit->stack));
2290
2291 /* Pop stack */
2292 stack_pop(notit->stack);
2293
2294 /* If the stack is not empty, increment the base's index */
2295 if (!stack_empty(notit->stack)) {
2296 stack_top(notit->stack)->index++;
2297 }
2298
2299 return BT_CTF_BTR_STATUS_OK;
2300 }
2301
2302 static
2303 struct bt_ctf_field *resolve_field(struct bt_ctf_notif_iter *notit,
2304 struct bt_ctf_field_path *path)
2305 {
2306 struct bt_ctf_field *field = NULL;
2307 unsigned int i;
2308
2309 if (BT_LOG_ON_VERBOSE) {
2310 GString *gstr = bt_ctf_field_path_string(path);
2311
2312 BT_LOGV("Resolving field path: notit-addr=%p, field-path=\"%s\"",
2313 notit, gstr ? gstr->str : NULL);
2314
2315 if (gstr) {
2316 g_string_free(gstr, TRUE);
2317 }
2318 }
2319
2320 switch (bt_ctf_field_path_get_root_scope(path)) {
2321 case BT_CTF_SCOPE_TRACE_PACKET_HEADER:
2322 field = notit->dscopes.trace_packet_header;
2323 break;
2324 case BT_CTF_SCOPE_STREAM_PACKET_CONTEXT:
2325 field = notit->dscopes.stream_packet_context;
2326 break;
2327 case BT_CTF_SCOPE_STREAM_EVENT_HEADER:
2328 field = notit->dscopes.stream_event_header;
2329 break;
2330 case BT_CTF_SCOPE_STREAM_EVENT_CONTEXT:
2331 field = notit->dscopes.stream_event_context;
2332 break;
2333 case BT_CTF_SCOPE_EVENT_CONTEXT:
2334 field = notit->dscopes.event_context;
2335 break;
2336 case BT_CTF_SCOPE_EVENT_FIELDS:
2337 field = notit->dscopes.event_payload;
2338 break;
2339 default:
2340 BT_LOGF("Cannot resolve field path: unknown scope: "
2341 "notit-addr=%p, root-scope=%s",
2342 notit, bt_ctf_scope_string(
2343 bt_ctf_field_path_get_root_scope(path)));
2344 abort();
2345 }
2346
2347 if (!field) {
2348 BT_LOGW("Cannot resolve field path: root field not found: "
2349 "notit-addr=%p, root-scope=%s",
2350 notit, bt_ctf_scope_string(
2351 bt_ctf_field_path_get_root_scope(path)));
2352 goto end;
2353 }
2354
2355 bt_get(field);
2356
2357 for (i = 0; i < bt_ctf_field_path_get_index_count(path); ++i) {
2358 struct bt_ctf_field *next_field = NULL;
2359 struct bt_ctf_field_type *field_type;
2360 int index = bt_ctf_field_path_get_index(path, i);
2361
2362 field_type = bt_ctf_field_get_type(field);
2363 assert(field_type);
2364
2365 if (is_struct_type(field_type)) {
2366 next_field = bt_ctf_field_structure_get_field_by_index(
2367 field, index);
2368 } else if (is_variant_type(field_type)) {
2369 next_field =
2370 bt_ctf_field_variant_get_current_field(field);
2371 }
2372
2373 BT_PUT(field);
2374 BT_PUT(field_type);
2375
2376 if (!next_field) {
2377 BT_LOGW("Cannot find next field: "
2378 "notit-addr=%p, ft-addr=%p, ft-id=%s, index=%d",
2379 notit, field_type,
2380 bt_ctf_field_type_id_string(
2381 bt_ctf_field_type_get_type_id(field_type)),
2382 index);
2383 goto end;
2384 }
2385
2386 /* Move next field -> field */
2387 BT_MOVE(field, next_field);
2388 }
2389
2390 end:
2391 return field;
2392 }
2393
2394 static
2395 int64_t btr_get_sequence_length_cb(struct bt_ctf_field_type *type, void *data)
2396 {
2397 int64_t ret = -1;
2398 int iret;
2399 struct bt_ctf_field *seq_field;
2400 struct bt_ctf_field_path *field_path;
2401 struct bt_ctf_notif_iter *notit = data;
2402 struct bt_ctf_field *length_field = NULL;
2403 uint64_t length;
2404
2405 field_path = bt_ctf_field_type_sequence_get_length_field_path(type);
2406 assert(field_path);
2407 length_field = resolve_field(notit, field_path);
2408 if (!length_field) {
2409 BT_LOGW("Cannot resolve sequence field type's length field path: "
2410 "notit-addr=%p, ft-addr=%p",
2411 notit, type);
2412 goto end;
2413 }
2414
2415 iret = bt_ctf_field_unsigned_integer_get_value(length_field, &length);
2416 if (iret) {
2417 BT_LOGE("Cannot get value of sequence length field: "
2418 "notit-addr=%p, field-addr=%p",
2419 notit, length_field);
2420 goto end;
2421 }
2422
2423 seq_field = stack_top(notit->stack)->base;
2424 iret = bt_ctf_field_sequence_set_length(seq_field, length_field);
2425 if (iret) {
2426 BT_LOGE("Cannot set sequence field's length field: "
2427 "notit-addr=%p, seq-field-addr=%p, "
2428 "length-field-addr=%p, ",
2429 notit, seq_field, length_field);
2430 goto end;
2431 }
2432
2433 ret = (int64_t) length;
2434
2435 end:
2436 BT_PUT(length_field);
2437 BT_PUT(field_path);
2438
2439 return ret;
2440 }
2441
2442 static
2443 struct bt_ctf_field_type *btr_get_variant_type_cb(
2444 struct bt_ctf_field_type *type, void *data)
2445 {
2446 struct bt_ctf_field_path *path;
2447 struct bt_ctf_notif_iter *notit = data;
2448 struct bt_ctf_field *var_field;
2449 struct bt_ctf_field *tag_field = NULL;
2450 struct bt_ctf_field *selected_field = NULL;
2451 struct bt_ctf_field_type *selected_field_type = NULL;
2452
2453 path = bt_ctf_field_type_variant_get_tag_field_path(type);
2454 assert(path);
2455 tag_field = resolve_field(notit, path);
2456 if (!tag_field) {
2457 BT_LOGW("Cannot resolve variant field type's tag field path: "
2458 "notit-addr=%p, ft-addr=%p",
2459 notit, type);
2460 goto end;
2461 }
2462
2463 /*
2464 * We found the enumeration tag field instance which should be
2465 * able to select a current field for this variant. This
2466 * callback function we're in is called _after_
2467 * compound_begin(), so the current stack top's base field is
2468 * the variant field in question. We get the selected field here
2469 * thanks to this tag field (thus creating the selected field),
2470 * which will also provide us with its type. Then, this field
2471 * will remain the current selected one until the next callback
2472 * function call which is used to fill the current selected
2473 * field.
2474 */
2475 var_field = stack_top(notit->stack)->base;
2476 selected_field = bt_ctf_field_variant_get_field(var_field, tag_field);
2477 if (!selected_field) {
2478 BT_LOGW("Cannot get variant field's selection using tag field: "
2479 "notit-addr=%p, var-field-addr=%p, tag-field-addr=%p",
2480 notit, var_field, tag_field);
2481 goto end;
2482 }
2483
2484 selected_field_type = bt_ctf_field_get_type(selected_field);
2485
2486 end:
2487 BT_PUT(tag_field);
2488 BT_PUT(selected_field);
2489 BT_PUT(path);
2490
2491 return selected_field_type;
2492 }
2493
2494 static
2495 int set_event_clocks(struct bt_ctf_event *event,
2496 struct bt_ctf_notif_iter *notit)
2497 {
2498 int ret;
2499 GHashTableIter iter;
2500 struct bt_ctf_clock_class *clock_class;
2501 uint64_t *clock_state;
2502
2503 g_hash_table_iter_init(&iter, notit->clock_states);
2504
2505 while (g_hash_table_iter_next(&iter, (gpointer) &clock_class,
2506 (gpointer) &clock_state)) {
2507 struct bt_ctf_clock_value *clock_value;
2508
2509 clock_value = bt_ctf_clock_value_create(clock_class,
2510 *clock_state);
2511 if (!clock_value) {
2512 BT_LOGE("Cannot create clock value from clock class: "
2513 "notit-addr=%p, clock-class-addr=%p, "
2514 "clock-class-name=\"%s\"",
2515 notit, clock_class,
2516 bt_ctf_clock_class_get_name(clock_class));
2517 ret = -1;
2518 goto end;
2519 }
2520 ret = bt_ctf_event_set_clock_value(event, clock_value);
2521 bt_put(clock_value);
2522 if (ret) {
2523 struct bt_ctf_event_class *event_class =
2524 bt_ctf_event_get_class(event);
2525
2526 assert(event_class);
2527 BT_LOGE("Cannot set event's clock value: "
2528 "notit-addr=%p, event-addr=%p, "
2529 "event-class-name=\"%s\", "
2530 "event-class-id=%" PRId64 ", "
2531 "clock-class-addr=%p, "
2532 "clock-class-name=\"%s\", "
2533 "clock-value-addr=%p",
2534 notit, event,
2535 bt_ctf_event_class_get_name(event_class),
2536 bt_ctf_event_class_get_id(event_class),
2537 clock_class,
2538 bt_ctf_clock_class_get_name(clock_class),
2539 clock_value);
2540 bt_put(event_class);
2541 goto end;
2542 }
2543 }
2544
2545 ret = 0;
2546 end:
2547 return ret;
2548 }
2549
2550 static
2551 struct bt_ctf_event *create_event(struct bt_ctf_notif_iter *notit)
2552 {
2553 int ret;
2554 struct bt_ctf_event *event;
2555
2556 BT_LOGV("Creating event for event notification: "
2557 "notit-addr=%p, event-class-addr=%p, "
2558 "event-class-name=\"%s\", "
2559 "event-class-id=%" PRId64,
2560 notit, notit->meta.event_class,
2561 bt_ctf_event_class_get_name(notit->meta.event_class),
2562 bt_ctf_event_class_get_id(notit->meta.event_class));
2563
2564 /* Create event object. */
2565 event = bt_ctf_event_create(notit->meta.event_class);
2566 if (!event) {
2567 BT_LOGE("Cannot create event: "
2568 "notit-addr=%p, event-class-addr=%p, "
2569 "event-class-name=\"%s\", "
2570 "event-class-id=%" PRId64,
2571 notit, notit->meta.event_class,
2572 bt_ctf_event_class_get_name(notit->meta.event_class),
2573 bt_ctf_event_class_get_id(notit->meta.event_class));
2574 goto error;
2575 }
2576
2577 /* Set header, stream event context, context, and payload fields. */
2578 ret = bt_ctf_event_set_header(event,
2579 notit->dscopes.stream_event_header);
2580 if (ret) {
2581 BT_LOGE("Cannot set event's header field: "
2582 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2583 "event-class-name=\"%s\", "
2584 "event-class-id=%" PRId64 ", field-addr=%p",
2585 notit, event, notit->meta.event_class,
2586 bt_ctf_event_class_get_name(notit->meta.event_class),
2587 bt_ctf_event_class_get_id(notit->meta.event_class),
2588 notit->dscopes.stream_event_header);
2589 goto error;
2590 }
2591
2592 ret = bt_ctf_event_set_stream_event_context(event,
2593 notit->dscopes.stream_event_context);
2594 if (ret) {
2595 BT_LOGE("Cannot set event's context field: "
2596 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2597 "event-class-name=\"%s\", "
2598 "event-class-id=%" PRId64 ", field-addr=%p",
2599 notit, event, notit->meta.event_class,
2600 bt_ctf_event_class_get_name(notit->meta.event_class),
2601 bt_ctf_event_class_get_id(notit->meta.event_class),
2602 notit->dscopes.stream_event_context);
2603 goto error;
2604 }
2605
2606 ret = bt_ctf_event_set_event_context(event,
2607 notit->dscopes.event_context);
2608 if (ret) {
2609 BT_LOGE("Cannot set event's stream event context field: "
2610 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2611 "event-class-name=\"%s\", "
2612 "event-class-id=%" PRId64 ", field-addr=%p",
2613 notit, event, notit->meta.event_class,
2614 bt_ctf_event_class_get_name(notit->meta.event_class),
2615 bt_ctf_event_class_get_id(notit->meta.event_class),
2616 notit->dscopes.event_context);
2617 goto error;
2618 }
2619
2620 ret = bt_ctf_event_set_event_payload(event,
2621 notit->dscopes.event_payload);
2622 if (ret) {
2623 BT_LOGE("Cannot set event's payload field: "
2624 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2625 "event-class-name=\"%s\", "
2626 "event-class-id=%" PRId64 ", field-addr=%p",
2627 notit, event, notit->meta.event_class,
2628 bt_ctf_event_class_get_name(notit->meta.event_class),
2629 bt_ctf_event_class_get_id(notit->meta.event_class),
2630 notit->dscopes.event_payload);
2631 goto error;
2632 }
2633
2634 ret = set_event_clocks(event, notit);
2635 if (ret) {
2636 BT_LOGE("Cannot set event's clock values: "
2637 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2638 "event-class-name=\"%s\", "
2639 "event-class-id=%" PRId64,
2640 notit, event, notit->meta.event_class,
2641 bt_ctf_event_class_get_name(notit->meta.event_class),
2642 bt_ctf_event_class_get_id(notit->meta.event_class));
2643 goto error;
2644 }
2645
2646 /* Associate with current packet. */
2647 assert(notit->packet);
2648 ret = bt_ctf_event_set_packet(event, notit->packet);
2649 if (ret) {
2650 BT_LOGE("Cannot set event's header field: "
2651 "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
2652 "event-class-name=\"%s\", "
2653 "event-class-id=%" PRId64 ", packet-addr=%p",
2654 notit, event, notit->meta.event_class,
2655 bt_ctf_event_class_get_name(notit->meta.event_class),
2656 bt_ctf_event_class_get_id(notit->meta.event_class),
2657 notit->packet);
2658 goto error;
2659 }
2660
2661 goto end;
2662
2663 error:
2664 BT_PUT(event);
2665
2666 end:
2667 return event;
2668 }
2669
2670 static
2671 int set_stream(struct bt_ctf_notif_iter *notit)
2672 {
2673 int ret = 0;
2674 struct bt_ctf_stream *stream = NULL;
2675
2676 BT_LOGV("Calling user function (get stream): notit-addr=%p, "
2677 "stream-class-addr=%p, stream-class-name=\"%s\", "
2678 "stream-class-id=%" PRId64,
2679 notit, notit->meta.stream_class,
2680 bt_ctf_stream_class_get_name(notit->meta.stream_class),
2681 bt_ctf_stream_class_get_id(notit->meta.stream_class));
2682 stream = bt_get(notit->medium.medops.get_stream(
2683 notit->meta.stream_class, notit->medium.data));
2684 BT_LOGV("User function returned: stream-addr=%p", stream);
2685 if (!stream) {
2686 BT_LOGW_STR("User function failed to return a stream object for the given stream class.");
2687 ret = -1;
2688 goto end;
2689 }
2690
2691 if (notit->stream && stream != notit->stream) {
2692 BT_LOGW("User function returned a different stream than the previous one for the same sequence of packets.");
2693 ret = -1;
2694 goto end;
2695 }
2696
2697 BT_MOVE(notit->stream, stream);
2698
2699 end:
2700 bt_put(stream);
2701 return ret;
2702 }
2703
2704 static
2705 void create_packet(struct bt_ctf_notif_iter *notit)
2706 {
2707 int ret;
2708 struct bt_ctf_packet *packet = NULL;
2709
2710 BT_LOGV("Creating packet for packet notification: "
2711 "notit-addr=%p", notit);
2712
2713 /* Ask the user for the stream */
2714 ret = set_stream(notit);
2715 if (ret) {
2716 goto error;
2717 }
2718
2719 BT_LOGV("Creating packet from stream: "
2720 "notit-addr=%p, stream-addr=%p, "
2721 "stream-class-addr=%p, "
2722 "stream-class-name=\"%s\", "
2723 "stream-class-id=%" PRId64,
2724 notit, notit->stream, notit->meta.stream_class,
2725 bt_ctf_stream_class_get_name(notit->meta.stream_class),
2726 bt_ctf_stream_class_get_id(notit->meta.stream_class));
2727
2728 /* Create packet */
2729 packet = bt_ctf_packet_create(notit->stream);
2730 if (!packet) {
2731 BT_LOGE("Cannot create packet from stream: "
2732 "notit-addr=%p, stream-addr=%p, "
2733 "stream-class-addr=%p, "
2734 "stream-class-name=\"%s\", "
2735 "stream-class-id=%" PRId64,
2736 notit, notit->stream, notit->meta.stream_class,
2737 bt_ctf_stream_class_get_name(notit->meta.stream_class),
2738 bt_ctf_stream_class_get_id(notit->meta.stream_class));
2739 goto error;
2740 }
2741
2742 /* Set packet's context and header fields */
2743 if (notit->dscopes.trace_packet_header) {
2744 ret = bt_ctf_packet_set_header(packet,
2745 notit->dscopes.trace_packet_header);
2746 if (ret) {
2747 BT_LOGE("Cannot set packet's header field: "
2748 "notit-addr=%p, packet-addr=%p, "
2749 "stream-addr=%p, "
2750 "stream-class-addr=%p, "
2751 "stream-class-name=\"%s\", "
2752 "stream-class-id=%" PRId64 ", "
2753 "field-addr=%p",
2754 notit, packet, notit->stream, notit->meta.stream_class,
2755 bt_ctf_stream_class_get_name(notit->meta.stream_class),
2756 bt_ctf_stream_class_get_id(notit->meta.stream_class),
2757 notit->dscopes.trace_packet_header);
2758 goto error;
2759 }
2760 }
2761
2762 if (notit->dscopes.stream_packet_context) {
2763 ret = bt_ctf_packet_set_context(packet,
2764 notit->dscopes.stream_packet_context);
2765 if (ret) {
2766 BT_LOGE("Cannot set packet's context field: "
2767 "notit-addr=%p, packet-addr=%p, "
2768 "stream-addr=%p, "
2769 "stream-class-addr=%p, "
2770 "stream-class-name=\"%s\", "
2771 "stream-class-id=%" PRId64 ", "
2772 "field-addr=%p",
2773 notit, packet, notit->stream, notit->meta.stream_class,
2774 bt_ctf_stream_class_get_name(notit->meta.stream_class),
2775 bt_ctf_stream_class_get_id(notit->meta.stream_class),
2776 notit->dscopes.trace_packet_header);
2777 goto error;
2778 }
2779 }
2780
2781 goto end;
2782
2783 error:
2784 BT_PUT(packet);
2785
2786 end:
2787 BT_MOVE(notit->packet, packet);
2788 }
2789
2790 static
2791 void notify_new_packet(struct bt_ctf_notif_iter *notit,
2792 struct bt_notification **notification)
2793 {
2794 struct bt_notification *ret;
2795
2796 /* Initialize the iterator's current packet */
2797 create_packet(notit);
2798 if (!notit->packet) {
2799 BT_LOGE("Cannot create packet for packet notification: "
2800 "notit-addr=%p", notit);
2801 return;
2802 }
2803
2804 ret = bt_notification_packet_begin_create(notit->packet);
2805 if (!ret) {
2806 BT_LOGE("Cannot create packet beginning notification: "
2807 "notit-addr=%p, packet-addr=%p",
2808 notit, notit->packet);
2809 return;
2810 }
2811 *notification = ret;
2812 }
2813
2814 static
2815 void notify_end_of_packet(struct bt_ctf_notif_iter *notit,
2816 struct bt_notification **notification)
2817 {
2818 struct bt_notification *ret;
2819
2820 if (!notit->packet) {
2821 return;
2822 }
2823
2824 ret = bt_notification_packet_end_create(notit->packet);
2825 if (!ret) {
2826 BT_LOGE("Cannot create packet end notification: "
2827 "notit-addr=%p, packet-addr=%p",
2828 notit, notit->packet);
2829 return;
2830 }
2831 BT_PUT(notit->packet);
2832 *notification = ret;
2833 }
2834
2835 static
2836 void notify_event(struct bt_ctf_notif_iter *notit,
2837 struct bt_clock_class_priority_map *cc_prio_map,
2838 struct bt_notification **notification)
2839 {
2840 struct bt_ctf_event *event;
2841 struct bt_notification *ret = NULL;
2842
2843 /* Create event */
2844 event = create_event(notit);
2845 if (!event) {
2846 BT_LOGE("Cannot create event for event notification: "
2847 "notit-addr=%p", notit);
2848 goto end;
2849 }
2850
2851 ret = bt_notification_event_create(event, cc_prio_map);
2852 if (!ret) {
2853 BT_LOGE("Cannot create event notification: "
2854 "notit-addr=%p, event-addr=%p, "
2855 "cc-prio-map-addr=%p",
2856 notit, event, cc_prio_map);
2857 goto end;
2858 }
2859 *notification = ret;
2860 end:
2861 BT_PUT(event);
2862 }
2863
2864 static
2865 void init_trace_field_path_cache(struct bt_ctf_trace *trace,
2866 struct trace_field_path_cache *trace_field_path_cache)
2867 {
2868 int stream_id = -1;
2869 int stream_instance_id = -1;
2870 int i, count;
2871 struct bt_ctf_field_type *packet_header = NULL;
2872
2873 packet_header = bt_ctf_trace_get_packet_header_type(trace);
2874 if (!packet_header) {
2875 goto end;
2876 }
2877
2878 if (!bt_ctf_field_type_is_structure(packet_header)) {
2879 goto end;
2880 }
2881
2882 count = bt_ctf_field_type_structure_get_field_count(packet_header);
2883 assert(count >= 0);
2884
2885 for (i = 0; (i < count && (stream_id == -1 || stream_instance_id == -1)); i++) {
2886 int ret;
2887 const char *field_name;
2888
2889 ret = bt_ctf_field_type_structure_get_field(packet_header,
2890 &field_name, NULL, i);
2891 if (ret) {
2892 BT_LOGE("Cannot get structure field's field: "
2893 "field-addr=%p, index=%d",
2894 packet_header, i);
2895 goto end;
2896 }
2897
2898 if (stream_id == -1 && !strcmp(field_name, "stream_id")) {
2899 stream_id = i;
2900 } else if (stream_instance_id == -1 &&
2901 !strcmp(field_name, "stream_instance_id")) {
2902 stream_instance_id = i;
2903 }
2904 }
2905
2906 end:
2907 trace_field_path_cache->stream_id = stream_id;
2908 trace_field_path_cache->stream_instance_id = stream_instance_id;
2909 BT_PUT(packet_header);
2910 }
2911
2912 BT_HIDDEN
2913 struct bt_ctf_notif_iter *bt_ctf_notif_iter_create(struct bt_ctf_trace *trace,
2914 size_t max_request_sz,
2915 struct bt_ctf_notif_iter_medium_ops medops, void *data)
2916 {
2917 struct bt_ctf_notif_iter *notit = NULL;
2918 struct bt_ctf_btr_cbs cbs = {
2919 .types = {
2920 .signed_int = btr_signed_int_cb,
2921 .unsigned_int = btr_unsigned_int_cb,
2922 .floating_point = btr_floating_point_cb,
2923 .string_begin = btr_string_begin_cb,
2924 .string = btr_string_cb,
2925 .string_end = btr_string_end_cb,
2926 .compound_begin = btr_compound_begin_cb,
2927 .compound_end = btr_compound_end_cb,
2928 },
2929 .query = {
2930 .get_sequence_length = btr_get_sequence_length_cb,
2931 .get_variant_type = btr_get_variant_type_cb,
2932 },
2933 };
2934
2935 assert(trace);
2936 assert(medops.request_bytes);
2937 assert(medops.get_stream);
2938 BT_LOGD("Creating CTF plugin notification iterator: "
2939 "trace-addr=%p, trace-name=\"%s\", max-request-size=%zu, "
2940 "data=%p",
2941 trace, bt_ctf_trace_get_name(trace), max_request_sz, data);
2942 notit = g_new0(struct bt_ctf_notif_iter, 1);
2943 if (!notit) {
2944 BT_LOGE_STR("Failed to allocate one CTF plugin notification iterator.");
2945 goto end;
2946 }
2947 notit->clock_states = g_hash_table_new_full(g_direct_hash,
2948 g_direct_equal, bt_put, g_free);
2949 if (!notit->clock_states) {
2950 BT_LOGE_STR("Failed to allocate a GHashTable.");
2951 goto error;
2952 }
2953 notit->meta.trace = bt_get(trace);
2954 notit->medium.medops = medops;
2955 notit->medium.max_request_sz = max_request_sz;
2956 notit->medium.data = data;
2957 notit->stack = stack_new(notit);
2958 if (!notit->stack) {
2959 BT_LOGE_STR("Failed to create field stack.");
2960 goto error;
2961 }
2962
2963 notit->btr = bt_ctf_btr_create(cbs, notit);
2964 if (!notit->btr) {
2965 BT_LOGE_STR("Failed to create binary type reader (BTR).");
2966 goto error;
2967 }
2968
2969 bt_ctf_notif_iter_reset(notit);
2970 init_trace_field_path_cache(trace, &notit->trace_field_path_cache);
2971 notit->sc_field_path_caches = g_hash_table_new_full(g_direct_hash,
2972 g_direct_equal, bt_put, g_free);
2973 if (!notit->sc_field_path_caches) {
2974 BT_LOGE_STR("Failed to allocate a GHashTable.");
2975 goto error;
2976 }
2977
2978 notit->field_overrides = g_hash_table_new_full(g_direct_hash,
2979 g_direct_equal, bt_put, g_free);
2980 if (!notit->field_overrides) {
2981 BT_LOGE_STR("Failed to allocate a GHashTable.");
2982 goto error;
2983 }
2984
2985 BT_LOGD("Created CTF plugin notification iterator: "
2986 "trace-addr=%p, trace-name=\"%s\", max-request-size=%zu, "
2987 "data=%p, notit-addr=%p",
2988 trace, bt_ctf_trace_get_name(trace), max_request_sz, data,
2989 notit);
2990
2991 end:
2992 return notit;
2993
2994 error:
2995 bt_ctf_notif_iter_destroy(notit);
2996 notit = NULL;
2997 goto end;
2998 }
2999
3000 void bt_ctf_notif_iter_destroy(struct bt_ctf_notif_iter *notit)
3001 {
3002 BT_PUT(notit->meta.trace);
3003 BT_PUT(notit->meta.stream_class);
3004 BT_PUT(notit->meta.event_class);
3005 BT_PUT(notit->packet);
3006 BT_PUT(notit->stream);
3007 BT_PUT(notit->cur_timestamp_end);
3008 put_all_dscopes(notit);
3009
3010 BT_LOGD("Destroying CTF plugin notification iterator: addr=%p", notit);
3011
3012 if (notit->stack) {
3013 BT_LOGD_STR("Destroying field stack.");
3014 stack_destroy(notit->stack);
3015 }
3016
3017 if (notit->btr) {
3018 BT_LOGD("Destroying BTR: btr-addr=%p", notit->btr);
3019 bt_ctf_btr_destroy(notit->btr);
3020 }
3021
3022 if (notit->clock_states) {
3023 g_hash_table_destroy(notit->clock_states);
3024 }
3025
3026 if (notit->sc_field_path_caches) {
3027 g_hash_table_destroy(notit->sc_field_path_caches);
3028 }
3029
3030 if (notit->field_overrides) {
3031 g_hash_table_destroy(notit->field_overrides);
3032 }
3033
3034 g_free(notit);
3035 }
3036
3037 enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_next_notification(
3038 struct bt_ctf_notif_iter *notit,
3039 struct bt_clock_class_priority_map *cc_prio_map,
3040 struct bt_notification **notification)
3041 {
3042 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
3043
3044 assert(notit);
3045 assert(notification);
3046
3047 BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p",
3048 notit, cc_prio_map);
3049
3050 while (true) {
3051 status = handle_state(notit);
3052 if (status == BT_CTF_NOTIF_ITER_STATUS_AGAIN) {
3053 BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_AGAIN.");
3054 goto end;
3055 }
3056 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
3057 if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
3058 BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_EOF.");
3059 } else {
3060 BT_LOGW("Cannot handle state: "
3061 "notit-addr=%p, state=%s",
3062 notit, state_string(notit->state));
3063 }
3064 goto end;
3065 }
3066
3067 switch (notit->state) {
3068 case STATE_EMIT_NOTIF_NEW_PACKET:
3069 /* notify_new_packet() logs errors */
3070 notify_new_packet(notit, notification);
3071 if (!*notification) {
3072 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
3073 }
3074 goto end;
3075 case STATE_EMIT_NOTIF_EVENT:
3076 /* notify_event() logs errors */
3077 notify_event(notit, cc_prio_map, notification);
3078 if (!*notification) {
3079 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
3080 }
3081 goto end;
3082 case STATE_EMIT_NOTIF_END_OF_PACKET:
3083 /* Update clock with timestamp_end field. */
3084 if (notit->cur_timestamp_end) {
3085 enum bt_ctf_btr_status btr_status;
3086 struct bt_ctf_field_type *field_type =
3087 bt_ctf_field_get_type(
3088 notit->cur_timestamp_end);
3089
3090 assert(field_type);
3091 btr_status = update_clock(notit,
3092 notit->cur_timestamp_end);
3093 BT_PUT(field_type);
3094 if (btr_status != BT_CTF_BTR_STATUS_OK) {
3095 BT_LOGW("Cannot update stream's clock value: "
3096 "notit-addr=%p", notit);
3097 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
3098 goto end;
3099 }
3100 }
3101
3102 /* notify_end_of_packet() logs errors */
3103 notify_end_of_packet(notit, notification);
3104 if (!*notification) {
3105 status = BT_CTF_NOTIF_ITER_STATUS_ERROR;
3106 }
3107 goto end;
3108 default:
3109 /* Non-emitting state: continue */
3110 break;
3111 }
3112 }
3113
3114 end:
3115 return status;
3116 }
3117
3118 BT_HIDDEN
3119 enum bt_ctf_notif_iter_status bt_ctf_notif_iter_get_packet_header_context_fields(
3120 struct bt_ctf_notif_iter *notit,
3121 struct bt_ctf_field **packet_header_field,
3122 struct bt_ctf_field **packet_context_field)
3123 {
3124 enum bt_ctf_notif_iter_status status = BT_CTF_NOTIF_ITER_STATUS_OK;
3125
3126 assert(notit);
3127
3128 if (notit->state == STATE_EMIT_NOTIF_NEW_PACKET) {
3129 /* We're already there */
3130 goto set_fields;
3131 }
3132
3133 while (true) {
3134 status = handle_state(notit);
3135 if (status == BT_CTF_NOTIF_ITER_STATUS_AGAIN) {
3136 BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_AGAIN.");
3137 goto end;
3138 }
3139 if (status != BT_CTF_NOTIF_ITER_STATUS_OK) {
3140 if (status == BT_CTF_NOTIF_ITER_STATUS_EOF) {
3141 BT_LOGV_STR("Medium returned BT_CTF_NOTIF_ITER_STATUS_EOF.");
3142 } else {
3143 BT_LOGW("Cannot handle state: "
3144 "notit-addr=%p, state=%s",
3145 notit, state_string(notit->state));
3146 }
3147 goto end;
3148 }
3149
3150 switch (notit->state) {
3151 case STATE_EMIT_NOTIF_NEW_PACKET:
3152 /*
3153 * Packet header and context fields are
3154 * potentially decoded (or they don't exist).
3155 */
3156 goto set_fields;
3157 case STATE_INIT:
3158 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
3159 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
3160 case STATE_AFTER_TRACE_PACKET_HEADER:
3161 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
3162 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
3163 case STATE_AFTER_STREAM_PACKET_CONTEXT:
3164 /* Non-emitting state: continue */
3165 break;
3166 default:
3167 /*
3168 * We should never get past the
3169 * STATE_EMIT_NOTIF_NEW_PACKET state.
3170 */
3171 BT_LOGF("Unexpected state: notit-addr=%p, state=%s",
3172 notit, state_string(notit->state));
3173 abort();
3174 }
3175 }
3176
3177 set_fields:
3178 if (packet_header_field) {
3179 *packet_header_field = bt_get(notit->dscopes.trace_packet_header);
3180 }
3181
3182 if (packet_context_field) {
3183 *packet_context_field = bt_get(notit->dscopes.stream_packet_context);
3184 }
3185
3186 end:
3187 return status;
3188 }
3189
3190 BT_HIDDEN
3191 void bt_ctf_notif_iter_set_medops_data(struct bt_ctf_notif_iter *notit,
3192 void *medops_data)
3193 {
3194 assert(notit);
3195 notit->medium.data = medops_data;
3196 }
This page took 0.138429 seconds and 5 git commands to generate.