#include "message/stream.h"
#include "message/packet.h"
#include "lib/func-status.h"
+#include "clock-correlation-validator/clock-correlation-validator.h"
/*
* TODO: Use graph's state (number of active iterators, etc.) and
(_iter)->state == BT_MESSAGE_ITERATOR_STATE_LAST_SEEKING_RETURNED_ERROR, \
"Message iterator is in the wrong state: %!+i", (_iter))
-#ifdef BT_DEV_MODE
+BT_IF_DEV_MODE(
struct per_stream_state
{
bt_packet *cur_packet;
/* Bit mask of expected message types. */
guint expected_msg_types;
};
-#endif
+)
static void
clear_per_stream_state (struct bt_message_iterator *iterator)
"%!+i", iterator);
bt_message_iterator_try_finalize(iterator);
- if (iterator->clock_expectation.type ==
- CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID) {
- BT_CLOCK_CLASS_PUT_REF_AND_RESET(
- iterator->clock_expectation.clock_class);
- }
-
if (iterator->connection) {
/*
* Remove ourself from the originating connection so
iterator->msgs = NULL;
}
-#ifdef BT_DEV_MODE
- g_hash_table_destroy(iterator->per_stream_state);
-#endif
+ BT_IF_DEV_MODE(bt_clock_correlation_validator_destroy(
+ iterator->correlation_validator));
+ BT_IF_DEV_MODE(g_hash_table_destroy(iterator->per_stream_state));
g_free(iterator);
}
goto error;
}
+ BT_IF_DEV_MODE(
+ iterator->correlation_validator =
+ bt_clock_correlation_validator_create();
+ if (!iterator->correlation_validator) {
+ BT_LIB_LOGE_APPEND_CAUSE(
+ "Failed to allocate a clock correlation validator.");
+ status = BT_FUNC_STATUS_MEMORY_ERROR;
+ goto error;
+ }
+ );
+
g_ptr_array_set_size(iterator->msgs, MSG_BATCH_SIZE);
iterator->last_ns_from_origin = INT64_MIN;
-#ifdef BT_DEV_MODE
/* The per-stream state is only used for dev assertions right now. */
- iterator->per_stream_state = g_hash_table_new_full(
+ BT_IF_DEV_MODE(iterator->per_stream_state = g_hash_table_new_full(
g_direct_hash,
g_direct_equal,
NULL,
- g_free);
-#endif
+ g_free));
iterator->auto_seek.msgs = g_queue_new();
if (!iterator->auto_seek.msgs) {
struct bt_message_iterator *iterator,
const struct bt_message *msg)
{
- enum bt_message_type message_type = bt_message_get_type(msg);
-
- if (message_type == BT_MESSAGE_TYPE_STREAM_BEGINNING) {
- const struct bt_message_stream *stream_msg = (struct bt_message_stream *) msg;
- const struct bt_clock_class *clock_class = stream_msg->stream->class->default_clock_class;
- bt_uuid clock_class_uuid = NULL;
-
- if (clock_class) {
- clock_class_uuid = bt_clock_class_get_uuid(clock_class);
- }
-
- switch (iterator->clock_expectation.type) {
- case CLOCK_EXPECTATION_UNSET:
- /*
- * This is the first time we see a message with a clock
- * snapshot: record the properties of that clock, against
- * which we'll compare the clock properties of the following
- * messages.
- */
-
- if (!clock_class) {
- iterator->clock_expectation.type = CLOCK_EXPECTATION_NONE;
- } else if (bt_clock_class_origin_is_unix_epoch(clock_class)) {
- iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX;
- } else if (clock_class_uuid) {
- iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID;
- bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid);
- } else {
- iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID;
- iterator->clock_expectation.clock_class = clock_class;
- bt_clock_class_get_ref(iterator->clock_expectation.clock_class);
- }
- break;
-
- case CLOCK_EXPECTATION_NONE:
+ enum bt_clock_correlation_validator_error_type type;
+ bt_uuid expected_uuid;
+ const bt_clock_class *actual_clock_cls;
+ const bt_clock_class *expected_clock_cls;
+
+ if (!bt_clock_correlation_validator_validate_message(
+ iterator->correlation_validator, msg, &type,
+ &expected_uuid, &actual_clock_cls,
+ &expected_clock_cls)) {
+ switch (type) {
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_NO_CLOCK_CLASS_GOT_ONE:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "stream-class-has-no-clock-class", !clock_class,
- "Expecting no clock class, got one: %![cc-]+K",
- clock_class);
- break;
-
- case CLOCK_EXPECTATION_ORIGIN_UNIX:
+ "stream-class-has-no-clock-class", false,
+ "Expecting no clock class, got one.");
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UNIX_GOT_NONE:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "stream-class-has-clock-class-with-unix-epoch-origin", clock_class,
- "Expecting a clock class with Unix epoch origin, got none.");
-
+ "stream-class-has-clock-class-with-unix-epoch-origin", false,
+ "Expecting a clock class, got none.");
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UNIX_GOT_OTHER:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "clock-class-has-unix-epoch-origin",
- bt_clock_class_origin_is_unix_epoch(clock_class),
+ "clock-class-has-unix-epoch-origin", false,
"Expecting a clock class with Unix epoch origin: %![cc-]+K",
- clock_class);
- break;
-
- case CLOCK_EXPECTATION_ORIGIN_OTHER_UUID:
+ actual_clock_cls);
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UUID_GOT_NONE:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "stream-class-has-clock-class-with-uuid", clock_class,
- "Expecting a clock class with UUID, got none.");
-
+ "stream-class-has-clock-class-with-uuid", false,
+ "Expecting a clock class, got none.");
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UUID_GOT_UNIX:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "clock-class-has-non-unix-epoch-origin",
- !bt_clock_class_origin_is_unix_epoch(clock_class),
+ "clock-class-has-non-unix-epoch-origin", false,
"Expecting a clock class without Unix epoch origin: %![cc-]+K",
- clock_class);
-
+ actual_clock_cls);
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UUID_GOT_NO_UUID:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "clock-class-has-uuid",
- clock_class_uuid,
- "Expecting a clock class with UUID, got one without UUID: %![cc-]+K",
- clock_class);
-
+ "clock-class-has-uuid", false,
+ "Expecting a clock class with UUID: %![cc-]+K",
+ actual_clock_cls);
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_UUID_GOT_OTHER_UUID:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "clock-class-has-expected-uuid",
- !bt_uuid_compare(iterator->clock_expectation.uuid, clock_class_uuid),
- "Expecting a clock class with UUID, got one "
- "with a different UUID: %![cc-]+K, expected-uuid=%!u",
- clock_class, iterator->clock_expectation.uuid);
- break;
+ "clock-class-has-expected-uuid", false,
+ "Expecting a clock class with UUID, got one with a different UUID: %![cc-]+K, expected-uuid=%!u",
+ actual_clock_cls, expected_uuid);
- case CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID:
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_NO_UUID_GOT_NONE:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "stream-class-has-clock-class", clock_class,
+ "stream-class-has-clock-class", false,
"Expecting a clock class, got none.");
-
+ case BT_CLOCK_CORRELATION_VALIDATOR_ERROR_TYPE_EXPECTING_ORIGIN_NO_UUID_GOT_OTHER:
BT_ASSERT_POST_DEV(NEXT_METHOD_NAME,
- "clock-class-is-expected",
- clock_class == iterator->clock_expectation.clock_class,
- "Expecting clock class %![cc-]+K, got %![cc-]+K.",
- iterator->clock_expectation.clock_class,
- clock_class);
- break;
+ "clock-class-is-expected", false,
+ "Unexpected clock class: %![expected-cc-]+K, %![actual-cc-]+K",
+ expected_clock_cls, actual_clock_cls);
}
+
+ bt_common_abort();
}
}
struct bt_stream *stream;
switch (msg->type) {
- case BT_MESSAGE_TYPE_STREAM_BEGINNING:
- case BT_MESSAGE_TYPE_STREAM_END:
+ case BT_MESSAGE_TYPE_STREAM_BEGINNING:
+ case BT_MESSAGE_TYPE_STREAM_END:
{
struct bt_message_stream *msg_stream =
(struct bt_message_stream *) msg;
stream = msg_stream->stream;
break;
}
- case BT_MESSAGE_TYPE_EVENT:
+ case BT_MESSAGE_TYPE_EVENT:
{
struct bt_message_event *msg_event =
(struct bt_message_event *) msg;
stream = msg_event->event->stream;
break;
}
- case BT_MESSAGE_TYPE_PACKET_BEGINNING:
- case BT_MESSAGE_TYPE_PACKET_END:
+ case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+ case BT_MESSAGE_TYPE_PACKET_END:
{
struct bt_message_packet *msg_packet =
(struct bt_message_packet *) msg;
stream = msg_packet->packet->stream;
break;
}
- case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
- case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
+ case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+ case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
{
struct bt_message_discarded_items *msg_discarded =
(struct bt_message_discarded_items *) msg;
stream = msg_discarded->stream;
break;
}
- case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
+ case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
stream = NULL;
break;
default:
bt_common_abort();
- }
+ }
return stream;
}
const struct bt_message *msg)
{
switch (msg->type) {
- case BT_MESSAGE_TYPE_STREAM_BEGINNING:
+ case BT_MESSAGE_TYPE_STREAM_BEGINNING:
state->expected_msg_types = BT_MESSAGE_TYPE_STREAM_END;
if (stream->class->supports_packets) {
}
break;
- case BT_MESSAGE_TYPE_STREAM_END:
+ case BT_MESSAGE_TYPE_STREAM_END:
state->expected_msg_types = 0;
break;
- case BT_MESSAGE_TYPE_EVENT:
+ case BT_MESSAGE_TYPE_EVENT:
{
state->expected_msg_types = BT_MESSAGE_TYPE_EVENT;
break;
}
- case BT_MESSAGE_TYPE_PACKET_BEGINNING:
+ case BT_MESSAGE_TYPE_PACKET_BEGINNING:
{
state->expected_msg_types = BT_MESSAGE_TYPE_EVENT |
BT_MESSAGE_TYPE_PACKET_END;
break;
}
- case BT_MESSAGE_TYPE_PACKET_END:
+ case BT_MESSAGE_TYPE_PACKET_END:
{
state->expected_msg_types = BT_MESSAGE_TYPE_PACKET_BEGINNING |
BT_MESSAGE_TYPE_STREAM_END;
break;
}
- case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
+ case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
state->expected_msg_types = BT_MESSAGE_TYPE_DISCARDED_EVENTS;
if (state->cur_packet) {
}
break;
- case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
+ case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
state->expected_msg_types = BT_MESSAGE_TYPE_DISCARDED_PACKETS |
BT_MESSAGE_TYPE_PACKET_BEGINNING |
BT_MESSAGE_TYPE_STREAM_END;
* Other message types are not associated to a stream, so we
* should not get them here.
*/
- bt_common_abort();
- }
+ bt_common_abort();
+ }
}
static
"Clock snapshots are not monotonic");
}
-#ifdef BT_DEV_MODE
- assert_post_dev_next(iterator, status, msgs, *user_count);
-#endif
+ BT_IF_DEV_MODE(assert_post_dev_next(iterator, status, msgs,
+ *user_count));
BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(NEXT_METHOD_NAME,
status);
struct bt_message_iterator *iterator)
{
iterator->last_ns_from_origin = INT64_MIN;
- iterator->clock_expectation.type = CLOCK_EXPECTATION_UNSET;
}
static