-
- BT_PUT(field);
-
- if (!next_field) {
- BT_LOGW("Cannot find next field: "
- "notit-addr=%p, ft-addr=%p, ft-id=%s, index=%d",
- notit, field_type,
- bt_common_field_type_id_string(
- bt_field_type_get_type_id(field_type)),
- index);
- goto end;
- }
-
- /* Move next field -> field */
- BT_MOVE(field, next_field);
- }
-
-end:
- return field;
-}
-
-static
-int64_t btr_get_sequence_length_cb(struct bt_field_type *type, void *data)
-{
- int64_t ret = -1;
- int iret;
- struct bt_field *seq_field;
- struct bt_field_path *field_path;
- struct bt_notif_iter *notit = data;
- struct bt_field *length_field = NULL;
- uint64_t length;
-
- field_path = bt_field_type_sequence_borrow_length_field_path(type);
- BT_ASSERT(field_path);
- length_field = resolve_field(notit, field_path);
- if (!length_field) {
- BT_LOGW("Cannot resolve sequence field type's length field path: "
- "notit-addr=%p, ft-addr=%p",
- notit, type);
- goto end;
- }
-
- iret = bt_field_integer_unsigned_get_value(length_field, &length);
- if (iret) {
- BT_LOGE("Cannot get value of sequence length field: "
- "notit-addr=%p, field-addr=%p",
- notit, length_field);
- goto end;
- }
-
- seq_field = stack_top(notit->stack)->base;
- iret = bt_field_sequence_set_length(seq_field, length_field);
- if (iret) {
- BT_LOGE("Cannot set sequence field's length field: "
- "notit-addr=%p, seq-field-addr=%p, "
- "length-field-addr=%p, ",
- notit, seq_field, length_field);
- goto end;
- }
-
- ret = (int64_t) length;
-
-end:
- BT_PUT(length_field);
- return ret;
-}
-
-static
-struct bt_field_type *btr_borrow_variant_field_type_cb(
- struct bt_field_type *type, void *data)
-{
- struct bt_field_path *path;
- struct bt_notif_iter *notit = data;
- struct bt_field *var_field;
- struct bt_field *tag_field = NULL;
- struct bt_field *selected_field = NULL;
- struct bt_field_type *selected_field_type = NULL;
-
- path = bt_field_type_variant_borrow_tag_field_path(type);
- BT_ASSERT(path);
- tag_field = resolve_field(notit, path);
- if (!tag_field) {
- BT_LOGW("Cannot resolve variant field type's tag field path: "
- "notit-addr=%p, ft-addr=%p",
- notit, type);
- goto end;
- }
-
- /*
- * We found the enumeration tag field instance which should be
- * able to select a current field for this variant. This
- * callback function we're in is called _after_
- * compound_begin(), so the current stack top's base field is
- * the variant field in question. We get the selected field here
- * thanks to this tag field (thus creating the selected field),
- * which will also provide us with its type. Then, this field
- * will remain the current selected one until the next callback
- * function call which is used to fill the current selected
- * field.
- */
- var_field = stack_top(notit->stack)->base;
- selected_field = bt_field_variant_get_field(var_field, tag_field);
- if (!selected_field) {
- BT_LOGW("Cannot get variant field's selection using tag field: "
- "notit-addr=%p, var-field-addr=%p, tag-field-addr=%p",
- notit, var_field, tag_field);
- goto end;
- }
-
- selected_field_type = bt_field_borrow_type(selected_field);
-
-end:
- BT_PUT(tag_field);
- BT_PUT(selected_field);
- return selected_field_type;
-}
-
-static
-int set_event_clocks(struct bt_event *event,
- struct bt_notif_iter *notit)
-{
- int ret;
- GHashTableIter iter;
- struct bt_clock_class *clock_class;
- uint64_t *clock_state;
-
- g_hash_table_iter_init(&iter, notit->clock_states);
-
- while (g_hash_table_iter_next(&iter, (gpointer) &clock_class,
- (gpointer) &clock_state)) {
- struct bt_clock_value *clock_value;
-
- clock_value = bt_clock_value_create(clock_class,
- *clock_state);
- if (!clock_value) {
- BT_LOGE("Cannot create clock value from clock class: "
- "notit-addr=%p, clock-class-addr=%p, "
- "clock-class-name=\"%s\"",
- notit, clock_class,
- bt_clock_class_get_name(clock_class));
- ret = -1;
- goto end;
- }
- ret = bt_event_set_clock_value(event, clock_value);
- bt_put(clock_value);
- if (ret) {
- struct bt_event_class *event_class =
- bt_event_borrow_class(event);
-
- BT_ASSERT(event_class);
- BT_LOGE("Cannot set event's clock value: "
- "notit-addr=%p, event-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64 ", "
- "clock-class-addr=%p, "
- "clock-class-name=\"%s\", "
- "clock-value-addr=%p",
- notit, event,
- bt_event_class_get_name(event_class),
- bt_event_class_get_id(event_class),
- clock_class,
- bt_clock_class_get_name(clock_class),
- clock_value);
- goto end;
- }
- }
-
- ret = 0;
-end:
- return ret;
-}
-
-static
-struct bt_event *create_event(struct bt_notif_iter *notit)
-{
- int ret;
- struct bt_event *event;
-
- BT_LOGV("Creating event for event notification: "
- "notit-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- notit, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class));
-
- /* Create event object. */
- event = bt_event_create(notit->meta.event_class);
- if (!event) {
- BT_LOGE("Cannot create event: "
- "notit-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- notit, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class));
- goto error;
- }
-
- /* Set header, stream event context, context, and payload fields. */
- ret = bt_event_set_header(event,
- notit->dscopes.stream_event_header);
- if (ret) {
- BT_LOGE("Cannot set event's header field: "
- "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64 ", field-addr=%p",
- notit, event, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class),
- notit->dscopes.stream_event_header);
- goto error;
- }
-
- ret = bt_event_set_stream_event_context(event,
- notit->dscopes.stream_event_context);
- if (ret) {
- BT_LOGE("Cannot set event's context field: "
- "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64 ", field-addr=%p",
- notit, event, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class),
- notit->dscopes.stream_event_context);
- goto error;
- }
-
- ret = bt_event_set_context(event,
- notit->dscopes.event_context);
- if (ret) {
- BT_LOGE("Cannot set event's stream event context field: "
- "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64 ", field-addr=%p",
- notit, event, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class),
- notit->dscopes.event_context);
- goto error;