#include <babeltrace/assert-internal.h>
#include <string.h>
#include <babeltrace/babeltrace.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/field-path-internal.h>
+#include <babeltrace/common-internal.h>
#include <glib.h>
#include <stdlib.h>
STATE_DSCOPE_STREAM_PACKET_CONTEXT_BEGIN,
STATE_DSCOPE_STREAM_PACKET_CONTEXT_CONTINUE,
STATE_AFTER_STREAM_PACKET_CONTEXT,
+ STATE_EMIT_NOTIF_NEW_STREAM,
STATE_EMIT_NOTIF_NEW_PACKET,
STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN,
STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE,
STATE_DSCOPE_EVENT_PAYLOAD_CONTINUE,
STATE_EMIT_NOTIF_EVENT,
STATE_EMIT_NOTIF_END_OF_PACKET,
+ STATE_DONE,
STATE_SKIP_PACKET_PADDING,
};
void *data;
} medium;
+ /* Stream beginning was emitted */
+ bool stream_begin_emitted;
+
/* Current packet size (bits) (-1 if unknown) */
int64_t cur_packet_size;
return "STATE_AFTER_STREAM_PACKET_CONTEXT";
case STATE_EMIT_NOTIF_NEW_PACKET:
return "STATE_EMIT_NOTIF_NEW_PACKET";
+ case STATE_EMIT_NOTIF_NEW_STREAM:
+ return "STATE_EMIT_NOTIF_NEW_STREAM";
case STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN:
return "STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN";
case STATE_DSCOPE_STREAM_EVENT_HEADER_CONTINUE:
return "STATE_EMIT_NOTIF_EVENT";
case STATE_EMIT_NOTIF_END_OF_PACKET:
return "STATE_EMIT_NOTIF_END_OF_PACKET";
+ case STATE_DONE:
+ return "STATE_DONE";
case STATE_SKIP_PACKET_PADDING:
return "STATE_SKIP_PACKET_PADDING";
default:
}
/* Packet header type is common to the whole trace. */
- packet_header_type = bt_trace_get_packet_header_type(
+ packet_header_type = bt_trace_get_packet_header_field_type(
notit->meta.trace);
if (!packet_header_type) {
notit->state = STATE_AFTER_TRACE_PACKET_HEADER;
goto end;
}
- event_header = bt_stream_class_get_event_header_type(stream_class);
+ event_header = bt_stream_class_get_event_header_field_type(stream_class);
if (event_header && bt_field_type_is_structure(event_header)) {
int i, count;
}
}
- packet_context = bt_stream_class_get_packet_context_type(
+ packet_context = bt_stream_class_get_packet_context_field_type(
stream_class);
if (packet_context && bt_field_type_is_structure(packet_context)) {
int i, count;
notit->cur_sc_field_path_cache = NULL;
/* Is there any "stream_id" field in the packet header? */
- packet_header_type = bt_trace_get_packet_header_type(
+ packet_header_type = bt_trace_get_packet_header_field_type(
notit->meta.trace);
if (!packet_header_type) {
/*
stream_id_field = bt_field_structure_get_field_by_name(
notit->dscopes.trace_packet_header, "stream_id");
BT_ASSERT(stream_id_field);
- ret = bt_field_unsigned_integer_get_value(
+ ret = bt_field_integer_unsigned_get_value(
stream_id_field, &stream_id);
BT_ASSERT(!ret);
BT_PUT(stream_id_field);
struct bt_field_type *packet_context_type;
BT_ASSERT(notit->meta.stream_class);
- packet_context_type = bt_stream_class_get_packet_context_type(
+ packet_context_type = bt_stream_class_get_packet_context_field_type(
notit->meta.stream_class);
if (!packet_context_type) {
BT_LOGV("No packet packet context field type in stream class: continuing: "
content_size_field = bt_field_structure_get_field_by_name(
notit->dscopes.stream_packet_context, "content_size");
if (packet_size_field) {
- int ret = bt_field_unsigned_integer_get_value(
+ int ret = bt_field_integer_unsigned_get_value(
packet_size_field, &packet_size);
BT_ASSERT(ret == 0);
}
if (content_size_field) {
- int ret = bt_field_unsigned_integer_get_value(
+ int ret = bt_field_integer_unsigned_get_value(
content_size_field, &content_size);
BT_ASSERT(ret == 0);
status = set_current_packet_content_sizes(notit);
if (status == BT_NOTIF_ITER_STATUS_OK) {
- notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+ if (notit->stream_begin_emitted) {
+ notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+ } else {
+ notit->state = STATE_EMIT_NOTIF_NEW_STREAM;
+ }
}
return status;
}
}
- event_header_type = bt_stream_class_get_event_header_type(
+ event_header_type = bt_stream_class_get_event_header_field_type(
notit->meta.stream_class);
if (!event_header_type) {
notit->state = STATE_AFTER_STREAM_EVENT_HEADER;
uint64_t event_id = -1ULL;
int ret;
- event_header_type = bt_stream_class_get_event_header_type(
+ event_header_type = bt_stream_class_get_event_header_field_type(
notit->meta.stream_class);
if (!event_header_type) {
/*
}
if (bt_field_is_integer(v_struct_id_field)) {
- ret = bt_field_unsigned_integer_get_value(
+ ret = bt_field_integer_unsigned_get_value(
v_struct_id_field, &event_id);
if (ret) {
BT_LOGV("Cannot get value of unsigned integer field (`id`): continuing: "
}
if (bt_field_is_integer(id_field)) {
- ret_get_value = bt_field_unsigned_integer_get_value(
+ ret_get_value = bt_field_integer_unsigned_get_value(
id_field, &event_id);
} else if (bt_field_is_enumeration(id_field)) {
struct bt_field *container;
container = bt_field_enumeration_get_container(
id_field);
BT_ASSERT(container);
- ret_get_value = bt_field_unsigned_integer_get_value(
+ ret_get_value = bt_field_integer_unsigned_get_value(
container, &event_id);
BT_PUT(container);
}
enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
struct bt_field_type *stream_event_context_type;
- stream_event_context_type = bt_stream_class_get_event_context_type(
- notit->meta.stream_class);
+ stream_event_context_type =
+ bt_stream_class_get_event_context_field_type(
+ notit->meta.stream_class);
if (!stream_event_context_type) {
notit->state = STATE_DSCOPE_EVENT_CONTEXT_BEGIN;
goto end;
enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
struct bt_field_type *event_context_type;
- event_context_type = bt_event_class_get_context_type(
+ event_context_type = bt_event_class_get_context_field_type(
notit->meta.event_class);
if (!event_context_type) {
notit->state = STATE_DSCOPE_EVENT_PAYLOAD_BEGIN;
enum bt_notif_iter_status status = BT_NOTIF_ITER_STATUS_OK;
struct bt_field_type *event_payload_type;
- event_payload_type = bt_event_class_get_payload_type(
+ event_payload_type = bt_event_class_get_payload_field_type(
notit->meta.event_class);
if (!event_payload_type) {
notit->state = STATE_EMIT_NOTIF_EVENT;
case STATE_AFTER_STREAM_PACKET_CONTEXT:
status = after_packet_context_state(notit);
break;
+ case STATE_EMIT_NOTIF_NEW_STREAM:
+ notit->state = STATE_EMIT_NOTIF_NEW_PACKET;
+ break;
case STATE_EMIT_NOTIF_NEW_PACKET:
notit->state = STATE_DSCOPE_STREAM_EVENT_HEADER_BEGIN;
break;
/**
* Resets the internal state of a CTF notification iterator.
*/
-static
+BT_HIDDEN
void bt_notif_iter_reset(struct bt_notif_iter *notit)
{
BT_ASSERT(notit);
notit->cur_content_size = -1;
notit->cur_packet_size = -1;
notit->cur_packet_offset = -1;
+ notit->stream_begin_emitted = false;
}
static
switch (bt_field_type_get_type_id(base_type)) {
case BT_FIELD_TYPE_ID_STRUCT:
+ {
next_field = bt_field_structure_get_field_by_index(
base_field, index);
+ const char *name;
+ bt_field_type_structure_get_field_by_index(base_type,
+ &name, NULL, index);
break;
+ }
case BT_FIELD_TYPE_ID_ARRAY:
next_field = bt_field_array_get_field(base_field, index);
break;
BT_LOGF("Unknown base field type ID: "
"notit-addr=%p, ft-addr=%p, ft-id=%s",
notit, base_type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(base_type)));
abort();
}
requested_new_value_size =
bt_field_type_integer_get_size(value_type);
BT_ASSERT(requested_new_value_size > 0);
- ret = bt_field_unsigned_integer_get_value(value_field,
+ ret = bt_field_integer_unsigned_get_value(value_field,
&requested_new_value);
BT_ASSERT(!ret);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s, value=%" PRIu64,
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
value);
BT_LOGF("Unexpected field type ID: "
"notit-addr=%p, ft-addr=%p, ft-id=%s",
notit, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
abort();
}
BT_ASSERT(int_field);
- ret = bt_field_unsigned_integer_set_value(int_field, value);
+ ret = bt_field_integer_unsigned_set_value(int_field, value);
BT_ASSERT(ret == 0);
stack_top(notit->stack)->index++;
*out_int_field = int_field;
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
status = btr_unsigned_int_common(*((uint64_t *) value), type, data,
&field);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s, value=%" PRIu64,
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
value);
override = g_hash_table_lookup(notit->field_overrides, type);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s, value=%" PRId64,
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
value);
BT_LOGF("Unexpected field type ID: "
"notit-addr=%p, ft-addr=%p, ft-id=%s",
notit, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
abort();
}
BT_ASSERT(int_field);
- ret = bt_field_signed_integer_set_value(int_field, value);
+ ret = bt_field_integer_signed_set_value(int_field, value);
BT_ASSERT(!ret);
stack_top(notit->stack)->index++;
status = update_clock(notit, int_field);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s, value=%f",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
value);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
/* Create next field */
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s, string-length=%zu",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
len);
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
/* Pop string field */
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
/* Create field */
BT_LOGE("Cannot create compound field: "
"notit-addr=%p, ft-addr=%p, ft-id=%s",
notit, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
status = BT_BTR_STATUS_ERROR;
goto end;
BT_LOGE("Cannot push compound field onto the stack: "
"notit-addr=%p, ft-addr=%p, ft-id=%s, ret=%d",
notit, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)),
ret);
status = BT_BTR_STATUS_ERROR;
"notit-addr=%p, btr-addr=%p, ft-addr=%p, "
"ft-id=%s",
notit, notit->btr, type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(type)));
BT_ASSERT(!stack_empty(notit->stack));
default:
BT_LOGF("Cannot resolve field path: unknown scope: "
"notit-addr=%p, root-scope=%s",
- notit, bt_scope_string(
+ notit, bt_common_scope_string(
bt_field_path_get_root_scope(path)));
abort();
}
if (!field) {
BT_LOGW("Cannot resolve field path: root field not found: "
"notit-addr=%p, root-scope=%s",
- notit, bt_scope_string(
+ notit, bt_common_scope_string(
bt_field_path_get_root_scope(path)));
goto end;
}
BT_LOGW("Cannot find next field: "
"notit-addr=%p, ft-addr=%p, ft-id=%s, index=%d",
notit, field_type,
- bt_field_type_id_string(
+ bt_common_field_type_id_string(
bt_field_type_get_type_id(field_type)),
index);
goto end;
goto end;
}
- iret = bt_field_unsigned_integer_get_value(length_field, &length);
+ 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",
goto error;
}
- ret = bt_event_set_event_context(event,
+ ret = bt_event_set_context(event,
notit->dscopes.event_context);
if (ret) {
BT_LOGE("Cannot set event's stream event context field: "
goto error;
}
- ret = bt_event_set_event_payload(event,
+ ret = bt_event_set_payload(event,
notit->dscopes.event_payload);
if (ret) {
BT_LOGE("Cannot set event's payload field: "
goto end;
}
- ret = bt_field_unsigned_integer_get_value(stream_instance_id_field,
+ ret = bt_field_integer_unsigned_get_value(stream_instance_id_field,
&stream_instance_id);
if (ret) {
stream_instance_id = -1ULL;
BT_LOGV("Creating packet for packet notification: "
"notit-addr=%p", notit);
-
- /* Ask the user for the stream */
- ret = set_stream(notit);
- if (ret) {
- goto error;
- }
-
BT_LOGV("Creating packet from stream: "
"notit-addr=%p, stream-addr=%p, "
"stream-class-addr=%p, "
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: "
BT_MOVE(notit->packet, packet);
}
+static
+void notify_new_stream(struct bt_notif_iter *notit,
+ struct bt_notification **notification)
+{
+ struct bt_notification *ret = NULL;
+ int iret;
+
+ /* Ask the user for the stream */
+ iret = set_stream(notit);
+ if (iret) {
+ goto end;
+ }
+
+ BT_ASSERT(notit->stream);
+ ret = bt_notification_stream_begin_create(notit->stream);
+ if (!ret) {
+ BT_LOGE("Cannot create stream beginning notification: "
+ "notit-addr=%p, stream-addr=%p",
+ notit, notit->stream);
+ return;
+ }
+
+end:
+ *notification = ret;
+}
+
+static
+void notify_end_of_stream(struct bt_notif_iter *notit,
+ struct bt_notification **notification)
+{
+ struct bt_notification *ret;
+
+ if (!notit->stream) {
+ BT_LOGE("Cannot create stream for stream notification: "
+ "notit-addr=%p", notit);
+ return;
+ }
+
+ ret = bt_notification_stream_end_create(notit->stream);
+ if (!ret) {
+ BT_LOGE("Cannot create stream beginning notification: "
+ "notit-addr=%p, stream-addr=%p",
+ notit, notit->stream);
+ return;
+ }
+ *notification = ret;
+}
+
static
void notify_new_packet(struct bt_notif_iter *notit,
struct bt_notification **notification)
int i, count;
struct bt_field_type *packet_header = NULL;
- packet_header = bt_trace_get_packet_header_type(trace);
+ packet_header = bt_trace_get_packet_header_field_type(trace);
if (!packet_header) {
goto end;
}
BT_ASSERT(notit);
BT_ASSERT(notification);
+ if (notit->state == STATE_DONE) {
+ status = BT_NOTIF_ITER_STATUS_EOF;
+ goto end;
+ }
+
BT_LOGV("Getting next notification: notit-addr=%p, cc-prio-map-addr=%p",
notit, cc_prio_map);
}
if (status != BT_NOTIF_ITER_STATUS_OK) {
if (status == BT_NOTIF_ITER_STATUS_EOF) {
+ enum state next_state = notit->state;
+
BT_LOGV_STR("Medium returned BT_NOTIF_ITER_STATUS_EOF.");
+
+ if (notit->packet) {
+ notify_end_of_packet(notit, notification);
+ } else {
+ notify_end_of_stream(notit, notification);
+ next_state = STATE_DONE;
+ }
+
+ if (!*notification) {
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ goto end;
+ }
+
+ status = BT_NOTIF_ITER_STATUS_OK;
+ notit->state = next_state;
+ goto end;
} else {
BT_LOGW("Cannot handle state: "
"notit-addr=%p, state=%s",
}
switch (notit->state) {
+ case STATE_EMIT_NOTIF_NEW_STREAM:
+ /* notify_new_stream() logs errors */
+ notify_new_stream(notit, notification);
+ if (!*notification) {
+ status = BT_NOTIF_ITER_STATUS_ERROR;
+ }
+ notit->stream_begin_emitted = true;
+ goto end;
case STATE_EMIT_NOTIF_NEW_PACKET:
/* notify_new_packet() logs errors */
notify_new_packet(notit, notification);
*/
goto set_fields;
case STATE_INIT:
+ case STATE_EMIT_NOTIF_NEW_STREAM:
case STATE_DSCOPE_TRACE_PACKET_HEADER_BEGIN:
case STATE_DSCOPE_TRACE_PACKET_HEADER_CONTINUE:
case STATE_AFTER_TRACE_PACKET_HEADER: