lib: strictly type function return status enumerations
[babeltrace.git] / src / plugins / ctf / common / msg-iter / msg-iter.c
CommitLineData
e98a2d6e 1/*
d6e69534 2 * Babeltrace - CTF message iterator
06a626b8 3 *
44c440bc
PP
4 * Copyright (c) 2015-2018 EfficiOS Inc. and Linux Foundation
5 * Copyright (c) 2015-2018 Philippe Proulx <pproulx@efficios.com>
e98a2d6e
PP
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
eb7f6c4f 26#define BT_COMP_LOG_SELF_COMP (notit->self_comp)
ea14c7dd 27#define BT_LOG_OUTPUT_LEVEL (notit->log_level)
350ad6c1 28#define BT_LOG_TAG "PLUGIN/CTF/MSG-ITER"
eb7f6c4f 29#include "plugins/comp-logging.h"
fdf0e7a0 30
e98a2d6e
PP
31#include <stdint.h>
32#include <inttypes.h>
33#include <stdio.h>
34#include <stddef.h>
35#include <stdbool.h>
578e048b 36#include "common/assert.h"
e98a2d6e 37#include <string.h>
3fadfbc0 38#include <babeltrace2/babeltrace.h>
578e048b 39#include "common/common.h"
e98a2d6e 40#include <glib.h>
0fbb9a9f 41#include <stdlib.h>
e98a2d6e 42
d6e69534 43#include "msg-iter.h"
5cd6d0e5 44#include "../bfcr/bfcr.h"
e98a2d6e 45
d6e69534 46struct bt_msg_iter;
e98a2d6e
PP
47
48/* A visit stack entry */
49struct stack_entry {
50 /*
51 * Current base field, one of:
52 *
53 * * string
54 * * structure
55 * * array
56 * * sequence
57 * * variant
58 *
312c056a 59 * Field is borrowed.
e98a2d6e 60 */
b19ff26f 61 bt_field *base;
e98a2d6e 62
44c440bc 63 /* Index of next field to set */
e98a2d6e
PP
64 size_t index;
65};
66
ea14c7dd
PP
67struct bt_msg_iter;
68
e98a2d6e
PP
69/* Visit stack */
70struct stack {
ea14c7dd
PP
71 struct bt_msg_iter *notit;
72
afe86a06
PP
73 /* Entries (struct stack_entry) */
74 GArray *entries;
75
76 /* Number of active entries */
77 size_t size;
e98a2d6e
PP
78};
79
80/* State */
81enum state {
82 STATE_INIT,
83 STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN,
84 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE,
85 STATE_AFTER_TRACE_PACKET_HEADER,
86 STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN,
87 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
88 STATE_AFTER_STREAM_PACKET_CONTEXT,
495490c5 89 STATE_CHECK_EMIT_MSG_STREAM_BEGINNING,
fc917f65
PP
90 STATE_EMIT_MSG_STREAM_BEGINNING,
91 STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING,
495490c5
PP
92 STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS,
93 STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS,
94 STATE_EMIT_MSG_DISCARDED_EVENTS,
95 STATE_EMIT_MSG_DISCARDED_PACKETS,
fc917f65 96 STATE_EMIT_MSG_PACKET_BEGINNING,
44c440bc
PP
97 STATE_DSCOPE_EVENT_HEADER_BEGIN,
98 STATE_DSCOPE_EVENT_HEADER_CONTINUE,
99 STATE_AFTER_EVENT_HEADER,
100 STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN,
101 STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE,
102 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN,
103 STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE,
e98a2d6e
PP
104 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN,
105 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
d6e69534 106 STATE_EMIT_MSG_EVENT,
e98a2d6e 107 STATE_SKIP_PACKET_PADDING,
fc917f65
PP
108 STATE_EMIT_MSG_PACKET_END_MULTI,
109 STATE_EMIT_MSG_PACKET_END_SINGLE,
495490c5 110 STATE_CHECK_EMIT_MSG_STREAM_ACTIVITY_END,
fc917f65
PP
111 STATE_EMIT_MSG_STREAM_ACTIVITY_END,
112 STATE_EMIT_MSG_STREAM_END,
113 STATE_DONE,
e98a2d6e
PP
114};
115
495490c5
PP
116struct end_of_packet_snapshots {
117 uint64_t discarded_events;
118 uint64_t packets;
119 uint64_t beginning_clock;
120 uint64_t end_clock;
121};
122
d6e69534
PP
123/* CTF message iterator */
124struct bt_msg_iter {
e98a2d6e
PP
125 /* Visit stack */
126 struct stack *stack;
127
d6e69534
PP
128 /* Current message iterator to create messages (weak) */
129 bt_self_message_iterator *msg_iter;
5c563278 130
fc917f65
PP
131 /*
132 * True to emit stream beginning and stream activity beginning
133 * messages.
134 */
135 bool emit_stream_begin_msg;
136
495490c5 137 /* True to emit stream end and stream activity end messages */
fc917f65
PP
138 bool emit_stream_end_msg;
139
495490c5
PP
140 /* True to set the stream */
141 bool set_stream;
142
e98a2d6e
PP
143 /*
144 * Current dynamic scope field pointer.
145 *
312c056a
PP
146 * This is set by read_dscope_begin_state() and contains the
147 * value of one of the pointers in `dscopes` below.
e98a2d6e 148 */
b19ff26f 149 bt_field *cur_dscope_field;
e98a2d6e 150
44c440bc
PP
151 /*
152 * True if we're done filling a string field from a text
153 * array/sequence payload.
154 */
155 bool done_filling_string;
156
157 /* Trace and classes */
41693723
PP
158 /* True to set IR fields */
159 bool set_ir_fields;
160
e98a2d6e 161 struct {
44c440bc
PP
162 struct ctf_trace_class *tc;
163 struct ctf_stream_class *sc;
164 struct ctf_event_class *ec;
e98a2d6e
PP
165 } meta;
166
83ebb7f1 167 /* Current packet context field wrapper (NULL if not created yet) */
b19ff26f 168 bt_packet_context_field *packet_context_field;
312c056a 169
e98a2d6e 170 /* Current packet (NULL if not created yet) */
b19ff26f 171 bt_packet *packet;
e98a2d6e 172
af87daef 173 /* Current stream (NULL if not set yet) */
b19ff26f 174 bt_stream *stream;
af87daef 175
312c056a 176 /* Current event (NULL if not created yet) */
b19ff26f 177 bt_event *event;
312c056a 178
d6e69534
PP
179 /* Current event message (NULL if not created yet) */
180 bt_message *event_msg;
312c056a 181
44c440bc 182 /* Database of current dynamic scopes */
e98a2d6e 183 struct {
b19ff26f 184 bt_field *stream_packet_context;
b19ff26f
PP
185 bt_field *event_common_context;
186 bt_field *event_spec_context;
187 bt_field *event_payload;
e98a2d6e
PP
188 } dscopes;
189
190 /* Current state */
191 enum state state;
192
2cf1d51e 193 /* Current medium buffer data */
e98a2d6e
PP
194 struct {
195 /* Last address provided by medium */
196 const uint8_t *addr;
197
198 /* Buffer size provided by medium (bytes) */
199 size_t sz;
200
201 /* Offset within whole packet of addr (bits) */
202 size_t packet_offset;
203
204 /* Current position from addr (bits) */
205 size_t at;
174e773b
PP
206
207 /* Position of the last event header from addr (bits) */
208 size_t last_eh_at;
e98a2d6e
PP
209 } buf;
210
211 /* Binary type reader */
5cd6d0e5 212 struct bt_bfcr *bfcr;
e98a2d6e 213
2cf1d51e 214 /* Current medium data */
e98a2d6e 215 struct {
d6e69534 216 struct bt_msg_iter_medium_ops medops;
e98a2d6e
PP
217 size_t max_request_sz;
218 void *data;
219 } medium;
220
221 /* Current packet size (bits) (-1 if unknown) */
44c440bc 222 int64_t cur_exp_packet_total_size;
e98a2d6e
PP
223
224 /* Current content size (bits) (-1 if unknown) */
44c440bc 225 int64_t cur_exp_packet_content_size;
c44c3e70 226
44c440bc
PP
227 /* Current stream class ID */
228 int64_t cur_stream_class_id;
9e0c8dbb 229
44c440bc
PP
230 /* Current event class ID */
231 int64_t cur_event_class_id;
5f870343 232
44c440bc
PP
233 /* Current data stream ID */
234 int64_t cur_data_stream_id;
5f870343
JG
235
236 /*
44c440bc
PP
237 * Offset, in the underlying media, of the current packet's
238 * start (-1 if unknown).
5f870343 239 */
44c440bc
PP
240 off_t cur_packet_offset;
241
242 /* Default clock's current value */
605e1019 243 uint64_t default_clock_snapshot;
5f870343 244
495490c5
PP
245 /* End of current packet snapshots */
246 struct end_of_packet_snapshots snapshots;
247
248 /* End of previous packet snapshots */
249 struct end_of_packet_snapshots prev_packet_snapshots;
44c440bc
PP
250
251 /* Stored values (for sequence lengths, variant tags) */
252 GArray *stored_values;
ea14c7dd
PP
253
254 /* Iterator's current log level */
255 bt_logging_level log_level;
eb7f6c4f
PP
256
257 /* Iterator's owning self component, or `NULL` if none (query) */
258 bt_self_component *self_comp;
e98a2d6e
PP
259};
260
fdf0e7a0
PP
261static inline
262const char *state_string(enum state state)
263{
264 switch (state) {
265 case STATE_INIT:
266 return "STATE_INIT";
267 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
268 return "STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN";
269 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
270 return "STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE";
271 case STATE_AFTER_TRACE_PACKET_HEADER:
272 return "STATE_AFTER_TRACE_PACKET_HEADER";
273 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
274 return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN";
275 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
276 return "STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE";
277 case STATE_AFTER_STREAM_PACKET_CONTEXT:
278 return "STATE_AFTER_STREAM_PACKET_CONTEXT";
fc917f65
PP
279 case STATE_EMIT_MSG_STREAM_BEGINNING:
280 return "STATE_EMIT_MSG_STREAM_BEGINNING";
281 case STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING:
282 return "STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING";
283 case STATE_EMIT_MSG_PACKET_BEGINNING:
284 return "STATE_EMIT_MSG_PACKET_BEGINNING";
495490c5
PP
285 case STATE_EMIT_MSG_DISCARDED_EVENTS:
286 return "STATE_EMIT_MSG_DISCARDED_EVENTS";
287 case STATE_EMIT_MSG_DISCARDED_PACKETS:
288 return "STATE_EMIT_MSG_DISCARDED_PACKETS";
44c440bc
PP
289 case STATE_DSCOPE_EVENT_HEADER_BEGIN:
290 return "STATE_DSCOPE_EVENT_HEADER_BEGIN";
291 case STATE_DSCOPE_EVENT_HEADER_CONTINUE:
292 return "STATE_DSCOPE_EVENT_HEADER_CONTINUE";
293 case STATE_AFTER_EVENT_HEADER:
294 return "STATE_AFTER_EVENT_HEADER";
295 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN:
296 return "STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN";
297 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE:
298 return "STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE";
299 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN:
300 return "STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN";
301 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE:
302 return "STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE";
fdf0e7a0
PP
303 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN:
304 return "STATE_DSCOPE_EVENT_PAYLOAD_BEGIN";
305 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE:
306 return "STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE";
d6e69534
PP
307 case STATE_EMIT_MSG_EVENT:
308 return "STATE_EMIT_MSG_EVENT";
fdf0e7a0
PP
309 case STATE_SKIP_PACKET_PADDING:
310 return "STATE_SKIP_PACKET_PADDING";
fc917f65
PP
311 case STATE_EMIT_MSG_PACKET_END_MULTI:
312 return "STATE_EMIT_MSG_PACKET_END_MULTI";
313 case STATE_EMIT_MSG_PACKET_END_SINGLE:
314 return "STATE_EMIT_MSG_PACKET_END_SINGLE";
315 case STATE_EMIT_MSG_STREAM_ACTIVITY_END:
316 return "STATE_EMIT_MSG_STREAM_ACTIVITY_END";
317 case STATE_EMIT_MSG_STREAM_END:
318 return "STATE_EMIT_MSG_STREAM_END";
319 case STATE_DONE:
320 return "STATE_DONE";
fdf0e7a0
PP
321 default:
322 return "(unknown)";
323 }
324}
325
2cf1d51e 326static
d6e69534 327int bt_msg_iter_switch_packet(struct bt_msg_iter *notit);
2cf1d51e 328
e98a2d6e 329static
d6e69534 330struct stack *stack_new(struct bt_msg_iter *notit)
e98a2d6e
PP
331{
332 struct stack *stack = NULL;
333
334 stack = g_new0(struct stack, 1);
335 if (!stack) {
eb7f6c4f 336 BT_COMP_LOGE_STR("Failed to allocate one stack.");
e98a2d6e
PP
337 goto error;
338 }
339
ea14c7dd 340 stack->notit = notit;
afe86a06 341 stack->entries = g_array_new(FALSE, TRUE, sizeof(struct stack_entry));
e98a2d6e 342 if (!stack->entries) {
eb7f6c4f 343 BT_COMP_LOGE_STR("Failed to allocate a GArray.");
e98a2d6e
PP
344 goto error;
345 }
346
eb7f6c4f 347 BT_COMP_LOGD("Created stack: notit-addr=%p, stack-addr=%p", notit, stack);
44c440bc 348 goto end;
fdf0e7a0 349
e98a2d6e
PP
350error:
351 g_free(stack);
44c440bc
PP
352 stack = NULL;
353
354end:
355 return stack;
e98a2d6e
PP
356}
357
358static
359void stack_destroy(struct stack *stack)
360{
ea14c7dd
PP
361 struct bt_msg_iter *notit;
362
f6ccaed9 363 BT_ASSERT(stack);
ea14c7dd 364 notit = stack->notit;
eb7f6c4f 365 BT_COMP_LOGD("Destroying stack: addr=%p", stack);
afe86a06
PP
366
367 if (stack->entries) {
368 g_array_free(stack->entries, TRUE);
369 }
370
e98a2d6e
PP
371 g_free(stack);
372}
373
374static
b19ff26f 375void stack_push(struct stack *stack, bt_field *base)
e98a2d6e 376{
e98a2d6e 377 struct stack_entry *entry;
ea14c7dd 378 struct bt_msg_iter *notit;
e98a2d6e 379
f6ccaed9 380 BT_ASSERT(stack);
ea14c7dd 381 notit = stack->notit;
f6ccaed9 382 BT_ASSERT(base);
ef267d12 383 BT_COMP_LOGT("Pushing base field on stack: stack-addr=%p, "
afe86a06
PP
384 "stack-size-before=%zu, stack-size-after=%zu",
385 stack, stack->size, stack->size + 1);
386
387 if (stack->entries->len == stack->size) {
388 g_array_set_size(stack->entries, stack->size + 1);
e98a2d6e
PP
389 }
390
afe86a06 391 entry = &g_array_index(stack->entries, struct stack_entry, stack->size);
312c056a 392 entry->base = base;
afe86a06
PP
393 entry->index = 0;
394 stack->size++;
e98a2d6e
PP
395}
396
397static inline
398unsigned int stack_size(struct stack *stack)
399{
f6ccaed9 400 BT_ASSERT(stack);
afe86a06 401 return stack->size;
e98a2d6e
PP
402}
403
404static
405void stack_pop(struct stack *stack)
406{
ea14c7dd
PP
407 struct bt_msg_iter *notit;
408
f6ccaed9
PP
409 BT_ASSERT(stack);
410 BT_ASSERT(stack_size(stack));
ea14c7dd 411 notit = stack->notit;
ef267d12 412 BT_COMP_LOGT("Popping from stack: "
afe86a06
PP
413 "stack-addr=%p, stack-size-before=%zu, stack-size-after=%zu",
414 stack, stack->size, stack->size - 1);
415 stack->size--;
e98a2d6e
PP
416}
417
418static inline
419struct stack_entry *stack_top(struct stack *stack)
420{
f6ccaed9
PP
421 BT_ASSERT(stack);
422 BT_ASSERT(stack_size(stack));
afe86a06
PP
423 return &g_array_index(stack->entries, struct stack_entry,
424 stack->size - 1);
e98a2d6e
PP
425}
426
427static inline
428bool stack_empty(struct stack *stack)
429{
430 return stack_size(stack) == 0;
431}
432
433static
434void stack_clear(struct stack *stack)
435{
f6ccaed9 436 BT_ASSERT(stack);
afe86a06 437 stack->size = 0;
e98a2d6e
PP
438}
439
440static inline
d6e69534
PP
441enum bt_msg_iter_status msg_iter_status_from_m_status(
442 enum bt_msg_iter_medium_status m_status)
e98a2d6e 443{
44c440bc 444 /* They are the same */
dc77b521 445 return (int) m_status;
e98a2d6e
PP
446}
447
448static inline
d6e69534 449size_t buf_size_bits(struct bt_msg_iter *notit)
e98a2d6e 450{
fdf0e7a0 451 return notit->buf.sz * 8;
e98a2d6e
PP
452}
453
454static inline
d6e69534 455size_t buf_available_bits(struct bt_msg_iter *notit)
e98a2d6e
PP
456{
457 return buf_size_bits(notit) - notit->buf.at;
458}
459
460static inline
d6e69534 461size_t packet_at(struct bt_msg_iter *notit)
e98a2d6e
PP
462{
463 return notit->buf.packet_offset + notit->buf.at;
464}
465
e98a2d6e 466static inline
d6e69534 467void buf_consume_bits(struct bt_msg_iter *notit, size_t incr)
e98a2d6e 468{
ef267d12 469 BT_COMP_LOGT("Advancing cursor: notit-addr=%p, cur-before=%zu, cur-after=%zu",
fdf0e7a0 470 notit, notit->buf.at, notit->buf.at + incr);
e98a2d6e
PP
471 notit->buf.at += incr;
472}
473
e98a2d6e 474static
d6e69534
PP
475enum bt_msg_iter_status request_medium_bytes(
476 struct bt_msg_iter *notit)
e98a2d6e 477{
fdf0e7a0
PP
478 uint8_t *buffer_addr = NULL;
479 size_t buffer_sz = 0;
d6e69534 480 enum bt_msg_iter_medium_status m_status;
e98a2d6e 481
eb7f6c4f 482 BT_COMP_LOGD("Calling user function (request bytes): notit-addr=%p, "
fdf0e7a0 483 "request-size=%zu", notit, notit->medium.max_request_sz);
e98a2d6e
PP
484 m_status = notit->medium.medops.request_bytes(
485 notit->medium.max_request_sz, &buffer_addr,
486 &buffer_sz, notit->medium.data);
eb7f6c4f 487 BT_COMP_LOGD("User function returned: status=%s, buf-addr=%p, buf-size=%zu",
d6e69534 488 bt_msg_iter_medium_status_string(m_status),
fdf0e7a0 489 buffer_addr, buffer_sz);
d6e69534 490 if (m_status == BT_MSG_ITER_MEDIUM_STATUS_OK) {
f6ccaed9 491 BT_ASSERT(buffer_sz != 0);
e98a2d6e
PP
492
493 /* New packet offset is old one + old size (in bits) */
494 notit->buf.packet_offset += buf_size_bits(notit);
495
496 /* Restart at the beginning of the new medium buffer */
497 notit->buf.at = 0;
2b186c3e 498 notit->buf.last_eh_at = SIZE_MAX;
e98a2d6e
PP
499
500 /* New medium buffer size */
501 notit->buf.sz = buffer_sz;
502
503 /* New medium buffer address */
504 notit->buf.addr = buffer_addr;
fdf0e7a0 505
eb7f6c4f 506 BT_COMP_LOGD("User function returned new bytes: "
fdf0e7a0
PP
507 "packet-offset=%zu, cur=%zu, size=%zu, addr=%p",
508 notit->buf.packet_offset, notit->buf.at,
509 notit->buf.sz, notit->buf.addr);
eb7f6c4f 510 BT_COMP_LOGD_MEM(buffer_addr, buffer_sz, "Returned bytes at %p:",
fdf0e7a0 511 buffer_addr);
d6e69534 512 } else if (m_status == BT_MSG_ITER_MEDIUM_STATUS_EOF) {
0684124b
PP
513 /*
514 * User returned end of stream: validate that we're not
515 * in the middle of a packet header, packet context, or
516 * event.
517 */
44c440bc
PP
518 if (notit->cur_exp_packet_total_size >= 0) {
519 if (packet_at(notit) ==
520 notit->cur_exp_packet_total_size) {
df0139b8 521 goto end;
0684124b 522 }
df0139b8
PP
523 } else {
524 if (packet_at(notit) == 0) {
525 goto end;
0684124b 526 }
0684124b 527
df0139b8
PP
528 if (notit->buf.last_eh_at != SIZE_MAX &&
529 notit->buf.at == notit->buf.last_eh_at) {
530 goto end;
0684124b
PP
531 }
532 }
533
0684124b 534 /* All other states are invalid */
eb7f6c4f 535 BT_COMP_LOGW("User function returned %s, but message iterator is in an unexpected state: "
df0139b8
PP
536 "state=%s, cur-packet-size=%" PRId64 ", cur=%zu, "
537 "packet-cur=%zu, last-eh-at=%zu",
d6e69534 538 bt_msg_iter_medium_status_string(m_status),
df0139b8 539 state_string(notit->state),
44c440bc 540 notit->cur_exp_packet_total_size,
df0139b8
PP
541 notit->buf.at, packet_at(notit),
542 notit->buf.last_eh_at);
d6e69534 543 m_status = BT_MSG_ITER_MEDIUM_STATUS_ERROR;
fdf0e7a0 544 } else if (m_status < 0) {
eb7f6c4f 545 BT_COMP_LOGW("User function failed: status=%s",
d6e69534 546 bt_msg_iter_medium_status_string(m_status));
e98a2d6e
PP
547 }
548
df0139b8 549end:
d6e69534 550 return msg_iter_status_from_m_status(m_status);
e98a2d6e
PP
551}
552
553static inline
d6e69534
PP
554enum bt_msg_iter_status buf_ensure_available_bits(
555 struct bt_msg_iter *notit)
e98a2d6e 556{
d6e69534 557 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
e98a2d6e 558
91d81473 559 if (G_UNLIKELY(buf_available_bits(notit) == 0)) {
e98a2d6e 560 /*
d6e69534 561 * This _cannot_ return BT_MSG_ITER_STATUS_OK
e98a2d6e
PP
562 * _and_ no bits.
563 */
564 status = request_medium_bytes(notit);
565 }
566
567 return status;
568}
569
570static
d6e69534
PP
571enum bt_msg_iter_status read_dscope_begin_state(
572 struct bt_msg_iter *notit,
5cd6d0e5 573 struct ctf_field_class *dscope_fc,
e98a2d6e 574 enum state done_state, enum state continue_state,
b19ff26f 575 bt_field *dscope_field)
e98a2d6e 576{
d6e69534 577 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 578 enum bt_bfcr_status bfcr_status;
e98a2d6e
PP
579 size_t consumed_bits;
580
e98a2d6e 581 notit->cur_dscope_field = dscope_field;
ef267d12 582 BT_COMP_LOGT("Starting BFCR: notit-addr=%p, bfcr-addr=%p, fc-addr=%p",
5cd6d0e5
PP
583 notit, notit->bfcr, dscope_fc);
584 consumed_bits = bt_bfcr_start(notit->bfcr, dscope_fc,
e98a2d6e 585 notit->buf.addr, notit->buf.at, packet_at(notit),
5cd6d0e5 586 notit->buf.sz, &bfcr_status);
ef267d12 587 BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits);
e98a2d6e 588
5cd6d0e5
PP
589 switch (bfcr_status) {
590 case BT_BFCR_STATUS_OK:
591 /* Field class was read completely */
ef267d12 592 BT_COMP_LOGT_STR("Field was completely decoded.");
e98a2d6e
PP
593 notit->state = done_state;
594 break;
5cd6d0e5 595 case BT_BFCR_STATUS_EOF:
ef267d12 596 BT_COMP_LOGT_STR("BFCR needs more data to decode field completely.");
e98a2d6e
PP
597 notit->state = continue_state;
598 break;
599 default:
eb7f6c4f 600 BT_COMP_LOGW("BFCR failed to start: notit-addr=%p, bfcr-addr=%p, "
5cd6d0e5
PP
601 "status=%s", notit, notit->bfcr,
602 bt_bfcr_status_string(bfcr_status));
d6e69534 603 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e
PP
604 goto end;
605 }
606
607 /* Consume bits now since we know we're not in an error state */
608 buf_consume_bits(notit, consumed_bits);
609
610end:
611 return status;
612}
613
614static
d6e69534
PP
615enum bt_msg_iter_status read_dscope_continue_state(
616 struct bt_msg_iter *notit, enum state done_state)
e98a2d6e 617{
d6e69534 618 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 619 enum bt_bfcr_status bfcr_status;
e98a2d6e
PP
620 size_t consumed_bits;
621
ef267d12 622 BT_COMP_LOGT("Continuing BFCR: notit-addr=%p, bfcr-addr=%p",
5cd6d0e5 623 notit, notit->bfcr);
df0139b8 624
e98a2d6e 625 status = buf_ensure_available_bits(notit);
d6e69534 626 if (status != BT_MSG_ITER_STATUS_OK) {
fdf0e7a0 627 if (status < 0) {
eb7f6c4f 628 BT_COMP_LOGW("Cannot ensure that buffer has at least one byte: "
d6e69534
PP
629 "msg-addr=%p, status=%s",
630 notit, bt_msg_iter_status_string(status));
fdf0e7a0 631 } else {
ef267d12 632 BT_COMP_LOGT("Cannot ensure that buffer has at least one byte: "
d6e69534
PP
633 "msg-addr=%p, status=%s",
634 notit, bt_msg_iter_status_string(status));
fdf0e7a0
PP
635 }
636
e98a2d6e
PP
637 goto end;
638 }
639
5cd6d0e5
PP
640 consumed_bits = bt_bfcr_continue(notit->bfcr, notit->buf.addr,
641 notit->buf.sz, &bfcr_status);
ef267d12 642 BT_COMP_LOGT("BFCR consumed bits: size=%zu", consumed_bits);
e98a2d6e 643
5cd6d0e5
PP
644 switch (bfcr_status) {
645 case BT_BFCR_STATUS_OK:
78586d8a 646 /* Type was read completely. */
ef267d12 647 BT_COMP_LOGT_STR("Field was completely decoded.");
e98a2d6e
PP
648 notit->state = done_state;
649 break;
5cd6d0e5 650 case BT_BFCR_STATUS_EOF:
78586d8a 651 /* Stay in this continue state. */
ef267d12 652 BT_COMP_LOGT_STR("BFCR needs more data to decode field completely.");
e98a2d6e
PP
653 break;
654 default:
eb7f6c4f 655 BT_COMP_LOGW("BFCR failed to continue: notit-addr=%p, bfcr-addr=%p, "
5cd6d0e5
PP
656 "status=%s", notit, notit->bfcr,
657 bt_bfcr_status_string(bfcr_status));
d6e69534 658 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e
PP
659 goto end;
660 }
661
78586d8a 662 /* Consume bits now since we know we're not in an error state. */
e98a2d6e 663 buf_consume_bits(notit, consumed_bits);
e98a2d6e
PP
664end:
665 return status;
666}
667
668static
d6e69534 669void release_event_dscopes(struct bt_msg_iter *notit)
e98a2d6e 670{
44c440bc
PP
671 notit->dscopes.event_common_context = NULL;
672 notit->dscopes.event_spec_context = NULL;
312c056a 673 notit->dscopes.event_payload = NULL;
e98a2d6e
PP
674}
675
676static
d6e69534 677void release_all_dscopes(struct bt_msg_iter *notit)
e98a2d6e 678{
312c056a
PP
679 notit->dscopes.stream_packet_context = NULL;
680
681 if (notit->packet_context_field) {
40f4ba76 682 bt_packet_context_field_release(notit->packet_context_field);
312c056a
PP
683 notit->packet_context_field = NULL;
684 }
685
686 release_event_dscopes(notit);
e98a2d6e
PP
687}
688
689static
d6e69534
PP
690enum bt_msg_iter_status read_packet_header_begin_state(
691 struct bt_msg_iter *notit)
e98a2d6e 692{
5cd6d0e5 693 struct ctf_field_class *packet_header_fc = NULL;
d6e69534 694 enum bt_msg_iter_status ret = BT_MSG_ITER_STATUS_OK;
e98a2d6e 695
d6e69534 696 if (bt_msg_iter_switch_packet(notit)) {
eb7f6c4f 697 BT_COMP_LOGW("Cannot switch packet: notit-addr=%p", notit);
d6e69534 698 ret = BT_MSG_ITER_STATUS_ERROR;
2cf1d51e
JG
699 goto end;
700 }
e98a2d6e 701
fc917f65
PP
702 /*
703 * Make sure at least one bit is available for this packet. An
704 * empty packet is impossible. If we reach the end of the medium
705 * at this point, then it's considered the end of the stream.
706 */
707 ret = buf_ensure_available_bits(notit);
708 switch (ret) {
709 case BT_MSG_ITER_STATUS_OK:
710 break;
711 case BT_MSG_ITER_STATUS_EOF:
712 ret = BT_MSG_ITER_STATUS_OK;
495490c5 713 notit->state = STATE_CHECK_EMIT_MSG_STREAM_ACTIVITY_END;
fc917f65
PP
714 goto end;
715 default:
716 goto end;
717 }
718
862ca4ed 719 /* Packet header class is common to the whole trace class. */
5cd6d0e5
PP
720 packet_header_fc = notit->meta.tc->packet_header_fc;
721 if (!packet_header_fc) {
835b2d10 722 notit->state = STATE_AFTER_TRACE_PACKET_HEADER;
e98a2d6e
PP
723 goto end;
724 }
725
44c440bc
PP
726 notit->cur_stream_class_id = -1;
727 notit->cur_event_class_id = -1;
728 notit->cur_data_stream_id = -1;
eb7f6c4f 729 BT_COMP_LOGD("Decoding packet header field:"
862ca4ed
PP
730 "notit-addr=%p, trace-class-addr=%p, fc-addr=%p",
731 notit, notit->meta.tc, packet_header_fc);
5cd6d0e5 732 ret = read_dscope_begin_state(notit, packet_header_fc,
fdf0e7a0 733 STATE_AFTER_TRACE_PACKET_HEADER,
83ebb7f1 734 STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE, NULL);
fdf0e7a0 735 if (ret < 0) {
eb7f6c4f 736 BT_COMP_LOGW("Cannot decode packet header field: "
862ca4ed
PP
737 "notit-addr=%p, trace-class-addr=%p, "
738 "fc-addr=%p",
739 notit, notit->meta.tc, packet_header_fc);
fdf0e7a0 740 }
d1e46835 741
e98a2d6e 742end:
2cf1d51e 743 return ret;
e98a2d6e
PP
744}
745
746static
d6e69534
PP
747enum bt_msg_iter_status read_packet_header_continue_state(
748 struct bt_msg_iter *notit)
e98a2d6e
PP
749{
750 return read_dscope_continue_state(notit,
44c440bc 751 STATE_AFTER_TRACE_PACKET_HEADER);
5f870343
JG
752}
753
e98a2d6e 754static inline
d6e69534 755enum bt_msg_iter_status set_current_stream_class(struct bt_msg_iter *notit)
e98a2d6e 756{
d6e69534 757 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
44c440bc
PP
758 struct ctf_stream_class *new_stream_class = NULL;
759
760 if (notit->cur_stream_class_id == -1) {
fdf0e7a0 761 /*
44c440bc
PP
762 * No current stream class ID field, therefore only one
763 * stream class.
fdf0e7a0 764 */
44c440bc 765 if (notit->meta.tc->stream_classes->len != 1) {
eb7f6c4f 766 BT_COMP_LOGW("Need exactly one stream class since there's "
44c440bc 767 "no stream class ID field: "
862ca4ed 768 "notit-addr=%p", notit);
d6e69534 769 status = BT_MSG_ITER_STATUS_ERROR;
44c440bc
PP
770 goto end;
771 }
e98a2d6e 772
44c440bc
PP
773 new_stream_class = notit->meta.tc->stream_classes->pdata[0];
774 notit->cur_stream_class_id = new_stream_class->id;
e98a2d6e
PP
775 }
776
44c440bc
PP
777 new_stream_class = ctf_trace_class_borrow_stream_class_by_id(
778 notit->meta.tc, notit->cur_stream_class_id);
115de887 779 if (!new_stream_class) {
eb7f6c4f 780 BT_COMP_LOGW("No stream class with ID of stream class ID to use in trace class: "
fdf0e7a0 781 "notit-addr=%p, stream-class-id=%" PRIu64 ", "
862ca4ed
PP
782 "trace-class-addr=%p",
783 notit, notit->cur_stream_class_id, notit->meta.tc);
d6e69534 784 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e
PP
785 goto end;
786 }
787
44c440bc
PP
788 if (notit->meta.sc) {
789 if (new_stream_class != notit->meta.sc) {
eb7f6c4f 790 BT_COMP_LOGW("Two packets refer to two different stream classes within the same packet sequence: "
115de887 791 "notit-addr=%p, prev-stream-class-addr=%p, "
115de887
PP
792 "prev-stream-class-id=%" PRId64 ", "
793 "next-stream-class-addr=%p, "
115de887 794 "next-stream-class-id=%" PRId64 ", "
862ca4ed 795 "trace-addr=%p",
44c440bc
PP
796 notit, notit->meta.sc,
797 notit->meta.sc->id,
115de887 798 new_stream_class,
44c440bc 799 new_stream_class->id,
862ca4ed 800 notit->meta.tc);
d6e69534 801 status = BT_MSG_ITER_STATUS_ERROR;
115de887
PP
802 goto end;
803 }
804 } else {
44c440bc 805 notit->meta.sc = new_stream_class;
115de887
PP
806 }
807
eb7f6c4f 808 BT_COMP_LOGD("Set current stream class: "
fdf0e7a0 809 "notit-addr=%p, stream-class-addr=%p, "
44c440bc
PP
810 "stream-class-id=%" PRId64,
811 notit, notit->meta.sc, notit->meta.sc->id);
d1e46835 812
e98a2d6e 813end:
e98a2d6e
PP
814 return status;
815}
816
312c056a 817static inline
d6e69534 818enum bt_msg_iter_status set_current_stream(struct bt_msg_iter *notit)
312c056a 819{
d6e69534 820 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
b19ff26f 821 bt_stream *stream = NULL;
312c056a 822
eb7f6c4f 823 BT_COMP_LOGD("Calling user function (get stream): notit-addr=%p, "
44c440bc
PP
824 "stream-class-addr=%p, stream-class-id=%" PRId64,
825 notit, notit->meta.sc,
826 notit->meta.sc->id);
398454ed 827 stream = notit->medium.medops.borrow_stream(
44c440bc 828 notit->meta.sc->ir_sc, notit->cur_data_stream_id,
398454ed 829 notit->medium.data);
c5b9b441 830 bt_stream_get_ref(stream);
eb7f6c4f 831 BT_COMP_LOGD("User function returned: stream-addr=%p", stream);
312c056a 832 if (!stream) {
eb7f6c4f 833 BT_COMP_LOGW_STR("User function failed to return a stream object "
44c440bc 834 "for the given stream class.");
d6e69534 835 status = BT_MSG_ITER_STATUS_ERROR;
312c056a
PP
836 goto end;
837 }
838
839 if (notit->stream && stream != notit->stream) {
eb7f6c4f 840 BT_COMP_LOGW("User function returned a different stream than the "
44c440bc 841 "previous one for the same sequence of packets.");
d6e69534 842 status = BT_MSG_ITER_STATUS_ERROR;
312c056a
PP
843 goto end;
844 }
845
c5b9b441 846 BT_STREAM_MOVE_REF(notit->stream, stream);
312c056a
PP
847
848end:
c5b9b441 849 bt_stream_put_ref(stream);
312c056a
PP
850 return status;
851}
852
853static inline
d6e69534 854enum bt_msg_iter_status set_current_packet(struct bt_msg_iter *notit)
312c056a 855{
d6e69534 856 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
b19ff26f 857 bt_packet *packet = NULL;
312c056a 858
eb7f6c4f 859 BT_COMP_LOGD("Creating packet for packet message: "
312c056a 860 "notit-addr=%p", notit);
eb7f6c4f 861 BT_COMP_LOGD("Creating packet from stream: "
312c056a
PP
862 "notit-addr=%p, stream-addr=%p, "
863 "stream-class-addr=%p, "
312c056a 864 "stream-class-id=%" PRId64,
44c440bc
PP
865 notit, notit->stream, notit->meta.sc,
866 notit->meta.sc->id);
312c056a
PP
867
868 /* Create packet */
869 BT_ASSERT(notit->stream);
40f4ba76 870 packet = bt_packet_create(notit->stream);
312c056a 871 if (!packet) {
eb7f6c4f 872 BT_COMP_LOGE("Cannot create packet from stream: "
312c056a
PP
873 "notit-addr=%p, stream-addr=%p, "
874 "stream-class-addr=%p, "
312c056a 875 "stream-class-id=%" PRId64,
44c440bc
PP
876 notit, notit->stream, notit->meta.sc,
877 notit->meta.sc->id);
312c056a
PP
878 goto error;
879 }
880
881 goto end;
882
883error:
c5b9b441 884 BT_PACKET_PUT_REF_AND_RESET(packet);
d6e69534 885 status = BT_MSG_ITER_STATUS_ERROR;
312c056a
PP
886
887end:
c5b9b441 888 BT_PACKET_MOVE_REF(notit->packet, packet);
312c056a
PP
889 return status;
890}
891
e98a2d6e 892static
d6e69534
PP
893enum bt_msg_iter_status after_packet_header_state(
894 struct bt_msg_iter *notit)
e98a2d6e 895{
d6e69534 896 enum bt_msg_iter_status status;
e98a2d6e
PP
897
898 status = set_current_stream_class(notit);
d6e69534 899 if (status != BT_MSG_ITER_STATUS_OK) {
312c056a 900 goto end;
e98a2d6e
PP
901 }
902
312c056a
PP
903 notit->state = STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN;
904
905end:
e98a2d6e
PP
906 return status;
907}
908
909static
d6e69534
PP
910enum bt_msg_iter_status read_packet_context_begin_state(
911 struct bt_msg_iter *notit)
e98a2d6e 912{
d6e69534 913 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 914 struct ctf_field_class *packet_context_fc;
e98a2d6e 915
44c440bc 916 BT_ASSERT(notit->meta.sc);
5cd6d0e5
PP
917 packet_context_fc = notit->meta.sc->packet_context_fc;
918 if (!packet_context_fc) {
eb7f6c4f 919 BT_COMP_LOGD("No packet packet context field class in stream class: continuing: "
fdf0e7a0 920 "notit-addr=%p, stream-class-addr=%p, "
44c440bc
PP
921 "stream-class-id=%" PRId64,
922 notit, notit->meta.sc,
923 notit->meta.sc->id);
835b2d10 924 notit->state = STATE_AFTER_STREAM_PACKET_CONTEXT;
e98a2d6e
PP
925 goto end;
926 }
927
312c056a 928 BT_ASSERT(!notit->packet_context_field);
44c440bc 929
5cd6d0e5 930 if (packet_context_fc->in_ir) {
44c440bc
PP
931 /*
932 * Create free packet context field from stream class.
933 * This field is going to be moved to the packet once we
934 * create it. We cannot create the packet now because a
935 * packet is created from a stream, and this API must be
83ebb7f1
PP
936 * able to return the packet context properties without
937 * creating a stream
938 * (bt_msg_iter_get_packet_properties()).
44c440bc
PP
939 */
940 notit->packet_context_field =
40f4ba76 941 bt_packet_context_field_create(
e5be10ef 942 notit->meta.sc->ir_sc);
44c440bc 943 if (!notit->packet_context_field) {
eb7f6c4f 944 BT_COMP_LOGE_STR("Cannot create packet context field wrapper from stream class.");
d6e69534 945 status = BT_MSG_ITER_STATUS_ERROR;
44c440bc
PP
946 goto end;
947 }
948
949 notit->dscopes.stream_packet_context =
40f4ba76 950 bt_packet_context_field_borrow_field(
e5be10ef 951 notit->packet_context_field);
44c440bc 952 BT_ASSERT(notit->dscopes.stream_packet_context);
312c056a
PP
953 }
954
eb7f6c4f 955 BT_COMP_LOGD("Decoding packet context field: "
fdf0e7a0 956 "notit-addr=%p, stream-class-addr=%p, "
5cd6d0e5 957 "stream-class-id=%" PRId64 ", fc-addr=%p",
44c440bc 958 notit, notit->meta.sc,
5cd6d0e5
PP
959 notit->meta.sc->id, packet_context_fc);
960 status = read_dscope_begin_state(notit, packet_context_fc,
fdf0e7a0
PP
961 STATE_AFTER_STREAM_PACKET_CONTEXT,
962 STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
312c056a 963 notit->dscopes.stream_packet_context);
fdf0e7a0 964 if (status < 0) {
eb7f6c4f 965 BT_COMP_LOGW("Cannot decode packet context field: "
fdf0e7a0 966 "notit-addr=%p, stream-class-addr=%p, "
5cd6d0e5 967 "stream-class-id=%" PRId64 ", fc-addr=%p",
44c440bc
PP
968 notit, notit->meta.sc,
969 notit->meta.sc->id,
5cd6d0e5 970 packet_context_fc);
fdf0e7a0 971 }
e98a2d6e
PP
972
973end:
e98a2d6e
PP
974 return status;
975}
976
977static
d6e69534
PP
978enum bt_msg_iter_status read_packet_context_continue_state(
979 struct bt_msg_iter *notit)
e98a2d6e
PP
980{
981 return read_dscope_continue_state(notit,
78586d8a 982 STATE_AFTER_STREAM_PACKET_CONTEXT);
e98a2d6e
PP
983}
984
78586d8a 985static
d6e69534
PP
986enum bt_msg_iter_status set_current_packet_content_sizes(
987 struct bt_msg_iter *notit)
e98a2d6e 988{
d6e69534 989 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
e98a2d6e 990
44c440bc
PP
991 if (notit->cur_exp_packet_total_size == -1) {
992 if (notit->cur_exp_packet_content_size != -1) {
01f71e30
PP
993 notit->cur_exp_packet_total_size =
994 notit->cur_exp_packet_content_size;
e98a2d6e 995 }
e98a2d6e 996 } else {
44c440bc
PP
997 if (notit->cur_exp_packet_content_size == -1) {
998 notit->cur_exp_packet_content_size =
999 notit->cur_exp_packet_total_size;
1000 }
e98a2d6e
PP
1001 }
1002
9067de2b
PP
1003 BT_ASSERT((notit->cur_exp_packet_total_size >= 0 &&
1004 notit->cur_exp_packet_content_size >= 0) ||
1005 (notit->cur_exp_packet_total_size < 0 &&
1006 notit->cur_exp_packet_content_size < 0));
01f71e30 1007
44c440bc
PP
1008 if (notit->cur_exp_packet_content_size >
1009 notit->cur_exp_packet_total_size) {
eb7f6c4f 1010 BT_COMP_LOGW("Invalid packet or content size: "
44c440bc 1011 "content size is greater than packet size: "
fdf0e7a0 1012 "notit-addr=%p, packet-context-field-addr=%p, "
44c440bc 1013 "packet-size=%" PRId64 ", content-size=%" PRId64,
fdf0e7a0 1014 notit, notit->dscopes.stream_packet_context,
44c440bc
PP
1015 notit->cur_exp_packet_total_size,
1016 notit->cur_exp_packet_content_size);
d6e69534 1017 status = BT_MSG_ITER_STATUS_ERROR;
fdf0e7a0
PP
1018 goto end;
1019 }
1020
eb7f6c4f 1021 BT_COMP_LOGD("Set current packet and content sizes: "
fdf0e7a0 1022 "notit-addr=%p, packet-size=%" PRIu64 ", content-size=%" PRIu64,
44c440bc
PP
1023 notit, notit->cur_exp_packet_total_size,
1024 notit->cur_exp_packet_content_size);
fc917f65 1025
e98a2d6e 1026end:
e98a2d6e
PP
1027 return status;
1028}
1029
1030static
fc917f65 1031enum bt_msg_iter_status after_packet_context_state(struct bt_msg_iter *notit)
e98a2d6e 1032{
d6e69534 1033 enum bt_msg_iter_status status;
e98a2d6e
PP
1034
1035 status = set_current_packet_content_sizes(notit);
d6e69534 1036 if (status != BT_MSG_ITER_STATUS_OK) {
e22b45d0
PP
1037 goto end;
1038 }
1039
fc917f65
PP
1040 if (notit->stream) {
1041 /*
1042 * Stream exists, which means we already emitted at
1043 * least one packet beginning message, so the initial
1044 * stream beginning message was also emitted.
1045 */
495490c5 1046 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
e22b45d0 1047 } else {
495490c5 1048 notit->state = STATE_CHECK_EMIT_MSG_STREAM_BEGINNING;
e98a2d6e
PP
1049 }
1050
e22b45d0 1051end:
e98a2d6e
PP
1052 return status;
1053}
1054
1055static
fc917f65 1056enum bt_msg_iter_status read_event_header_begin_state(struct bt_msg_iter *notit)
e98a2d6e 1057{
d6e69534 1058 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 1059 struct ctf_field_class *event_header_fc = NULL;
e98a2d6e 1060
174e773b
PP
1061 /* Reset the position of the last event header */
1062 notit->buf.last_eh_at = notit->buf.at;
44c440bc 1063 notit->cur_event_class_id = -1;
174e773b 1064
e98a2d6e 1065 /* Check if we have some content left */
44c440bc 1066 if (notit->cur_exp_packet_content_size >= 0) {
91d81473 1067 if (G_UNLIKELY(packet_at(notit) ==
44c440bc 1068 notit->cur_exp_packet_content_size)) {
e98a2d6e 1069 /* No more events! */
eb7f6c4f 1070 BT_COMP_LOGD("Reached end of packet: notit-addr=%p, "
fdf0e7a0 1071 "cur=%zu", notit, packet_at(notit));
fc917f65 1072 notit->state = STATE_EMIT_MSG_PACKET_END_MULTI;
e98a2d6e 1073 goto end;
91d81473 1074 } else if (G_UNLIKELY(packet_at(notit) >
44c440bc 1075 notit->cur_exp_packet_content_size)) {
e98a2d6e 1076 /* That's not supposed to happen */
eb7f6c4f 1077 BT_COMP_LOGD("Before decoding event header field: cursor is passed the packet's content: "
1974687e 1078 "notit-addr=%p, content-size=%" PRId64 ", "
44c440bc
PP
1079 "cur=%zu", notit,
1080 notit->cur_exp_packet_content_size,
fdf0e7a0 1081 packet_at(notit));
d6e69534 1082 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e
PP
1083 goto end;
1084 }
44c440bc
PP
1085 } else {
1086 /*
1087 * "Infinite" content: we're done when the medium has
1088 * nothing else for us.
1089 */
1090 status = buf_ensure_available_bits(notit);
fc917f65
PP
1091 switch (status) {
1092 case BT_MSG_ITER_STATUS_OK:
1093 break;
1094 case BT_MSG_ITER_STATUS_EOF:
1095 status = BT_MSG_ITER_STATUS_OK;
1096 notit->state = STATE_EMIT_MSG_PACKET_END_SINGLE;
1097 goto end;
1098 default:
44c440bc
PP
1099 goto end;
1100 }
e98a2d6e
PP
1101 }
1102
312c056a 1103 release_event_dscopes(notit);
44c440bc 1104 BT_ASSERT(notit->meta.sc);
5cd6d0e5
PP
1105 event_header_fc = notit->meta.sc->event_header_fc;
1106 if (!event_header_fc) {
44c440bc 1107 notit->state = STATE_AFTER_EVENT_HEADER;
e98a2d6e
PP
1108 goto end;
1109 }
1110
eb7f6c4f 1111 BT_COMP_LOGD("Decoding event header field: "
fdf0e7a0 1112 "notit-addr=%p, stream-class-addr=%p, "
44c440bc 1113 "stream-class-id=%" PRId64 ", "
5cd6d0e5 1114 "fc-addr=%p",
44c440bc
PP
1115 notit, notit->meta.sc,
1116 notit->meta.sc->id,
5cd6d0e5
PP
1117 event_header_fc);
1118 status = read_dscope_begin_state(notit, event_header_fc,
44c440bc 1119 STATE_AFTER_EVENT_HEADER,
83ebb7f1 1120 STATE_DSCOPE_EVENT_HEADER_CONTINUE, NULL);
fdf0e7a0 1121 if (status < 0) {
eb7f6c4f 1122 BT_COMP_LOGW("Cannot decode event header field: "
fdf0e7a0 1123 "notit-addr=%p, stream-class-addr=%p, "
5cd6d0e5 1124 "stream-class-id=%" PRId64 ", fc-addr=%p",
44c440bc
PP
1125 notit, notit->meta.sc,
1126 notit->meta.sc->id,
5cd6d0e5 1127 event_header_fc);
fdf0e7a0 1128 }
e98a2d6e 1129
d1e46835 1130end:
e98a2d6e
PP
1131 return status;
1132}
1133
1134static
d6e69534
PP
1135enum bt_msg_iter_status read_event_header_continue_state(
1136 struct bt_msg_iter *notit)
e98a2d6e
PP
1137{
1138 return read_dscope_continue_state(notit,
44c440bc 1139 STATE_AFTER_EVENT_HEADER);
e98a2d6e
PP
1140}
1141
1142static inline
d6e69534 1143enum bt_msg_iter_status set_current_event_class(struct bt_msg_iter *notit)
e98a2d6e 1144{
d6e69534 1145 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
e98a2d6e 1146
44c440bc 1147 struct ctf_event_class *new_event_class = NULL;
e98a2d6e 1148
44c440bc 1149 if (notit->cur_event_class_id == -1) {
e98a2d6e 1150 /*
44c440bc
PP
1151 * No current event class ID field, therefore only one
1152 * event class.
e98a2d6e 1153 */
44c440bc 1154 if (notit->meta.sc->event_classes->len != 1) {
eb7f6c4f 1155 BT_COMP_LOGW("Need exactly one event class since there's "
44c440bc 1156 "no event class ID field: "
862ca4ed 1157 "notit-addr=%p", notit);
d6e69534 1158 status = BT_MSG_ITER_STATUS_ERROR;
44c440bc 1159 goto end;
fdf0e7a0 1160 }
e98a2d6e 1161
44c440bc
PP
1162 new_event_class = notit->meta.sc->event_classes->pdata[0];
1163 notit->cur_event_class_id = new_event_class->id;
e98a2d6e
PP
1164 }
1165
44c440bc
PP
1166 new_event_class = ctf_stream_class_borrow_event_class_by_id(
1167 notit->meta.sc, notit->cur_event_class_id);
1168 if (!new_event_class) {
eb7f6c4f 1169 BT_COMP_LOGW("No event class with ID of event class ID to use in stream class: "
44c440bc
PP
1170 "notit-addr=%p, stream-class-id=%" PRIu64 ", "
1171 "event-class-id=%" PRIu64 ", "
862ca4ed 1172 "trace-class-addr=%p",
44c440bc 1173 notit, notit->meta.sc->id, notit->cur_event_class_id,
862ca4ed 1174 notit->meta.tc);
d6e69534 1175 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e
PP
1176 goto end;
1177 }
1178
44c440bc 1179 notit->meta.ec = new_event_class;
eb7f6c4f 1180 BT_COMP_LOGD("Set current event class: "
fdf0e7a0 1181 "notit-addr=%p, event-class-addr=%p, "
44c440bc
PP
1182 "event-class-id=%" PRId64 ", "
1183 "event-class-name=\"%s\"",
1184 notit, notit->meta.ec, notit->meta.ec->id,
1185 notit->meta.ec->name->str);
fdf0e7a0 1186
e98a2d6e 1187end:
e98a2d6e
PP
1188 return status;
1189}
1190
312c056a 1191static inline
d6e69534
PP
1192enum bt_msg_iter_status set_current_event_message(
1193 struct bt_msg_iter *notit)
312c056a 1194{
d6e69534
PP
1195 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
1196 bt_message *msg = NULL;
312c056a 1197
44c440bc 1198 BT_ASSERT(notit->meta.ec);
312c056a 1199 BT_ASSERT(notit->packet);
eb7f6c4f 1200 BT_COMP_LOGD("Creating event message from event class and packet: "
312c056a 1201 "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", packet-addr=%p",
44c440bc
PP
1202 notit, notit->meta.ec,
1203 notit->meta.ec->name->str,
312c056a 1204 notit->packet);
d6e69534 1205 BT_ASSERT(notit->msg_iter);
2c091c04
PP
1206 BT_ASSERT(notit->meta.sc);
1207
1208 if (bt_stream_class_borrow_default_clock_class(notit->meta.sc->ir_sc)) {
1209 msg = bt_message_event_create_with_default_clock_snapshot(
1210 notit->msg_iter, notit->meta.ec->ir_ec,
1211 notit->packet, notit->default_clock_snapshot);
1212 } else {
1213 msg = bt_message_event_create(notit->msg_iter,
1214 notit->meta.ec->ir_ec, notit->packet);
1215 }
1216
d6e69534 1217 if (!msg) {
eb7f6c4f 1218 BT_COMP_LOGE("Cannot create event message: "
312c056a
PP
1219 "notit-addr=%p, ec-addr=%p, ec-name=\"%s\", "
1220 "packet-addr=%p",
44c440bc
PP
1221 notit, notit->meta.ec,
1222 notit->meta.ec->name->str,
312c056a
PP
1223 notit->packet);
1224 goto error;
1225 }
1226
1227 goto end;
1228
1229error:
d6e69534
PP
1230 BT_MESSAGE_PUT_REF_AND_RESET(msg);
1231 status = BT_MSG_ITER_STATUS_ERROR;
312c056a
PP
1232
1233end:
d6e69534 1234 BT_MESSAGE_MOVE_REF(notit->event_msg, msg);
312c056a
PP
1235 return status;
1236}
1237
e98a2d6e 1238static
d6e69534
PP
1239enum bt_msg_iter_status after_event_header_state(
1240 struct bt_msg_iter *notit)
e98a2d6e 1241{
d6e69534 1242 enum bt_msg_iter_status status;
e98a2d6e 1243
e98a2d6e 1244 status = set_current_event_class(notit);
d6e69534 1245 if (status != BT_MSG_ITER_STATUS_OK) {
e98a2d6e
PP
1246 goto end;
1247 }
1248
d6e69534
PP
1249 status = set_current_event_message(notit);
1250 if (status != BT_MSG_ITER_STATUS_OK) {
312c056a
PP
1251 goto end;
1252 }
1253
d6e69534
PP
1254 notit->event = bt_message_event_borrow_event(
1255 notit->event_msg);
312c056a 1256 BT_ASSERT(notit->event);
44c440bc 1257 notit->state = STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN;
e98a2d6e
PP
1258
1259end:
1260 return status;
1261}
1262
1263static
d6e69534
PP
1264enum bt_msg_iter_status read_event_common_context_begin_state(
1265 struct bt_msg_iter *notit)
e98a2d6e 1266{
d6e69534 1267 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 1268 struct ctf_field_class *event_common_context_fc;
e98a2d6e 1269
5cd6d0e5
PP
1270 event_common_context_fc = notit->meta.sc->event_common_context_fc;
1271 if (!event_common_context_fc) {
44c440bc 1272 notit->state = STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN;
e98a2d6e
PP
1273 goto end;
1274 }
1275
5cd6d0e5 1276 if (event_common_context_fc->in_ir) {
44c440bc
PP
1277 BT_ASSERT(!notit->dscopes.event_common_context);
1278 notit->dscopes.event_common_context =
40f4ba76 1279 bt_event_borrow_common_context_field(
e5be10ef 1280 notit->event);
44c440bc
PP
1281 BT_ASSERT(notit->dscopes.event_common_context);
1282 }
1283
ef267d12 1284 BT_COMP_LOGT("Decoding event common context field: "
fdf0e7a0 1285 "notit-addr=%p, stream-class-addr=%p, "
44c440bc 1286 "stream-class-id=%" PRId64 ", "
5cd6d0e5 1287 "fc-addr=%p",
44c440bc
PP
1288 notit, notit->meta.sc,
1289 notit->meta.sc->id,
5cd6d0e5
PP
1290 event_common_context_fc);
1291 status = read_dscope_begin_state(notit, event_common_context_fc,
44c440bc
PP
1292 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN,
1293 STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE,
1294 notit->dscopes.event_common_context);
fdf0e7a0 1295 if (status < 0) {
eb7f6c4f 1296 BT_COMP_LOGW("Cannot decode event common context field: "
fdf0e7a0 1297 "notit-addr=%p, stream-class-addr=%p, "
5cd6d0e5 1298 "stream-class-id=%" PRId64 ", fc-addr=%p",
44c440bc
PP
1299 notit, notit->meta.sc,
1300 notit->meta.sc->id,
5cd6d0e5 1301 event_common_context_fc);
fdf0e7a0 1302 }
e98a2d6e
PP
1303
1304end:
e98a2d6e
PP
1305 return status;
1306}
1307
1308static
d6e69534
PP
1309enum bt_msg_iter_status read_event_common_context_continue_state(
1310 struct bt_msg_iter *notit)
e98a2d6e
PP
1311{
1312 return read_dscope_continue_state(notit,
44c440bc 1313 STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN);
e98a2d6e
PP
1314}
1315
1316static
d6e69534
PP
1317enum bt_msg_iter_status read_event_spec_context_begin_state(
1318 struct bt_msg_iter *notit)
e98a2d6e 1319{
d6e69534 1320 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 1321 struct ctf_field_class *event_spec_context_fc;
e98a2d6e 1322
5cd6d0e5
PP
1323 event_spec_context_fc = notit->meta.ec->spec_context_fc;
1324 if (!event_spec_context_fc) {
835b2d10 1325 notit->state = STATE_DSCOPE_EVENT_PAYLOAD_BEGIN;
e98a2d6e
PP
1326 goto end;
1327 }
fdf0e7a0 1328
5cd6d0e5 1329 if (event_spec_context_fc->in_ir) {
44c440bc 1330 BT_ASSERT(!notit->dscopes.event_spec_context);
e5be10ef 1331 notit->dscopes.event_spec_context =
40f4ba76 1332 bt_event_borrow_specific_context_field(
e5be10ef 1333 notit->event);
44c440bc
PP
1334 BT_ASSERT(notit->dscopes.event_spec_context);
1335 }
1336
ef267d12 1337 BT_COMP_LOGT("Decoding event specific context field: "
fdf0e7a0
PP
1338 "notit-addr=%p, event-class-addr=%p, "
1339 "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
5cd6d0e5 1340 "fc-addr=%p",
44c440bc
PP
1341 notit, notit->meta.ec,
1342 notit->meta.ec->name->str,
1343 notit->meta.ec->id,
5cd6d0e5
PP
1344 event_spec_context_fc);
1345 status = read_dscope_begin_state(notit, event_spec_context_fc,
e98a2d6e 1346 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN,
44c440bc
PP
1347 STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE,
1348 notit->dscopes.event_spec_context);
fdf0e7a0 1349 if (status < 0) {
eb7f6c4f 1350 BT_COMP_LOGW("Cannot decode event specific context field: "
fdf0e7a0
PP
1351 "notit-addr=%p, event-class-addr=%p, "
1352 "event-class-name=\"%s\", "
5cd6d0e5 1353 "event-class-id=%" PRId64 ", fc-addr=%p",
44c440bc
PP
1354 notit, notit->meta.ec,
1355 notit->meta.ec->name->str,
1356 notit->meta.ec->id,
5cd6d0e5 1357 event_spec_context_fc);
fdf0e7a0 1358 }
e98a2d6e
PP
1359
1360end:
e98a2d6e
PP
1361 return status;
1362}
1363
1364static
d6e69534
PP
1365enum bt_msg_iter_status read_event_spec_context_continue_state(
1366 struct bt_msg_iter *notit)
e98a2d6e
PP
1367{
1368 return read_dscope_continue_state(notit,
1369 STATE_DSCOPE_EVENT_PAYLOAD_BEGIN);
1370}
1371
1372static
d6e69534
PP
1373enum bt_msg_iter_status read_event_payload_begin_state(
1374 struct bt_msg_iter *notit)
e98a2d6e 1375{
d6e69534 1376 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
5cd6d0e5 1377 struct ctf_field_class *event_payload_fc;
e98a2d6e 1378
5cd6d0e5
PP
1379 event_payload_fc = notit->meta.ec->payload_fc;
1380 if (!event_payload_fc) {
d6e69534 1381 notit->state = STATE_EMIT_MSG_EVENT;
e98a2d6e
PP
1382 goto end;
1383 }
1384
5cd6d0e5 1385 if (event_payload_fc->in_ir) {
44c440bc 1386 BT_ASSERT(!notit->dscopes.event_payload);
e5be10ef 1387 notit->dscopes.event_payload =
40f4ba76 1388 bt_event_borrow_payload_field(
e5be10ef 1389 notit->event);
44c440bc
PP
1390 BT_ASSERT(notit->dscopes.event_payload);
1391 }
1392
ef267d12 1393 BT_COMP_LOGT("Decoding event payload field: "
fdf0e7a0
PP
1394 "notit-addr=%p, event-class-addr=%p, "
1395 "event-class-name=\"%s\", event-class-id=%" PRId64 ", "
5cd6d0e5 1396 "fc-addr=%p",
44c440bc
PP
1397 notit, notit->meta.ec,
1398 notit->meta.ec->name->str,
1399 notit->meta.ec->id,
5cd6d0e5
PP
1400 event_payload_fc);
1401 status = read_dscope_begin_state(notit, event_payload_fc,
d6e69534 1402 STATE_EMIT_MSG_EVENT,
e98a2d6e 1403 STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
312c056a 1404 notit->dscopes.event_payload);
fdf0e7a0 1405 if (status < 0) {
eb7f6c4f 1406 BT_COMP_LOGW("Cannot decode event payload field: "
fdf0e7a0
PP
1407 "notit-addr=%p, event-class-addr=%p, "
1408 "event-class-name=\"%s\", "
5cd6d0e5 1409 "event-class-id=%" PRId64 ", fc-addr=%p",
44c440bc
PP
1410 notit, notit->meta.ec,
1411 notit->meta.ec->name->str,
1412 notit->meta.ec->id,
5cd6d0e5 1413 event_payload_fc);
fdf0e7a0 1414 }
e98a2d6e
PP
1415
1416end:
e98a2d6e
PP
1417 return status;
1418}
1419
1420static
d6e69534
PP
1421enum bt_msg_iter_status read_event_payload_continue_state(
1422 struct bt_msg_iter *notit)
e98a2d6e 1423{
d6e69534 1424 return read_dscope_continue_state(notit, STATE_EMIT_MSG_EVENT);
e98a2d6e
PP
1425}
1426
1427static
fc917f65 1428enum bt_msg_iter_status skip_packet_padding_state(struct bt_msg_iter *notit)
e98a2d6e 1429{
d6e69534 1430 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
e98a2d6e
PP
1431 size_t bits_to_skip;
1432
44c440bc
PP
1433 BT_ASSERT(notit->cur_exp_packet_total_size > 0);
1434 bits_to_skip = notit->cur_exp_packet_total_size - packet_at(notit);
e98a2d6e
PP
1435 if (bits_to_skip == 0) {
1436 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1437 goto end;
1438 } else {
1439 size_t bits_to_consume;
fdf0e7a0 1440
eb7f6c4f 1441 BT_COMP_LOGD("Trying to skip %zu bits of padding: notit-addr=%p, size=%zu",
fdf0e7a0 1442 bits_to_skip, notit, bits_to_skip);
e98a2d6e 1443 status = buf_ensure_available_bits(notit);
d6e69534 1444 if (status != BT_MSG_ITER_STATUS_OK) {
e98a2d6e
PP
1445 goto end;
1446 }
1447
1448 bits_to_consume = MIN(buf_available_bits(notit), bits_to_skip);
eb7f6c4f 1449 BT_COMP_LOGD("Skipping %zu bits of padding: notit-addr=%p, size=%zu",
fdf0e7a0 1450 bits_to_consume, notit, bits_to_consume);
e98a2d6e 1451 buf_consume_bits(notit, bits_to_consume);
44c440bc
PP
1452 bits_to_skip = notit->cur_exp_packet_total_size -
1453 packet_at(notit);
e98a2d6e
PP
1454 if (bits_to_skip == 0) {
1455 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1456 goto end;
1457 }
1458 }
1459
1460end:
1461 return status;
1462}
1463
495490c5
PP
1464static
1465enum bt_msg_iter_status check_emit_msg_stream_beginning_state(
1466 struct bt_msg_iter *notit)
1467{
1468 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
1469
1470 if (notit->set_stream) {
1471 status = set_current_stream(notit);
1472 if (status != BT_MSG_ITER_STATUS_OK) {
1473 goto end;
1474 }
1475 }
1476
1477 if (notit->emit_stream_begin_msg) {
1478 notit->state = STATE_EMIT_MSG_STREAM_BEGINNING;
1479 } else {
1480 /* Stream's first packet */
1481 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
1482 }
1483
1484end:
1485 return status;
1486}
1487
1488static
1489enum bt_msg_iter_status check_emit_msg_discarded_events(
1490 struct bt_msg_iter *notit)
1491{
1492 notit->state = STATE_EMIT_MSG_DISCARDED_EVENTS;
1493
afd45274
PP
1494 if (!notit->meta.sc->has_discarded_events) {
1495 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
1496 goto end;
1497 }
1498
495490c5
PP
1499 if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
1500 if (notit->snapshots.discarded_events == 0 ||
1501 notit->snapshots.discarded_events == UINT64_C(-1)) {
1502 /*
1503 * Stream's first packet with no discarded
1504 * events or no information about discarded
1505 * events: do not emit.
1506 */
1507 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
1508 }
1509 } else {
1510 /*
1511 * If the previous packet has a value for this counter,
1512 * then this counter is defined for the whole stream.
1513 */
1514 BT_ASSERT(notit->snapshots.discarded_events != UINT64_C(-1));
1515
1516 if (notit->snapshots.discarded_events -
1517 notit->prev_packet_snapshots.discarded_events == 0) {
1518 /*
1519 * No discarded events since previous packet: do
1520 * not emit.
1521 */
1522 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
1523 }
1524 }
1525
afd45274 1526end:
495490c5
PP
1527 return BT_MSG_ITER_STATUS_OK;
1528}
1529
1530static
1531enum bt_msg_iter_status check_emit_msg_discarded_packets(
1532 struct bt_msg_iter *notit)
1533{
1534 notit->state = STATE_EMIT_MSG_DISCARDED_PACKETS;
1535
afd45274
PP
1536 if (!notit->meta.sc->has_discarded_packets) {
1537 notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
1538 goto end;
1539 }
1540
495490c5
PP
1541 if (notit->prev_packet_snapshots.packets == UINT64_C(-1)) {
1542 /*
1543 * Stream's first packet or no information about
1544 * discarded packets: do not emit. In other words, if
1545 * this is the first packet and its sequence number is
1546 * not 0, do not consider that packets were previously
1547 * lost: we might be reading a partial stream (LTTng
1548 * snapshot for example).
1549 */
1550 notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
1551 } else {
1552 /*
1553 * If the previous packet has a value for this counter,
1554 * then this counter is defined for the whole stream.
1555 */
1556 BT_ASSERT(notit->snapshots.packets != UINT64_C(-1));
1557
1558 if (notit->snapshots.packets -
1559 notit->prev_packet_snapshots.packets <= 1) {
1560 /*
1561 * No discarded packets since previous packet:
1562 * do not emit.
1563 */
1564 notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
1565 }
1566 }
1567
afd45274 1568end:
495490c5
PP
1569 return BT_MSG_ITER_STATUS_OK;
1570}
1571
1572static
1573enum bt_msg_iter_status check_emit_msg_stream_activity_end(
1574 struct bt_msg_iter *notit)
1575{
1576 if (notit->emit_stream_end_msg) {
1577 notit->state = STATE_EMIT_MSG_STREAM_ACTIVITY_END;
1578 } else {
1579 notit->state = STATE_DONE;
1580 }
1581
1582 return BT_MSG_ITER_STATUS_OK;
1583}
1584
e98a2d6e 1585static inline
d6e69534 1586enum bt_msg_iter_status handle_state(struct bt_msg_iter *notit)
e98a2d6e 1587{
d6e69534 1588 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
fdf0e7a0 1589 const enum state state = notit->state;
e98a2d6e 1590
ef267d12 1591 BT_COMP_LOGT("Handling state: notit-addr=%p, state=%s",
fdf0e7a0 1592 notit, state_string(state));
e98a2d6e
PP
1593
1594 // TODO: optimalize!
fdf0e7a0 1595 switch (state) {
e98a2d6e
PP
1596 case STATE_INIT:
1597 notit->state = STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN;
1598 break;
1599 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
1600 status = read_packet_header_begin_state(notit);
1601 break;
1602 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
1603 status = read_packet_header_continue_state(notit);
1604 break;
1605 case STATE_AFTER_TRACE_PACKET_HEADER:
1606 status = after_packet_header_state(notit);
1607 break;
1608 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
1609 status = read_packet_context_begin_state(notit);
1610 break;
1611 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
1612 status = read_packet_context_continue_state(notit);
1613 break;
1614 case STATE_AFTER_STREAM_PACKET_CONTEXT:
1615 status = after_packet_context_state(notit);
1616 break;
495490c5
PP
1617 case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING:
1618 status = check_emit_msg_stream_beginning_state(notit);
1619 break;
fc917f65
PP
1620 case STATE_EMIT_MSG_STREAM_BEGINNING:
1621 notit->state = STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING;
1622 break;
1623 case STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING:
495490c5
PP
1624 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS;
1625 break;
1626 case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS:
1627 status = check_emit_msg_discarded_events(notit);
1628 break;
1629 case STATE_EMIT_MSG_DISCARDED_EVENTS:
1630 notit->state = STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS;
1631 break;
1632 case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS:
1633 status = check_emit_msg_discarded_packets(notit);
1634 break;
1635 case STATE_EMIT_MSG_DISCARDED_PACKETS:
fc917f65 1636 notit->state = STATE_EMIT_MSG_PACKET_BEGINNING;
f42867e2 1637 break;
fc917f65 1638 case STATE_EMIT_MSG_PACKET_BEGINNING:
44c440bc 1639 notit->state = STATE_DSCOPE_EVENT_HEADER_BEGIN;
e98a2d6e 1640 break;
44c440bc 1641 case STATE_DSCOPE_EVENT_HEADER_BEGIN:
e98a2d6e
PP
1642 status = read_event_header_begin_state(notit);
1643 break;
44c440bc 1644 case STATE_DSCOPE_EVENT_HEADER_CONTINUE:
e98a2d6e
PP
1645 status = read_event_header_continue_state(notit);
1646 break;
44c440bc 1647 case STATE_AFTER_EVENT_HEADER:
e98a2d6e
PP
1648 status = after_event_header_state(notit);
1649 break;
44c440bc
PP
1650 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_BEGIN:
1651 status = read_event_common_context_begin_state(notit);
e98a2d6e 1652 break;
44c440bc
PP
1653 case STATE_DSCOPE_EVENT_COMMON_CONTEXT_CONTINUE:
1654 status = read_event_common_context_continue_state(notit);
e98a2d6e 1655 break;
44c440bc
PP
1656 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_BEGIN:
1657 status = read_event_spec_context_begin_state(notit);
e98a2d6e 1658 break;
44c440bc
PP
1659 case STATE_DSCOPE_EVENT_SPEC_CONTEXT_CONTINUE:
1660 status = read_event_spec_context_continue_state(notit);
e98a2d6e
PP
1661 break;
1662 case STATE_DSCOPE_EVENT_PAYLOAD_BEGIN:
1663 status = read_event_payload_begin_state(notit);
1664 break;
1665 case STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE:
1666 status = read_event_payload_continue_state(notit);
1667 break;
d6e69534 1668 case STATE_EMIT_MSG_EVENT:
44c440bc 1669 notit->state = STATE_DSCOPE_EVENT_HEADER_BEGIN;
e98a2d6e
PP
1670 break;
1671 case STATE_SKIP_PACKET_PADDING:
1672 status = skip_packet_padding_state(notit);
1673 break;
fc917f65 1674 case STATE_EMIT_MSG_PACKET_END_MULTI:
e98a2d6e
PP
1675 notit->state = STATE_SKIP_PACKET_PADDING;
1676 break;
fc917f65 1677 case STATE_EMIT_MSG_PACKET_END_SINGLE:
495490c5
PP
1678 notit->state = STATE_CHECK_EMIT_MSG_STREAM_ACTIVITY_END;
1679 break;
1680 case STATE_CHECK_EMIT_MSG_STREAM_ACTIVITY_END:
1681 status = check_emit_msg_stream_activity_end(notit);
fc917f65
PP
1682 break;
1683 case STATE_EMIT_MSG_STREAM_ACTIVITY_END:
1684 notit->state = STATE_EMIT_MSG_STREAM_END;
1685 break;
1686 case STATE_EMIT_MSG_STREAM_END:
1687 notit->state = STATE_DONE;
1688 break;
1689 case STATE_DONE:
1690 break;
fdf0e7a0 1691 default:
eb7f6c4f 1692 BT_COMP_LOGF("Unknown CTF plugin message iterator state: "
fdf0e7a0
PP
1693 "notit-addr=%p, state=%d", notit, notit->state);
1694 abort();
e98a2d6e
PP
1695 }
1696
ef267d12 1697 BT_COMP_LOGT("Handled state: notit-addr=%p, status=%s, "
fdf0e7a0 1698 "prev-state=%s, cur-state=%s",
d6e69534 1699 notit, bt_msg_iter_status_string(status),
fdf0e7a0 1700 state_string(state), state_string(notit->state));
e98a2d6e
PP
1701 return status;
1702}
1703
f42867e2 1704BT_HIDDEN
495490c5 1705void bt_msg_iter_reset_for_next_stream_file(struct bt_msg_iter *notit)
e98a2d6e 1706{
f6ccaed9 1707 BT_ASSERT(notit);
eb7f6c4f 1708 BT_COMP_LOGD("Resetting message iterator: addr=%p", notit);
e98a2d6e 1709 stack_clear(notit->stack);
44c440bc
PP
1710 notit->meta.sc = NULL;
1711 notit->meta.ec = NULL;
c5b9b441
PP
1712 BT_PACKET_PUT_REF_AND_RESET(notit->packet);
1713 BT_STREAM_PUT_REF_AND_RESET(notit->stream);
d6e69534 1714 BT_MESSAGE_PUT_REF_AND_RESET(notit->event_msg);
312c056a
PP
1715 release_all_dscopes(notit);
1716 notit->cur_dscope_field = NULL;
1717
312c056a 1718 if (notit->packet_context_field) {
40f4ba76 1719 bt_packet_context_field_release(notit->packet_context_field);
312c056a
PP
1720 notit->packet_context_field = NULL;
1721 }
1722
e98a2d6e
PP
1723 notit->buf.addr = NULL;
1724 notit->buf.sz = 0;
1725 notit->buf.at = 0;
2b186c3e 1726 notit->buf.last_eh_at = SIZE_MAX;
e98a2d6e
PP
1727 notit->buf.packet_offset = 0;
1728 notit->state = STATE_INIT;
44c440bc
PP
1729 notit->cur_exp_packet_content_size = -1;
1730 notit->cur_exp_packet_total_size = -1;
9e0c8dbb 1731 notit->cur_packet_offset = -1;
44c440bc 1732 notit->cur_event_class_id = -1;
495490c5
PP
1733 notit->snapshots.beginning_clock = UINT64_C(-1);
1734 notit->snapshots.end_clock = UINT64_C(-1);
1735}
1736
1737/**
1738 * Resets the internal state of a CTF message iterator.
1739 */
1740BT_HIDDEN
1741void bt_msg_iter_reset(struct bt_msg_iter *notit)
1742{
1743 bt_msg_iter_reset_for_next_stream_file(notit);
1744 notit->cur_stream_class_id = -1;
44c440bc 1745 notit->cur_data_stream_id = -1;
fc917f65
PP
1746 notit->emit_stream_begin_msg = true;
1747 notit->emit_stream_end_msg = true;
495490c5
PP
1748 notit->snapshots.discarded_events = UINT64_C(-1);
1749 notit->snapshots.packets = UINT64_C(-1);
1750 notit->prev_packet_snapshots.discarded_events = UINT64_C(-1);
1751 notit->prev_packet_snapshots.packets = UINT64_C(-1);
1752 notit->prev_packet_snapshots.beginning_clock = UINT64_C(-1);
1753 notit->prev_packet_snapshots.end_clock = UINT64_C(-1);
e98a2d6e
PP
1754}
1755
2cf1d51e 1756static
d6e69534 1757int bt_msg_iter_switch_packet(struct bt_msg_iter *notit)
2cf1d51e
JG
1758{
1759 int ret = 0;
1760
115de887
PP
1761 /*
1762 * We don't put the stream class here because we need to make
d6e69534 1763 * sure that all the packets processed by the same message
115de887
PP
1764 * iterator refer to the same stream class (the first one).
1765 */
f6ccaed9 1766 BT_ASSERT(notit);
312c056a 1767
44c440bc
PP
1768 if (notit->cur_exp_packet_total_size != -1) {
1769 notit->cur_packet_offset += notit->cur_exp_packet_total_size;
9e0c8dbb 1770 }
312c056a 1771
eb7f6c4f 1772 BT_COMP_LOGD("Switching packet: notit-addr=%p, cur=%zu, "
9e0c8dbb
JG
1773 "packet-offset=%" PRId64, notit, notit->buf.at,
1774 notit->cur_packet_offset);
2cf1d51e 1775 stack_clear(notit->stack);
44c440bc 1776 notit->meta.ec = NULL;
c5b9b441 1777 BT_PACKET_PUT_REF_AND_RESET(notit->packet);
d6e69534 1778 BT_MESSAGE_PUT_REF_AND_RESET(notit->event_msg);
312c056a
PP
1779 release_all_dscopes(notit);
1780 notit->cur_dscope_field = NULL;
2cf1d51e
JG
1781
1782 /*
1783 * Adjust current buffer so that addr points to the beginning of the new
1784 * packet.
1785 */
1786 if (notit->buf.addr) {
1787 size_t consumed_bytes = (size_t) (notit->buf.at / CHAR_BIT);
1788
1789 /* Packets are assumed to start on a byte frontier. */
1790 if (notit->buf.at % CHAR_BIT) {
eb7f6c4f 1791 BT_COMP_LOGW("Cannot switch packet: current position is not a multiple of 8: "
fdf0e7a0 1792 "notit-addr=%p, cur=%zu", notit, notit->buf.at);
2cf1d51e
JG
1793 ret = -1;
1794 goto end;
1795 }
1796
1797 notit->buf.addr += consumed_bytes;
1798 notit->buf.sz -= consumed_bytes;
1799 notit->buf.at = 0;
1800 notit->buf.packet_offset = 0;
eb7f6c4f 1801 BT_COMP_LOGD("Adjusted buffer: addr=%p, size=%zu",
fdf0e7a0 1802 notit->buf.addr, notit->buf.sz);
2cf1d51e
JG
1803 }
1804
44c440bc
PP
1805 notit->cur_exp_packet_content_size = -1;
1806 notit->cur_exp_packet_total_size = -1;
1807 notit->cur_stream_class_id = -1;
1808 notit->cur_event_class_id = -1;
1809 notit->cur_data_stream_id = -1;
495490c5 1810 notit->prev_packet_snapshots = notit->snapshots;
44c440bc
PP
1811 notit->snapshots.discarded_events = UINT64_C(-1);
1812 notit->snapshots.packets = UINT64_C(-1);
1813 notit->snapshots.beginning_clock = UINT64_C(-1);
1814 notit->snapshots.end_clock = UINT64_C(-1);
fdf0e7a0 1815
2cf1d51e
JG
1816end:
1817 return ret;
1818}
1819
e98a2d6e 1820static
d6e69534 1821bt_field *borrow_next_field(struct bt_msg_iter *notit)
e98a2d6e 1822{
b19ff26f
PP
1823 bt_field *next_field = NULL;
1824 bt_field *base_field;
1825 const bt_field_class *base_fc;
e98a2d6e
PP
1826 size_t index;
1827
f6ccaed9 1828 BT_ASSERT(!stack_empty(notit->stack));
e98a2d6e
PP
1829 index = stack_top(notit->stack)->index;
1830 base_field = stack_top(notit->stack)->base;
f6ccaed9 1831 BT_ASSERT(base_field);
40f4ba76 1832 base_fc = bt_field_borrow_class_const(base_field);
5cd6d0e5 1833 BT_ASSERT(base_fc);
e98a2d6e 1834
40f4ba76 1835 switch (bt_field_class_get_type(base_fc)) {
864cad70 1836 case BT_FIELD_CLASS_TYPE_STRUCTURE:
f42867e2 1837 {
44c440bc 1838 BT_ASSERT(index <
5cd6d0e5 1839 bt_field_class_structure_get_member_count(
40f4ba76
PP
1840 bt_field_borrow_class_const(
1841 base_field)));
e5be10ef 1842 next_field =
40f4ba76 1843 bt_field_structure_borrow_member_field_by_index(
e5be10ef 1844 base_field, index);
e98a2d6e 1845 break;
f42867e2 1846 }
864cad70
PP
1847 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
1848 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
40f4ba76
PP
1849 BT_ASSERT(index < bt_field_array_get_length(base_field));
1850 next_field = bt_field_array_borrow_element_field_by_index(
44c440bc 1851 base_field, index);
e98a2d6e 1852 break;
864cad70 1853 case BT_FIELD_CLASS_TYPE_VARIANT:
44c440bc 1854 BT_ASSERT(index == 0);
40f4ba76 1855 next_field = bt_field_variant_borrow_selected_option_field(
44c440bc 1856 base_field);
e98a2d6e
PP
1857 break;
1858 default:
0fbb9a9f 1859 abort();
e98a2d6e
PP
1860 }
1861
44c440bc 1862 BT_ASSERT(next_field);
e98a2d6e
PP
1863 return next_field;
1864}
1865
c44c3e70 1866static
d6e69534 1867void update_default_clock(struct bt_msg_iter *notit, uint64_t new_val,
44c440bc 1868 uint64_t new_val_size)
c44c3e70 1869{
44c440bc 1870 uint64_t new_val_mask;
c44c3e70 1871 uint64_t cur_value_masked;
c44c3e70 1872
44c440bc 1873 BT_ASSERT(new_val_size > 0);
c44c3e70
JG
1874
1875 /*
1876 * Special case for a 64-bit new value, which is the limit
1877 * of a clock value as of this version: overwrite the
1878 * current value directly.
1879 */
44c440bc 1880 if (new_val_size == 64) {
605e1019 1881 notit->default_clock_snapshot = new_val;
c44c3e70
JG
1882 goto end;
1883 }
1884
44c440bc 1885 new_val_mask = (1ULL << new_val_size) - 1;
605e1019 1886 cur_value_masked = notit->default_clock_snapshot & new_val_mask;
c44c3e70 1887
44c440bc 1888 if (new_val < cur_value_masked) {
c44c3e70
JG
1889 /*
1890 * It looks like a wrap happened on the number of bits
1891 * of the requested new value. Assume that the clock
1892 * value wrapped only one time.
1893 */
605e1019 1894 notit->default_clock_snapshot += new_val_mask + 1;
c44c3e70
JG
1895 }
1896
1897 /* Clear the low bits of the current clock value. */
605e1019 1898 notit->default_clock_snapshot &= ~new_val_mask;
c44c3e70
JG
1899
1900 /* Set the low bits of the current clock value. */
605e1019 1901 notit->default_clock_snapshot |= new_val;
d1e46835 1902
c44c3e70 1903end:
ef267d12 1904 BT_COMP_LOGT("Updated default clock's value from integer field's value: "
605e1019 1905 "value=%" PRIu64, notit->default_clock_snapshot);
c44c3e70
JG
1906}
1907
1908static
5cd6d0e5
PP
1909enum bt_bfcr_status bfcr_unsigned_int_cb(uint64_t value,
1910 struct ctf_field_class *fc, void *data)
c44c3e70 1911{
d6e69534 1912 struct bt_msg_iter *notit = data;
5cd6d0e5 1913 enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
b19ff26f 1914 bt_field *field = NULL;
5cd6d0e5 1915 struct ctf_field_class_int *int_fc = (void *) fc;
c44c3e70 1916
ef267d12 1917 BT_COMP_LOGT("Unsigned integer function called from BFCR: "
5cd6d0e5 1918 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
1919 "fc-type=%d, fc-in-ir=%d, value=%" PRIu64,
1920 notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
312c056a 1921
91d81473 1922 if (G_LIKELY(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE)) {
44c440bc 1923 goto update_def_clock;
c44c3e70
JG
1924 }
1925
5cd6d0e5
PP
1926 switch (int_fc->meaning) {
1927 case CTF_FIELD_CLASS_MEANING_EVENT_CLASS_ID:
44c440bc
PP
1928 notit->cur_event_class_id = value;
1929 break;
5cd6d0e5 1930 case CTF_FIELD_CLASS_MEANING_DATA_STREAM_ID:
44c440bc
PP
1931 notit->cur_data_stream_id = value;
1932 break;
5cd6d0e5 1933 case CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME:
44c440bc
PP
1934 notit->snapshots.beginning_clock = value;
1935 break;
5cd6d0e5 1936 case CTF_FIELD_CLASS_MEANING_PACKET_END_TIME:
44c440bc
PP
1937 notit->snapshots.end_clock = value;
1938 break;
5cd6d0e5 1939 case CTF_FIELD_CLASS_MEANING_STREAM_CLASS_ID:
44c440bc
PP
1940 notit->cur_stream_class_id = value;
1941 break;
5cd6d0e5 1942 case CTF_FIELD_CLASS_MEANING_MAGIC:
44c440bc 1943 if (value != 0xc1fc1fc1) {
eb7f6c4f 1944 BT_COMP_LOGW("Invalid CTF magic number: notit-addr=%p, "
44c440bc 1945 "magic=%" PRIx64, notit, value);
5cd6d0e5 1946 status = BT_BFCR_STATUS_ERROR;
c44c3e70
JG
1947 goto end;
1948 }
fdf0e7a0 1949
44c440bc 1950 break;
5cd6d0e5 1951 case CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT:
44c440bc
PP
1952 notit->snapshots.packets = value;
1953 break;
5cd6d0e5 1954 case CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT:
44c440bc
PP
1955 notit->snapshots.discarded_events = value;
1956 break;
5cd6d0e5 1957 case CTF_FIELD_CLASS_MEANING_EXP_PACKET_TOTAL_SIZE:
44c440bc
PP
1958 notit->cur_exp_packet_total_size = value;
1959 break;
5cd6d0e5 1960 case CTF_FIELD_CLASS_MEANING_EXP_PACKET_CONTENT_SIZE:
44c440bc
PP
1961 notit->cur_exp_packet_content_size = value;
1962 break;
1963 default:
1964 abort();
c44c3e70
JG
1965 }
1966
44c440bc 1967update_def_clock:
91d81473 1968 if (G_UNLIKELY(int_fc->mapped_clock_class)) {
5cd6d0e5 1969 update_default_clock(notit, value, int_fc->base.size);
44c440bc 1970 }
c44c3e70 1971
91d81473 1972 if (G_UNLIKELY(int_fc->storing_index >= 0)) {
44c440bc 1973 g_array_index(notit->stored_values, uint64_t,
5cd6d0e5 1974 (uint64_t) int_fc->storing_index) = value;
44c440bc 1975 }
e98a2d6e 1976
91d81473 1977 if (G_UNLIKELY(!fc->in_ir)) {
312c056a 1978 goto end;
e98a2d6e
PP
1979 }
1980
44c440bc
PP
1981 field = borrow_next_field(notit);
1982 BT_ASSERT(field);
40f4ba76
PP
1983 BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
1984 BT_ASSERT(bt_field_get_class_type(field) ==
1985 BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER ||
1986 bt_field_get_class_type(field) ==
1987 BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION);
1988 bt_field_unsigned_integer_set_value(field, value);
e98a2d6e 1989 stack_top(notit->stack)->index++;
fdf0e7a0 1990
312c056a 1991end:
e98a2d6e
PP
1992 return status;
1993}
1994
5f870343 1995static
5cd6d0e5
PP
1996enum bt_bfcr_status bfcr_unsigned_int_char_cb(uint64_t value,
1997 struct ctf_field_class *fc, void *data)
5f870343 1998{
44c440bc 1999 int ret;
d6e69534 2000 struct bt_msg_iter *notit = data;
5cd6d0e5 2001 enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
b19ff26f 2002 bt_field *string_field = NULL;
5cd6d0e5 2003 struct ctf_field_class_int *int_fc = (void *) fc;
44c440bc 2004 char str[2] = {'\0', '\0'};
5f870343 2005
ef267d12 2006 BT_COMP_LOGT("Unsigned integer character function called from BFCR: "
5cd6d0e5 2007 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2008 "fc-type=%d, fc-in-ir=%d, value=%" PRIu64,
2009 notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
5cd6d0e5
PP
2010 BT_ASSERT(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE);
2011 BT_ASSERT(!int_fc->mapped_clock_class);
2012 BT_ASSERT(int_fc->storing_index < 0);
312c056a 2013
91d81473 2014 if (G_UNLIKELY(!fc->in_ir)) {
44c440bc
PP
2015 goto end;
2016 }
5f870343 2017
44c440bc 2018 if (notit->done_filling_string) {
5f870343
JG
2019 goto end;
2020 }
2021
44c440bc
PP
2022 if (value == 0) {
2023 notit->done_filling_string = true;
5f870343
JG
2024 goto end;
2025 }
2026
44c440bc 2027 string_field = stack_top(notit->stack)->base;
40f4ba76
PP
2028 BT_ASSERT(bt_field_get_class_type(string_field) ==
2029 BT_FIELD_CLASS_TYPE_STRING);
44c440bc
PP
2030
2031 /* Append character */
2032 str[0] = (char) value;
40f4ba76 2033 ret = bt_field_string_append_with_length(string_field, str, 1);
44c440bc 2034 if (ret) {
eb7f6c4f 2035 BT_COMP_LOGE("Cannot append character to string field's value: "
44c440bc
PP
2036 "notit-addr=%p, field-addr=%p, ret=%d",
2037 notit, string_field, ret);
5cd6d0e5 2038 status = BT_BFCR_STATUS_ERROR;
44c440bc
PP
2039 goto end;
2040 }
312c056a 2041
5f870343
JG
2042end:
2043 return status;
2044}
2045
2046static
5cd6d0e5
PP
2047enum bt_bfcr_status bfcr_signed_int_cb(int64_t value,
2048 struct ctf_field_class *fc, void *data)
e98a2d6e 2049{
5cd6d0e5 2050 enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
b19ff26f 2051 bt_field *field = NULL;
d6e69534 2052 struct bt_msg_iter *notit = data;
5cd6d0e5 2053 struct ctf_field_class_int *int_fc = (void *) fc;
e98a2d6e 2054
ef267d12 2055 BT_COMP_LOGT("Signed integer function called from BFCR: "
5cd6d0e5 2056 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2057 "fc-type=%d, fc-in-ir=%d, value=%" PRId64,
2058 notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
5cd6d0e5 2059 BT_ASSERT(int_fc->meaning == CTF_FIELD_CLASS_MEANING_NONE);
44c440bc 2060
91d81473 2061 if (G_UNLIKELY(int_fc->storing_index >= 0)) {
44c440bc 2062 g_array_index(notit->stored_values, uint64_t,
5cd6d0e5 2063 (uint64_t) int_fc->storing_index) = (uint64_t) value;
44c440bc
PP
2064 }
2065
91d81473 2066 if (G_UNLIKELY(!fc->in_ir)) {
312c056a 2067 goto end;
e98a2d6e
PP
2068 }
2069
44c440bc
PP
2070 field = borrow_next_field(notit);
2071 BT_ASSERT(field);
40f4ba76
PP
2072 BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
2073 BT_ASSERT(bt_field_get_class_type(field) ==
2074 BT_FIELD_CLASS_TYPE_SIGNED_INTEGER ||
2075 bt_field_get_class_type(field) ==
2076 BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION);
2077 bt_field_signed_integer_set_value(field, value);
e98a2d6e 2078 stack_top(notit->stack)->index++;
fdf0e7a0 2079
312c056a 2080end:
e98a2d6e
PP
2081 return status;
2082}
2083
2084static
5cd6d0e5
PP
2085enum bt_bfcr_status bfcr_floating_point_cb(double value,
2086 struct ctf_field_class *fc, void *data)
e98a2d6e 2087{
5cd6d0e5 2088 enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
b19ff26f 2089 bt_field *field = NULL;
d6e69534 2090 struct bt_msg_iter *notit = data;
e98a2d6e 2091
ef267d12 2092 BT_COMP_LOGT("Floating point number function called from BFCR: "
5cd6d0e5 2093 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2094 "fc-type=%d, fc-in-ir=%d, value=%f",
2095 notit, notit->bfcr, fc, fc->type, fc->in_ir, value);
41693723 2096
91d81473 2097 if (G_UNLIKELY(!fc->in_ir)) {
41693723
PP
2098 goto end;
2099 }
2100
312c056a 2101 field = borrow_next_field(notit);
44c440bc 2102 BT_ASSERT(field);
40f4ba76
PP
2103 BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
2104 BT_ASSERT(bt_field_get_class_type(field) ==
2105 BT_FIELD_CLASS_TYPE_REAL);
2106 bt_field_real_set_value(field, value);
e98a2d6e 2107 stack_top(notit->stack)->index++;
41693723
PP
2108
2109end:
e98a2d6e
PP
2110 return status;
2111}
2112
2113static
5cd6d0e5
PP
2114enum bt_bfcr_status bfcr_string_begin_cb(
2115 struct ctf_field_class *fc, void *data)
e98a2d6e 2116{
b19ff26f 2117 bt_field *field = NULL;
d6e69534 2118 struct bt_msg_iter *notit = data;
e98a2d6e 2119
ef267d12 2120 BT_COMP_LOGT("String (beginning) function called from BFCR: "
5cd6d0e5 2121 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2122 "fc-type=%d, fc-in-ir=%d",
2123 notit, notit->bfcr, fc, fc->type, fc->in_ir);
e98a2d6e 2124
91d81473 2125 if (G_UNLIKELY(!fc->in_ir)) {
41693723
PP
2126 goto end;
2127 }
2128
44c440bc
PP
2129 field = borrow_next_field(notit);
2130 BT_ASSERT(field);
40f4ba76
PP
2131 BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
2132 BT_ASSERT(bt_field_get_class_type(field) ==
2133 BT_FIELD_CLASS_TYPE_STRING);
d24d5663 2134 bt_field_string_clear(field);
312c056a 2135
e98a2d6e 2136 /*
5cd6d0e5
PP
2137 * Push on stack. Not a compound class per se, but we know that
2138 * only bfcr_string_cb() may be called between this call and a
2139 * subsequent call to bfcr_string_end_cb().
e98a2d6e 2140 */
44c440bc 2141 stack_push(notit->stack, field);
41693723
PP
2142
2143end:
5cd6d0e5 2144 return BT_BFCR_STATUS_OK;
e98a2d6e
PP
2145}
2146
2147static
5cd6d0e5
PP
2148enum bt_bfcr_status bfcr_string_cb(const char *value,
2149 size_t len, struct ctf_field_class *fc, void *data)
e98a2d6e 2150{
5cd6d0e5 2151 enum bt_bfcr_status status = BT_BFCR_STATUS_OK;
b19ff26f 2152 bt_field *field = NULL;
d6e69534 2153 struct bt_msg_iter *notit = data;
e98a2d6e
PP
2154 int ret;
2155
ef267d12 2156 BT_COMP_LOGT("String (substring) function called from BFCR: "
5cd6d0e5 2157 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2158 "fc-type=%d, fc-in-ir=%d, string-length=%zu",
2159 notit, notit->bfcr, fc, fc->type, fc->in_ir,
fdf0e7a0 2160 len);
41693723 2161
91d81473 2162 if (G_UNLIKELY(!fc->in_ir)) {
41693723
PP
2163 goto end;
2164 }
2165
e98a2d6e 2166 field = stack_top(notit->stack)->base;
f6ccaed9 2167 BT_ASSERT(field);
e98a2d6e 2168
312c056a 2169 /* Append current substring */
40f4ba76 2170 ret = bt_field_string_append_with_length(field, value, len);
e98a2d6e 2171 if (ret) {
eb7f6c4f 2172 BT_COMP_LOGE("Cannot append substring to string field's value: "
fdf0e7a0
PP
2173 "notit-addr=%p, field-addr=%p, string-length=%zu, "
2174 "ret=%d", notit, field, len, ret);
5cd6d0e5 2175 status = BT_BFCR_STATUS_ERROR;
e98a2d6e
PP
2176 goto end;
2177 }
2178
2179end:
2180 return status;
2181}
2182
2183static
5cd6d0e5
PP
2184enum bt_bfcr_status bfcr_string_end_cb(
2185 struct ctf_field_class *fc, void *data)
e98a2d6e 2186{
d6e69534 2187 struct bt_msg_iter *notit = data;
e98a2d6e 2188
ef267d12 2189 BT_COMP_LOGT("String (end) function called from BFCR: "
5cd6d0e5 2190 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2191 "fc-type=%d, fc-in-ir=%d",
2192 notit, notit->bfcr, fc, fc->type, fc->in_ir);
41693723 2193
91d81473 2194 if (G_UNLIKELY(!fc->in_ir)) {
41693723
PP
2195 goto end;
2196 }
fdf0e7a0 2197
e98a2d6e
PP
2198 /* Pop string field */
2199 stack_pop(notit->stack);
2200
2201 /* Go to next field */
2202 stack_top(notit->stack)->index++;
41693723
PP
2203
2204end:
5cd6d0e5 2205 return BT_BFCR_STATUS_OK;
e98a2d6e
PP
2206}
2207
5cd6d0e5
PP
2208enum bt_bfcr_status bfcr_compound_begin_cb(
2209 struct ctf_field_class *fc, void *data)
e98a2d6e 2210{
d6e69534 2211 struct bt_msg_iter *notit = data;
b19ff26f 2212 bt_field *field;
e98a2d6e 2213
ef267d12 2214 BT_COMP_LOGT("Compound (beginning) function called from BFCR: "
5cd6d0e5 2215 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2216 "fc-type=%d, fc-in-ir=%d",
2217 notit, notit->bfcr, fc, fc->type, fc->in_ir);
44c440bc 2218
5cd6d0e5 2219 if (!fc->in_ir) {
44c440bc
PP
2220 goto end;
2221 }
fdf0e7a0 2222
312c056a 2223 /* Borrow field */
e98a2d6e 2224 if (stack_empty(notit->stack)) {
312c056a
PP
2225 /* Root: already set by read_dscope_begin_state() */
2226 field = notit->cur_dscope_field;
e98a2d6e 2227 } else {
312c056a 2228 field = borrow_next_field(notit);
44c440bc 2229 BT_ASSERT(field);
e98a2d6e
PP
2230 }
2231
2232 /* Push field */
f6ccaed9 2233 BT_ASSERT(field);
40f4ba76 2234 BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
44c440bc
PP
2235 stack_push(notit->stack, field);
2236
2237 /*
5cd6d0e5 2238 * Change BFCR "unsigned int" callback if it's a text
44c440bc
PP
2239 * array/sequence.
2240 */
864cad70
PP
2241 if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY ||
2242 fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE) {
5cd6d0e5 2243 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 2244
5cd6d0e5 2245 if (array_fc->is_text) {
40f4ba76
PP
2246 BT_ASSERT(bt_field_get_class_type(field) ==
2247 BT_FIELD_CLASS_TYPE_STRING);
44c440bc 2248 notit->done_filling_string = false;
d24d5663 2249 bt_field_string_clear(field);
5cd6d0e5
PP
2250 bt_bfcr_set_unsigned_int_cb(notit->bfcr,
2251 bfcr_unsigned_int_char_cb);
44c440bc 2252 }
e98a2d6e
PP
2253 }
2254
2255end:
5cd6d0e5 2256 return BT_BFCR_STATUS_OK;
e98a2d6e
PP
2257}
2258
5cd6d0e5
PP
2259enum bt_bfcr_status bfcr_compound_end_cb(
2260 struct ctf_field_class *fc, void *data)
e98a2d6e 2261{
d6e69534 2262 struct bt_msg_iter *notit = data;
e98a2d6e 2263
ef267d12 2264 BT_COMP_LOGT("Compound (end) function called from BFCR: "
5cd6d0e5 2265 "notit-addr=%p, bfcr-addr=%p, fc-addr=%p, "
864cad70
PP
2266 "fc-type=%d, fc-in-ir=%d",
2267 notit, notit->bfcr, fc, fc->type, fc->in_ir);
e98a2d6e 2268
5cd6d0e5 2269 if (!fc->in_ir) {
e98a2d6e
PP
2270 goto end;
2271 }
2272
44c440bc 2273 BT_ASSERT(!stack_empty(notit->stack));
40f4ba76 2274 BT_ASSERT(bt_field_borrow_class_const(stack_top(notit->stack)->base) ==
5cd6d0e5 2275 fc->ir_fc);
e98a2d6e 2276
44c440bc 2277 /*
5cd6d0e5 2278 * Reset BFCR "unsigned int" callback if it's a text
44c440bc
PP
2279 * array/sequence.
2280 */
864cad70
PP
2281 if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY ||
2282 fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE) {
5cd6d0e5 2283 struct ctf_field_class_array_base *array_fc = (void *) fc;
44c440bc 2284
5cd6d0e5 2285 if (array_fc->is_text) {
864cad70 2286 BT_ASSERT(bt_field_get_class_type(
40f4ba76 2287 stack_top(notit->stack)->base) ==
e5be10ef 2288 BT_FIELD_CLASS_TYPE_STRING);
5cd6d0e5
PP
2289 bt_bfcr_set_unsigned_int_cb(notit->bfcr,
2290 bfcr_unsigned_int_cb);
e98a2d6e 2291 }
44c440bc 2292 }
e98a2d6e 2293
44c440bc
PP
2294 /* Pop stack */
2295 stack_pop(notit->stack);
e98a2d6e 2296
44c440bc
PP
2297 /* If the stack is not empty, increment the base's index */
2298 if (!stack_empty(notit->stack)) {
2299 stack_top(notit->stack)->index++;
e98a2d6e
PP
2300 }
2301
2302end:
5cd6d0e5 2303 return BT_BFCR_STATUS_OK;
e98a2d6e
PP
2304}
2305
2306static
5cd6d0e5 2307int64_t bfcr_get_sequence_length_cb(struct ctf_field_class *fc, void *data)
e98a2d6e 2308{
b19ff26f 2309 bt_field *seq_field;
d6e69534 2310 struct bt_msg_iter *notit = data;
5cd6d0e5 2311 struct ctf_field_class_sequence *seq_fc = (void *) fc;
44c440bc
PP
2312 int64_t length = -1;
2313 int ret;
e98a2d6e 2314
44c440bc 2315 length = (uint64_t) g_array_index(notit->stored_values, uint64_t,
5cd6d0e5 2316 seq_fc->stored_length_index);
fdf0e7a0 2317 seq_field = stack_top(notit->stack)->base;
44c440bc 2318 BT_ASSERT(seq_field);
785a6bba
PP
2319
2320 /*
2321 * bfcr_get_sequence_length_cb() also gets called back for a
2322 * text sequence, but the destination field is a string field.
2323 * Only set the field's sequence length if the destination field
2324 * is a sequence field.
2325 */
2326 if (!seq_fc->base.is_text) {
2327 BT_ASSERT(bt_field_get_class_type(seq_field) ==
2328 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
2329 ret = bt_field_dynamic_array_set_length(seq_field,
2330 (uint64_t) length);
2331 if (ret) {
eb7f6c4f 2332 BT_COMP_LOGE("Cannot set dynamic array field's length field: "
785a6bba
PP
2333 "notit-addr=%p, field-addr=%p, "
2334 "length=%" PRIu64, notit, seq_field, length);
2335 }
2cf1d51e 2336 }
fdf0e7a0 2337
44c440bc 2338 return length;
e98a2d6e
PP
2339}
2340
2341static
5cd6d0e5
PP
2342struct ctf_field_class *bfcr_borrow_variant_selected_field_class_cb(
2343 struct ctf_field_class *fc, void *data)
e98a2d6e 2344{
312c056a 2345 int ret;
44c440bc
PP
2346 uint64_t i;
2347 int64_t option_index = -1;
d6e69534 2348 struct bt_msg_iter *notit = data;
5cd6d0e5
PP
2349 struct ctf_field_class_variant *var_fc = (void *) fc;
2350 struct ctf_named_field_class *selected_option = NULL;
2351 struct ctf_field_class *ret_fc = NULL;
44c440bc
PP
2352 union {
2353 uint64_t u;
2354 int64_t i;
2355 } tag;
2356
2357 /* Get variant's tag */
2358 tag.u = g_array_index(notit->stored_values, uint64_t,
5cd6d0e5 2359 var_fc->stored_tag_index);
e98a2d6e
PP
2360
2361 /*
44c440bc 2362 * Check each range to find the selected option's index.
e98a2d6e 2363 */
5cd6d0e5
PP
2364 if (var_fc->tag_fc->base.is_signed) {
2365 for (i = 0; i < var_fc->ranges->len; i++) {
2366 struct ctf_field_class_variant_range *range =
2367 ctf_field_class_variant_borrow_range_by_index(
2368 var_fc, i);
44c440bc
PP
2369
2370 if (tag.i >= range->range.lower.i &&
2371 tag.i <= range->range.upper.i) {
2372 option_index = (int64_t) range->option_index;
2373 break;
2374 }
2375 }
312c056a 2376 } else {
5cd6d0e5
PP
2377 for (i = 0; i < var_fc->ranges->len; i++) {
2378 struct ctf_field_class_variant_range *range =
2379 ctf_field_class_variant_borrow_range_by_index(
2380 var_fc, i);
44c440bc
PP
2381
2382 if (tag.u >= range->range.lower.u &&
2383 tag.u <= range->range.upper.u) {
2384 option_index = (int64_t) range->option_index;
2385 break;
2386 }
2387 }
312c056a
PP
2388 }
2389
44c440bc 2390 if (option_index < 0) {
eb7f6c4f 2391 BT_COMP_LOGW("Cannot find variant field class's option: "
5cd6d0e5
PP
2392 "notit-addr=%p, var-fc-addr=%p, u-tag=%" PRIu64 ", "
2393 "i-tag=%" PRId64, notit, var_fc, tag.u, tag.i);
e98a2d6e
PP
2394 goto end;
2395 }
2396
5cd6d0e5
PP
2397 selected_option = ctf_field_class_variant_borrow_option_by_index(
2398 var_fc, (uint64_t) option_index);
e98a2d6e 2399
5cd6d0e5 2400 if (selected_option->fc->in_ir) {
b19ff26f 2401 bt_field *var_field = stack_top(notit->stack)->base;
1556a1af 2402
40f4ba76 2403 ret = bt_field_variant_select_option_field(
e5be10ef 2404 var_field, option_index);
e22b45d0 2405 if (ret) {
eb7f6c4f 2406 BT_COMP_LOGW("Cannot select variant field's option field: "
44c440bc
PP
2407 "notit-addr=%p, var-field-addr=%p, "
2408 "opt-index=%" PRId64, notit, var_field,
2409 option_index);
1556a1af
JG
2410 goto end;
2411 }
af87daef
PP
2412 }
2413
5cd6d0e5 2414 ret_fc = selected_option->fc;
e22b45d0 2415
af87daef 2416end:
5cd6d0e5 2417 return ret_fc;
44c440bc
PP
2418}
2419
f42867e2 2420static
fc917f65 2421void create_msg_stream_beginning(struct bt_msg_iter *notit,
d6e69534 2422 bt_message **message)
f42867e2 2423{
d6e69534 2424 bt_message *ret = NULL;
f42867e2 2425
f42867e2 2426 BT_ASSERT(notit->stream);
d6e69534
PP
2427 BT_ASSERT(notit->msg_iter);
2428 ret = bt_message_stream_beginning_create(notit->msg_iter,
f0010051 2429 notit->stream);
f42867e2 2430 if (!ret) {
eb7f6c4f 2431 BT_COMP_LOGE("Cannot create stream beginning message: "
f42867e2
PP
2432 "notit-addr=%p, stream-addr=%p",
2433 notit, notit->stream);
2434 return;
2435 }
2436
d6e69534 2437 *message = ret;
f42867e2
PP
2438}
2439
2440static
fc917f65
PP
2441void create_msg_stream_activity_beginning(struct bt_msg_iter *notit,
2442 bt_message **message)
2443{
2444 bt_message *ret = NULL;
2445
2446 BT_ASSERT(notit->stream);
2447 BT_ASSERT(notit->msg_iter);
2448 ret = bt_message_stream_activity_beginning_create(notit->msg_iter,
2449 notit->stream);
2450 if (!ret) {
eb7f6c4f 2451 BT_COMP_LOGE("Cannot create stream activity beginning message: "
fc917f65
PP
2452 "notit-addr=%p, stream-addr=%p",
2453 notit, notit->stream);
2454 return;
2455 }
2456
2457 *message = ret;
2458}
2459
2460static
2461void create_msg_stream_activity_end(struct bt_msg_iter *notit,
d6e69534 2462 bt_message **message)
fc917f65
PP
2463{
2464 bt_message *ret = NULL;
2465
2466 if (!notit->stream) {
eb7f6c4f 2467 BT_COMP_LOGE("Cannot create stream for stream message: "
fc917f65
PP
2468 "notit-addr=%p", notit);
2469 return;
2470 }
2471
2472 BT_ASSERT(notit->stream);
2473 BT_ASSERT(notit->msg_iter);
2474 ret = bt_message_stream_activity_end_create(notit->msg_iter,
2475 notit->stream);
2476 if (!ret) {
eb7f6c4f 2477 BT_COMP_LOGE("Cannot create stream activity end message: "
fc917f65
PP
2478 "notit-addr=%p, stream-addr=%p",
2479 notit, notit->stream);
2480 return;
2481 }
2482
2483 *message = ret;
2484}
2485
2486static
2487void create_msg_stream_end(struct bt_msg_iter *notit, bt_message **message)
f42867e2 2488{
d6e69534 2489 bt_message *ret;
f42867e2
PP
2490
2491 if (!notit->stream) {
eb7f6c4f 2492 BT_COMP_LOGE("Cannot create stream for stream message: "
f42867e2
PP
2493 "notit-addr=%p", notit);
2494 return;
2495 }
2496
d6e69534
PP
2497 BT_ASSERT(notit->msg_iter);
2498 ret = bt_message_stream_end_create(notit->msg_iter,
f0010051 2499 notit->stream);
f42867e2 2500 if (!ret) {
eb7f6c4f 2501 BT_COMP_LOGE("Cannot create stream end message: "
f42867e2
PP
2502 "notit-addr=%p, stream-addr=%p",
2503 notit, notit->stream);
2504 return;
2505 }
fc917f65 2506
d6e69534 2507 *message = ret;
f42867e2
PP
2508}
2509
78586d8a 2510static
fc917f65 2511void create_msg_packet_beginning(struct bt_msg_iter *notit,
d6e69534 2512 bt_message **message)
e98a2d6e 2513{
312c056a 2514 int ret;
d6e69534
PP
2515 enum bt_msg_iter_status status;
2516 bt_message *msg = NULL;
b19ff26f 2517 const bt_stream_class *sc;
e98a2d6e 2518
312c056a 2519 status = set_current_packet(notit);
d6e69534 2520 if (status != BT_MSG_ITER_STATUS_OK) {
312c056a 2521 goto end;
e98a2d6e
PP
2522 }
2523
312c056a 2524 BT_ASSERT(notit->packet);
40f4ba76 2525 sc = notit->meta.sc->ir_sc;
44c440bc
PP
2526 BT_ASSERT(sc);
2527
312c056a 2528 if (notit->packet_context_field) {
40f4ba76 2529 ret = bt_packet_move_context_field(
e5be10ef 2530 notit->packet, notit->packet_context_field);
312c056a
PP
2531 if (ret) {
2532 goto end;
2533 }
2534
2535 notit->packet_context_field = NULL;
2536
2537 /*
83ebb7f1
PP
2538 * At this point notit->dscopes.stream_packet_context
2539 * has the same value as the packet context field within
312c056a
PP
2540 * notit->packet.
2541 */
40f4ba76 2542 BT_ASSERT(bt_packet_borrow_context_field(
e5be10ef 2543 notit->packet) ==
312c056a
PP
2544 notit->dscopes.stream_packet_context);
2545 }
2546
d6e69534 2547 BT_ASSERT(notit->msg_iter);
a6d85d2f 2548
afd45274
PP
2549 if (notit->meta.sc->packets_have_ts_begin) {
2550 BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
a33f7c34 2551 msg = bt_message_packet_beginning_create_with_default_clock_snapshot(
afd45274
PP
2552 notit->msg_iter, notit->packet,
2553 notit->snapshots.beginning_clock);
a33f7c34 2554 } else {
a6d85d2f
PP
2555 msg = bt_message_packet_beginning_create(notit->msg_iter,
2556 notit->packet);
a6d85d2f
PP
2557 }
2558
d6e69534 2559 if (!msg) {
eb7f6c4f 2560 BT_COMP_LOGE("Cannot create packet beginning message: "
fdf0e7a0
PP
2561 "notit-addr=%p, packet-addr=%p",
2562 notit, notit->packet);
e22b45d0 2563 goto end;
78586d8a 2564 }
312c056a 2565
d6e69534 2566 *message = msg;
e22b45d0
PP
2567
2568end:
2569 return;
e98a2d6e
PP
2570}
2571
78586d8a 2572static
fc917f65 2573void create_msg_packet_end(struct bt_msg_iter *notit, bt_message **message)
e98a2d6e 2574{
d6e69534 2575 bt_message *msg;
e98a2d6e 2576
e98a2d6e 2577 if (!notit->packet) {
78586d8a 2578 return;
e98a2d6e
PP
2579 }
2580
44c440bc
PP
2581 /* Update default clock from packet's end time */
2582 if (notit->snapshots.end_clock != UINT64_C(-1)) {
605e1019 2583 notit->default_clock_snapshot = notit->snapshots.end_clock;
44c440bc
PP
2584 }
2585
d6e69534 2586 BT_ASSERT(notit->msg_iter);
a6d85d2f 2587
afd45274 2588 if (notit->meta.sc->packets_have_ts_end) {
a33f7c34 2589 BT_ASSERT(notit->snapshots.end_clock != UINT64_C(-1));
a6d85d2f
PP
2590 msg = bt_message_packet_end_create_with_default_clock_snapshot(
2591 notit->msg_iter, notit->packet,
2592 notit->snapshots.end_clock);
a33f7c34
PP
2593 } else {
2594 msg = bt_message_packet_end_create(notit->msg_iter,
2595 notit->packet);
a6d85d2f
PP
2596 }
2597
d6e69534 2598 if (!msg) {
eb7f6c4f 2599 BT_COMP_LOGE("Cannot create packet end message: "
fdf0e7a0
PP
2600 "notit-addr=%p, packet-addr=%p",
2601 notit, notit->packet);
78586d8a 2602 return;
ccf82993 2603
78586d8a 2604 }
e98a2d6e 2605
c5b9b441 2606 BT_PACKET_PUT_REF_AND_RESET(notit->packet);
d6e69534 2607 *message = msg;
e98a2d6e
PP
2608}
2609
495490c5
PP
2610static
2611void create_msg_discarded_events(struct bt_msg_iter *notit,
2612 bt_message **message)
2613{
2614 bt_message *msg;
2615 uint64_t beginning_raw_value = UINT64_C(-1);
2616 uint64_t end_raw_value = UINT64_C(-1);
495490c5
PP
2617
2618 BT_ASSERT(notit->msg_iter);
2619 BT_ASSERT(notit->stream);
afd45274 2620 BT_ASSERT(notit->meta.sc->has_discarded_events);
495490c5 2621
afd45274
PP
2622 if (notit->meta.sc->discarded_events_have_default_cs) {
2623 if (notit->prev_packet_snapshots.discarded_events == UINT64_C(-1)) {
2624 /*
2625 * We discarded events, but before (and possibly
2626 * including) the current packet: use this packet's time
2627 * range, and do not have a specific count.
2628 */
2629 beginning_raw_value = notit->snapshots.beginning_clock;
2630 end_raw_value = notit->snapshots.end_clock;
2631 } else {
2632 beginning_raw_value = notit->prev_packet_snapshots.end_clock;
2633 end_raw_value = notit->snapshots.end_clock;
2634 }
495490c5 2635
afd45274
PP
2636 BT_ASSERT(beginning_raw_value != UINT64_C(-1));
2637 BT_ASSERT(end_raw_value != UINT64_C(-1));
495490c5
PP
2638 msg = bt_message_discarded_events_create_with_default_clock_snapshots(
2639 notit->msg_iter, notit->stream, beginning_raw_value,
2640 end_raw_value);
2641 } else {
2642 msg = bt_message_discarded_events_create(notit->msg_iter,
2643 notit->stream);
2644 }
2645
2646 if (!msg) {
eb7f6c4f 2647 BT_COMP_LOGE("Cannot create discarded events message: "
495490c5
PP
2648 "notit-addr=%p, stream-addr=%p",
2649 notit, notit->stream);
2650 return;
2651 }
2652
afd45274
PP
2653 if (notit->prev_packet_snapshots.discarded_events != UINT64_C(-1)) {
2654 bt_message_discarded_events_set_count(msg,
2655 notit->snapshots.discarded_events -
2656 notit->prev_packet_snapshots.discarded_events);
495490c5
PP
2657 }
2658
2659 *message = msg;
2660}
2661
2662static
2663void create_msg_discarded_packets(struct bt_msg_iter *notit,
2664 bt_message **message)
2665{
2666 bt_message *msg;
2667
2668 BT_ASSERT(notit->msg_iter);
2669 BT_ASSERT(notit->stream);
afd45274 2670 BT_ASSERT(notit->meta.sc->has_discarded_packets);
495490c5
PP
2671 BT_ASSERT(notit->prev_packet_snapshots.packets !=
2672 UINT64_C(-1));
2673
afd45274
PP
2674 if (notit->meta.sc->discarded_packets_have_default_cs) {
2675 BT_ASSERT(notit->prev_packet_snapshots.end_clock != UINT64_C(-1));
2676 BT_ASSERT(notit->snapshots.beginning_clock != UINT64_C(-1));
495490c5
PP
2677 msg = bt_message_discarded_packets_create_with_default_clock_snapshots(
2678 notit->msg_iter, notit->stream,
2679 notit->prev_packet_snapshots.end_clock,
2680 notit->snapshots.beginning_clock);
2681 } else {
2682 msg = bt_message_discarded_packets_create(notit->msg_iter,
2683 notit->stream);
2684 }
2685
2686 if (!msg) {
eb7f6c4f 2687 BT_COMP_LOGE("Cannot create discarded packets message: "
495490c5
PP
2688 "notit-addr=%p, stream-addr=%p",
2689 notit, notit->stream);
2690 return;
2691 }
2692
2693 bt_message_discarded_packets_set_count(msg,
2694 notit->snapshots.packets -
2695 notit->prev_packet_snapshots.packets - 1);
2696 *message = msg;
2697}
2698
c44c3e70 2699BT_HIDDEN
d6e69534 2700struct bt_msg_iter *bt_msg_iter_create(struct ctf_trace_class *tc,
e98a2d6e 2701 size_t max_request_sz,
ea14c7dd 2702 struct bt_msg_iter_medium_ops medops, void *data,
eb7f6c4f 2703 bt_logging_level log_level, bt_self_component *self_comp)
e98a2d6e 2704{
d6e69534 2705 struct bt_msg_iter *notit = NULL;
5cd6d0e5
PP
2706 struct bt_bfcr_cbs cbs = {
2707 .classes = {
2708 .signed_int = bfcr_signed_int_cb,
2709 .unsigned_int = bfcr_unsigned_int_cb,
2710 .floating_point = bfcr_floating_point_cb,
2711 .string_begin = bfcr_string_begin_cb,
2712 .string = bfcr_string_cb,
2713 .string_end = bfcr_string_end_cb,
2714 .compound_begin = bfcr_compound_begin_cb,
2715 .compound_end = bfcr_compound_end_cb,
e98a2d6e
PP
2716 },
2717 .query = {
5cd6d0e5
PP
2718 .get_sequence_length = bfcr_get_sequence_length_cb,
2719 .borrow_variant_selected_field_class = bfcr_borrow_variant_selected_field_class_cb,
e98a2d6e
PP
2720 },
2721 };
2722
44c440bc 2723 BT_ASSERT(tc);
f6ccaed9 2724 BT_ASSERT(medops.request_bytes);
312c056a 2725 BT_ASSERT(medops.borrow_stream);
eb7f6c4f 2726 BT_COMP_LOG_CUR_LVL(BT_LOG_DEBUG, log_level, self_comp,
ea14c7dd 2727 "Creating CTF plugin message iterator: "
862ca4ed 2728 "trace-addr=%p, max-request-size=%zu, "
ea14c7dd
PP
2729 "data=%p, log-level=%s", tc, max_request_sz, data,
2730 bt_common_logging_level_string(log_level));
d6e69534 2731 notit = g_new0(struct bt_msg_iter, 1);
e98a2d6e 2732 if (!notit) {
eb7f6c4f 2733 BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_comp,
ea14c7dd 2734 "Failed to allocate one CTF plugin message iterator.");
e98a2d6e
PP
2735 goto end;
2736 }
eb7f6c4f 2737 notit->self_comp = self_comp;
ea14c7dd 2738 notit->log_level = log_level;
44c440bc 2739 notit->meta.tc = tc;
e98a2d6e
PP
2740 notit->medium.medops = medops;
2741 notit->medium.max_request_sz = max_request_sz;
2742 notit->medium.data = data;
e98a2d6e 2743 notit->stack = stack_new(notit);
44c440bc
PP
2744 notit->stored_values = g_array_new(FALSE, TRUE, sizeof(uint64_t));
2745 g_array_set_size(notit->stored_values, tc->stored_value_count);
2746
e98a2d6e 2747 if (!notit->stack) {
eb7f6c4f 2748 BT_COMP_LOGE_STR("Failed to create field stack.");
c44c3e70 2749 goto error;
e98a2d6e
PP
2750 }
2751
c4a714d2 2752 notit->bfcr = bt_bfcr_create(cbs, notit, log_level, NULL);
5cd6d0e5 2753 if (!notit->bfcr) {
eb7f6c4f 2754 BT_COMP_LOGE_STR("Failed to create binary class reader (BFCR).");
c44c3e70 2755 goto error;
e98a2d6e
PP
2756 }
2757
d6e69534 2758 bt_msg_iter_reset(notit);
eb7f6c4f 2759 BT_COMP_LOGD("Created CTF plugin message iterator: "
862ca4ed 2760 "trace-addr=%p, max-request-size=%zu, "
ea14c7dd
PP
2761 "data=%p, notit-addr=%p, log-level=%s",
2762 tc, max_request_sz, data, notit,
2763 bt_common_logging_level_string(log_level));
9e0c8dbb 2764 notit->cur_packet_offset = 0;
fdf0e7a0 2765
e98a2d6e
PP
2766end:
2767 return notit;
fdf0e7a0 2768
c44c3e70 2769error:
d6e69534 2770 bt_msg_iter_destroy(notit);
c44c3e70
JG
2771 notit = NULL;
2772 goto end;
e98a2d6e
PP
2773}
2774
d6e69534 2775void bt_msg_iter_destroy(struct bt_msg_iter *notit)
e98a2d6e 2776{
c5b9b441
PP
2777 BT_PACKET_PUT_REF_AND_RESET(notit->packet);
2778 BT_STREAM_PUT_REF_AND_RESET(notit->stream);
312c056a 2779 release_all_dscopes(notit);
e98a2d6e 2780
eb7f6c4f 2781 BT_COMP_LOGD("Destroying CTF plugin message iterator: addr=%p", notit);
fdf0e7a0 2782
e98a2d6e 2783 if (notit->stack) {
eb7f6c4f 2784 BT_COMP_LOGD_STR("Destroying field stack.");
e98a2d6e
PP
2785 stack_destroy(notit->stack);
2786 }
2787
5cd6d0e5 2788 if (notit->bfcr) {
eb7f6c4f 2789 BT_COMP_LOGD("Destroying BFCR: bfcr-addr=%p", notit->bfcr);
5cd6d0e5 2790 bt_bfcr_destroy(notit->bfcr);
e98a2d6e
PP
2791 }
2792
44c440bc
PP
2793 if (notit->stored_values) {
2794 g_array_free(notit->stored_values, TRUE);
5f870343 2795 }
fdf0e7a0 2796
e98a2d6e
PP
2797 g_free(notit);
2798}
2799
d6e69534
PP
2800enum bt_msg_iter_status bt_msg_iter_get_next_message(
2801 struct bt_msg_iter *notit,
fc917f65 2802 bt_self_message_iterator *msg_iter, bt_message **message)
e98a2d6e 2803{
d6e69534 2804 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
e98a2d6e 2805
f6ccaed9 2806 BT_ASSERT(notit);
d6e69534 2807 BT_ASSERT(message);
d6e69534 2808 notit->msg_iter = msg_iter;
495490c5 2809 notit->set_stream = true;
eb7f6c4f 2810 BT_COMP_LOGD("Getting next message: notit-addr=%p", notit);
fdf0e7a0 2811
e98a2d6e
PP
2812 while (true) {
2813 status = handle_state(notit);
91d81473 2814 if (G_UNLIKELY(status == BT_MSG_ITER_STATUS_AGAIN)) {
eb7f6c4f 2815 BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
7cdc2bab 2816 goto end;
91d81473 2817 } else if (G_UNLIKELY(status != BT_MSG_ITER_STATUS_OK)) {
eb7f6c4f 2818 BT_COMP_LOGW("Cannot handle state: notit-addr=%p, state=%s",
fc917f65 2819 notit, state_string(notit->state));
e98a2d6e
PP
2820 goto end;
2821 }
2822
2823 switch (notit->state) {
fc917f65
PP
2824 case STATE_EMIT_MSG_EVENT:
2825 BT_ASSERT(notit->event_msg);
fc917f65
PP
2826 *message = notit->event_msg;
2827 notit->event_msg = NULL;
495490c5
PP
2828 goto end;
2829 case STATE_EMIT_MSG_DISCARDED_EVENTS:
2830 /* create_msg_discared_events() logs errors */
2831 create_msg_discarded_events(notit, message);
2832
2833 if (!*message) {
2834 status = BT_MSG_ITER_STATUS_ERROR;
2835 }
2836
2837 goto end;
2838 case STATE_EMIT_MSG_DISCARDED_PACKETS:
2839 /* create_msg_discared_packets() logs errors */
2840 create_msg_discarded_packets(notit, message);
2841
2842 if (!*message) {
2843 status = BT_MSG_ITER_STATUS_ERROR;
2844 }
2845
fc917f65
PP
2846 goto end;
2847 case STATE_EMIT_MSG_PACKET_BEGINNING:
2848 /* create_msg_packet_beginning() logs errors */
2849 create_msg_packet_beginning(notit, message);
44c440bc 2850
d6e69534
PP
2851 if (!*message) {
2852 status = BT_MSG_ITER_STATUS_ERROR;
f42867e2 2853 }
44c440bc 2854
f42867e2 2855 goto end;
fc917f65
PP
2856 case STATE_EMIT_MSG_PACKET_END_SINGLE:
2857 case STATE_EMIT_MSG_PACKET_END_MULTI:
2858 /* create_msg_packet_end() logs errors */
2859 create_msg_packet_end(notit, message);
44c440bc 2860
d6e69534
PP
2861 if (!*message) {
2862 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e 2863 }
312c056a 2864
e98a2d6e 2865 goto end;
fc917f65 2866 case STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING:
495490c5
PP
2867 /* create_msg_stream_activity_beginning() logs errors */
2868 create_msg_stream_activity_beginning(notit, message);
fc917f65 2869
495490c5
PP
2870 if (!*message) {
2871 status = BT_MSG_ITER_STATUS_ERROR;
e98a2d6e 2872 }
312c056a 2873
495490c5 2874 goto end;
fc917f65 2875 case STATE_EMIT_MSG_STREAM_ACTIVITY_END:
495490c5
PP
2876 /* create_msg_stream_activity_end() logs errors */
2877 create_msg_stream_activity_end(notit, message);
fc917f65 2878
495490c5
PP
2879 if (!*message) {
2880 status = BT_MSG_ITER_STATUS_ERROR;
fc917f65
PP
2881 }
2882
495490c5 2883 goto end;
fc917f65 2884 case STATE_EMIT_MSG_STREAM_BEGINNING:
495490c5
PP
2885 /* create_msg_stream_beginning() logs errors */
2886 create_msg_stream_beginning(notit, message);
fc917f65 2887
495490c5
PP
2888 if (!*message) {
2889 status = BT_MSG_ITER_STATUS_ERROR;
fc917f65
PP
2890 }
2891
495490c5 2892 goto end;
fc917f65 2893 case STATE_EMIT_MSG_STREAM_END:
495490c5
PP
2894 /* create_msg_stream_end() logs errors */
2895 create_msg_stream_end(notit, message);
fc917f65 2896
495490c5
PP
2897 if (!*message) {
2898 status = BT_MSG_ITER_STATUS_ERROR;
fc917f65
PP
2899 }
2900
495490c5 2901 goto end;
fc917f65
PP
2902 case STATE_DONE:
2903 status = BT_MSG_ITER_STATUS_EOF;
e98a2d6e
PP
2904 goto end;
2905 default:
2906 /* Non-emitting state: continue */
2907 break;
2908 }
2909 }
2910
2911end:
2912 return status;
2913}
87187cbf 2914
41693723
PP
2915static
2916enum bt_msg_iter_status read_packet_header_context_fields(
2917 struct bt_msg_iter *notit)
87187cbf 2918{
9e0c8dbb 2919 int ret;
d6e69534 2920 enum bt_msg_iter_status status = BT_MSG_ITER_STATUS_OK;
87187cbf 2921
f6ccaed9 2922 BT_ASSERT(notit);
495490c5 2923 notit->set_stream = false;
87187cbf 2924
fc917f65 2925 if (notit->state == STATE_EMIT_MSG_PACKET_BEGINNING) {
87187cbf 2926 /* We're already there */
41693723 2927 goto end;
87187cbf
PP
2928 }
2929
2930 while (true) {
2931 status = handle_state(notit);
91d81473 2932 if (G_UNLIKELY(status == BT_MSG_ITER_STATUS_AGAIN)) {
eb7f6c4f 2933 BT_COMP_LOGD_STR("Medium returned BT_MSG_ITER_STATUS_AGAIN.");
87187cbf 2934 goto end;
91d81473 2935 } else if (G_UNLIKELY(status != BT_MSG_ITER_STATUS_OK)) {
eb7f6c4f 2936 BT_COMP_LOGW("Cannot handle state: notit-addr=%p, state=%s",
fc917f65 2937 notit, state_string(notit->state));
87187cbf
PP
2938 goto end;
2939 }
2940
2941 switch (notit->state) {
fc917f65 2942 case STATE_EMIT_MSG_PACKET_BEGINNING:
87187cbf
PP
2943 /*
2944 * Packet header and context fields are
2945 * potentially decoded (or they don't exist).
2946 */
41693723 2947 goto end;
87187cbf
PP
2948 case STATE_INIT:
2949 case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
2950 case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
2951 case STATE_AFTER_TRACE_PACKET_HEADER:
2952 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN:
2953 case STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE:
2954 case STATE_AFTER_STREAM_PACKET_CONTEXT:
495490c5 2955 case STATE_CHECK_EMIT_MSG_STREAM_BEGINNING:
fc917f65
PP
2956 case STATE_EMIT_MSG_STREAM_BEGINNING:
2957 case STATE_EMIT_MSG_STREAM_ACTIVITY_BEGINNING:
495490c5
PP
2958 case STATE_CHECK_EMIT_MSG_DISCARDED_EVENTS:
2959 case STATE_EMIT_MSG_DISCARDED_EVENTS:
2960 case STATE_CHECK_EMIT_MSG_DISCARDED_PACKETS:
2961 case STATE_EMIT_MSG_DISCARDED_PACKETS:
87187cbf
PP
2962 /* Non-emitting state: continue */
2963 break;
2964 default:
2965 /*
2966 * We should never get past the
fc917f65 2967 * STATE_EMIT_MSG_PACKET_BEGINNING state.
87187cbf 2968 */
eb7f6c4f 2969 BT_COMP_LOGF("Unexpected state: notit-addr=%p, state=%s",
fdf0e7a0 2970 notit, state_string(notit->state));
0fbb9a9f 2971 abort();
87187cbf
PP
2972 }
2973 }
2974
41693723 2975end:
312c056a
PP
2976 ret = set_current_packet_content_sizes(notit);
2977 if (ret) {
d6e69534 2978 status = BT_MSG_ITER_STATUS_ERROR;
312c056a
PP
2979 }
2980
87187cbf
PP
2981 return status;
2982}
6de92955
PP
2983
2984BT_HIDDEN
d6e69534 2985void bt_msg_iter_set_medops_data(struct bt_msg_iter *notit,
6de92955
PP
2986 void *medops_data)
2987{
f6ccaed9 2988 BT_ASSERT(notit);
6de92955
PP
2989 notit->medium.data = medops_data;
2990}
9e0c8dbb
JG
2991
2992BT_HIDDEN
fc917f65
PP
2993enum bt_msg_iter_status bt_msg_iter_seek(struct bt_msg_iter *notit,
2994 off_t offset)
9e0c8dbb 2995{
d6e69534
PP
2996 enum bt_msg_iter_status ret = BT_MSG_ITER_STATUS_OK;
2997 enum bt_msg_iter_medium_status medium_status;
9e0c8dbb 2998
f6ccaed9 2999 BT_ASSERT(notit);
9e0c8dbb 3000 if (offset < 0) {
eb7f6c4f 3001 BT_COMP_LOGE("Cannot seek to negative offset: offset=%jd", offset);
d6e69534 3002 ret = BT_MSG_ITER_STATUS_INVAL;
9e0c8dbb
JG
3003 goto end;
3004 }
3005
3006 if (!notit->medium.medops.seek) {
d6e69534 3007 ret = BT_MSG_ITER_STATUS_UNSUPPORTED;
eb7f6c4f 3008 BT_COMP_LOGD("Aborting seek as the iterator's underlying media does not implement seek support.");
9e0c8dbb
JG
3009 goto end;
3010 }
3011
3012 medium_status = notit->medium.medops.seek(
d6e69534
PP
3013 BT_MSG_ITER_SEEK_WHENCE_SET, offset, notit->medium.data);
3014 if (medium_status != BT_MSG_ITER_MEDIUM_STATUS_OK) {
3015 if (medium_status == BT_MSG_ITER_MEDIUM_STATUS_EOF) {
3016 ret = BT_MSG_ITER_STATUS_EOF;
9e0c8dbb 3017 } else {
d6e69534 3018 ret = BT_MSG_ITER_STATUS_ERROR;
9e0c8dbb
JG
3019 goto end;
3020 }
3021 }
3022
d6e69534 3023 bt_msg_iter_reset(notit);
9e0c8dbb 3024 notit->cur_packet_offset = offset;
44c440bc 3025
9e0c8dbb
JG
3026end:
3027 return ret;
3028}
3029
44c440bc 3030BT_HIDDEN
d6e69534
PP
3031enum bt_msg_iter_status bt_msg_iter_get_packet_properties(
3032 struct bt_msg_iter *notit,
3033 struct bt_msg_iter_packet_properties *props)
44c440bc 3034{
41693723
PP
3035 enum bt_msg_iter_status status;
3036
44c440bc
PP
3037 BT_ASSERT(notit);
3038 BT_ASSERT(props);
41693723
PP
3039 status = read_packet_header_context_fields(notit);
3040 if (status != BT_MSG_ITER_STATUS_OK) {
3041 goto end;
3042 }
44c440bc 3043
fc917f65
PP
3044 props->exp_packet_total_size = notit->cur_exp_packet_total_size;
3045 props->exp_packet_content_size = notit->cur_exp_packet_content_size;
44c440bc
PP
3046 props->stream_class_id = (uint64_t) notit->cur_stream_class_id;
3047 props->data_stream_id = notit->cur_data_stream_id;
3048 props->snapshots.discarded_events = notit->snapshots.discarded_events;
3049 props->snapshots.packets = notit->snapshots.packets;
3050 props->snapshots.beginning_clock = notit->snapshots.beginning_clock;
3051 props->snapshots.end_clock = notit->snapshots.end_clock;
41693723
PP
3052
3053end:
3054 return status;
9e0c8dbb 3055}
fc917f65
PP
3056
3057BT_HIDDEN
3058void bt_msg_iter_set_emit_stream_beginning_message(struct bt_msg_iter *notit,
3059 bool val)
3060{
3061 notit->emit_stream_begin_msg = val;
3062}
3063
3064BT_HIDDEN
3065void bt_msg_iter_set_emit_stream_end_message(struct bt_msg_iter *notit,
3066 bool val)
3067{
3068 notit->emit_stream_end_msg = val;
3069}
This page took 0.263482 seconds and 4 git commands to generate.