- 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);
- BT_PUT(field_path);
-
- return ret;
-}
-
-static
-struct bt_field_type *btr_get_variant_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_get_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_get_type(selected_field);
-
-end:
- BT_PUT(tag_field);
- BT_PUT(selected_field);
- BT_PUT(path);
-
- 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_get_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);
- bt_put(event_class);
- 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;
- }
-
- ret = bt_event_set_payload(event,
- notit->dscopes.event_payload);
- if (ret) {
- BT_LOGE("Cannot set event's payload 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_payload);
- goto error;
- }
-
- ret = set_event_clocks(event, notit);
- if (ret) {
- BT_LOGE("Cannot set event's clock values: "
- "notit-addr=%p, event-addr=%p, event-class-addr=%p, "
- "event-class-name=\"%s\", "
- "event-class-id=%" PRId64,
- notit, event, notit->meta.event_class,
- bt_event_class_get_name(notit->meta.event_class),
- bt_event_class_get_id(notit->meta.event_class));
- goto error;
- }
-
- /* Associate with current packet. */
- BT_ASSERT(notit->packet);
- ret = bt_event_set_packet(event, notit->packet);
- 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 ", packet-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->packet);
- goto error;
- }
-
- goto end;
-
-error:
- BT_PUT(event);
-
-end:
- return event;
-}
-
-static
-uint64_t get_cur_stream_instance_id(struct bt_notif_iter *notit)
-{
- struct bt_field *stream_instance_id_field = NULL;
- uint64_t stream_instance_id = -1ULL;
- int ret;
-
- if (!notit->dscopes.trace_packet_header) {
- goto end;
- }
-
- stream_instance_id_field = bt_field_structure_get_field_by_name(
- notit->dscopes.trace_packet_header, "stream_instance_id");
- if (!stream_instance_id_field) {
- goto end;
- }
-
- ret = bt_field_integer_unsigned_get_value(stream_instance_id_field,
- &stream_instance_id);
- if (ret) {
- stream_instance_id = -1ULL;
- goto end;
- }
-
-end:
- bt_put(stream_instance_id_field);
- return stream_instance_id;
-}
-
-static
-int set_stream(struct bt_notif_iter *notit)
-{
- int ret = 0;
- struct bt_stream *stream = NULL;
-
- BT_LOGV("Calling user function (get stream): notit-addr=%p, "
- "stream-class-addr=%p, stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64,
- notit, notit->meta.stream_class,
- bt_stream_class_get_name(notit->meta.stream_class),
- bt_stream_class_get_id(notit->meta.stream_class));
- stream = bt_get(notit->medium.medops.get_stream(
- notit->meta.stream_class, get_cur_stream_instance_id(notit),
- notit->medium.data));
- BT_LOGV("User function returned: stream-addr=%p", stream);
- if (!stream) {
- BT_LOGW_STR("User function failed to return a stream object for the given stream class.");
- ret = -1;
- goto end;
- }
-
- if (notit->stream && stream != notit->stream) {
- BT_LOGW("User function returned a different stream than the previous one for the same sequence of packets.");
- ret = -1;
- goto end;
- }
-
- BT_MOVE(notit->stream, stream);
-
-end:
- bt_put(stream);
- return ret;
-}
-
-static
-void create_packet(struct bt_notif_iter *notit)
-{
- int ret;
- struct bt_packet *packet = NULL;
-
- BT_LOGV("Creating packet for packet notification: "
- "notit-addr=%p", notit);
- BT_LOGV("Creating packet from stream: "
- "notit-addr=%p, stream-addr=%p, "
- "stream-class-addr=%p, "
- "stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64,
- notit, notit->stream, notit->meta.stream_class,
- bt_stream_class_get_name(notit->meta.stream_class),
- bt_stream_class_get_id(notit->meta.stream_class));
-
- /* Create packet */
- BT_ASSERT(notit->stream);
- packet = bt_packet_create(notit->stream);
- if (!packet) {
- BT_LOGE("Cannot create packet from stream: "
- "notit-addr=%p, stream-addr=%p, "
- "stream-class-addr=%p, "
- "stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64,
- notit, notit->stream, notit->meta.stream_class,
- bt_stream_class_get_name(notit->meta.stream_class),
- bt_stream_class_get_id(notit->meta.stream_class));
- goto error;
- }
-
- /* Set packet's context and header fields */
- if (notit->dscopes.trace_packet_header) {
- ret = bt_packet_set_header(packet,
- notit->dscopes.trace_packet_header);
- if (ret) {
- BT_LOGE("Cannot set packet's header field: "
- "notit-addr=%p, packet-addr=%p, "
- "stream-addr=%p, "
- "stream-class-addr=%p, "
- "stream-class-name=\"%s\", "
- "stream-class-id=%" PRId64 ", "
- "field-addr=%p",
- notit, packet, notit->stream, notit->meta.stream_class,
- bt_stream_class_get_name(notit->meta.stream_class),
- bt_stream_class_get_id(notit->meta.stream_class),
- notit->dscopes.trace_packet_header);
- goto error;
- }