- assert(stream);
- stream_end_notif = bt_notification_stream_end_create(stream);
- if (!stream_end_notif) {
- BT_LOGE_STR("Cannot create stream end notification.");
- goto error;
- }
-
- add_action_push_notif(iterator, stream_end_notif);
- BT_LOGV("Added \"push stream end notification\" action: "
- "stream-addr=%p, stream-name=\"%s\"",
- stream, bt_ctf_stream_get_name(stream));
- goto end;
-
-error:
- ret = -1;
-
-end:
- bt_put(stream_end_notif);
- return ret;
-}
-
-static
-int add_action_push_notif_packet_begin(
- struct bt_notification_iterator_private_connection *iterator,
- struct bt_ctf_packet *packet)
-{
- int ret = 0;
- struct bt_notification *packet_begin_notif = NULL;
-
- if (!is_subscribed_to_notification_type(iterator,
- BT_NOTIFICATION_TYPE_PACKET_BEGIN)) {
- BT_LOGV("Not adding \"push packet beginning notification\" action: "
- "notification iterator is not subscribed: addr=%p",
- iterator);
- goto end;
- }
-
- assert(packet);
- packet_begin_notif = bt_notification_packet_begin_create(packet);
- if (!packet_begin_notif) {
- BT_LOGE_STR("Cannot create packet beginning notification.");
- goto error;
- }
-
- add_action_push_notif(iterator, packet_begin_notif);
- BT_LOGV("Added \"push packet beginning notification\" action: "
- "packet-addr=%p", packet);
- goto end;
-
-error:
- ret = -1;
-
-end:
- bt_put(packet_begin_notif);
- return ret;
-}
-
-static
-int add_action_push_notif_packet_end(
- struct bt_notification_iterator_private_connection *iterator,
- struct bt_ctf_packet *packet)
-{
- int ret = 0;
- struct bt_notification *packet_end_notif = NULL;
-
- if (!is_subscribed_to_notification_type(iterator,
- BT_NOTIFICATION_TYPE_PACKET_END)) {
- BT_LOGV("Not adding \"push packet end notification\" action: "
- "notification iterator is not subscribed: addr=%p",
- iterator);
- goto end;
- }
-
- assert(packet);
- packet_end_notif = bt_notification_packet_end_create(packet);
- if (!packet_end_notif) {
- BT_LOGE_STR("Cannot create packet end notification.");
- goto error;
- }
-
- add_action_push_notif(iterator, packet_end_notif);
- BT_LOGV("Added \"push packet end notification\" action: "
- "packet-addr=%p", packet);
- goto end;
-
-error:
- ret = -1;
-
-end:
- bt_put(packet_end_notif);
- return ret;
-}
-
-static
-void add_action_set_stream_state_is_ended(
- struct bt_notification_iterator_private_connection *iterator,
- struct stream_state *stream_state)
-{
- struct action action = {
- .type = ACTION_TYPE_SET_STREAM_STATE_IS_ENDED,
- .payload.set_stream_state_is_ended = {
- .stream_state = stream_state,
- },
- };
-
- assert(stream_state);
- add_action(iterator, &action);
- BT_LOGV("Added \"set stream state's ended\" action: "
- "stream-state-addr=%p", stream_state);
-}
-
-static
-void add_action_set_stream_state_cur_packet(
- struct bt_notification_iterator_private_connection *iterator,
- struct stream_state *stream_state,
- struct bt_ctf_packet *packet)
-{
- struct action action = {
- .type = ACTION_TYPE_SET_STREAM_STATE_CUR_PACKET,
- .payload.set_stream_state_cur_packet = {
- .stream_state = stream_state,
- .packet = bt_get(packet),
- },
- };
-
- assert(stream_state);
- add_action(iterator, &action);
- BT_LOGV("Added \"set stream state's current packet\" action: "
- "stream-state-addr=%p, packet-addr=%p",
- stream_state, packet);
-}
-
-static
-void add_action_update_stream_state_discarded_elements(
- struct bt_notification_iterator_private_connection *iterator,
- enum action_type type,
- struct stream_state *stream_state,
- struct bt_ctf_clock_value *cur_begin,
- uint64_t cur_count)
-{
- struct action action = {
- .type = type,
- .payload.update_stream_state_discarded_elements = {
- .stream_state = stream_state,
- .cur_begin = bt_get(cur_begin),
- .cur_count = cur_count,
- },
- };
-
- assert(stream_state);
- assert(type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_PACKETS ||
- type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_EVENTS);
- add_action(iterator, &action);
- if (type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_PACKETS) {
- BT_LOGV("Added \"update stream state's discarded packets\" action: "
- "stream-state-addr=%p, cur-begin-addr=%p, cur-count=%" PRIu64,
- stream_state, cur_begin, cur_count);
- } else if (type == ACTION_TYPE_UPDATE_STREAM_STATE_DISCARDED_EVENTS) {
- BT_LOGV("Added \"update stream state's discarded events\" action: "
- "stream-state-addr=%p, cur-begin-addr=%p, cur-count=%" PRIu64,
- stream_state, cur_begin, cur_count);
- }
-}
-
-static
-int ensure_stream_state_exists(
- struct bt_notification_iterator_private_connection *iterator,
- struct bt_notification *stream_begin_notif,
- struct bt_ctf_stream *notif_stream,
- struct stream_state **_stream_state)
-{
- int ret = 0;
- struct stream_state *stream_state = NULL;
-
- if (!notif_stream) {
- /*
- * The notification does not reference any stream: no
- * need to get or create a stream state.
- */
- goto end;
- }
-
- stream_state = g_hash_table_lookup(iterator->stream_states,
- notif_stream);
- if (!stream_state) {
- /*
- * This iterator did not bump into this stream yet:
- * create a stream state and a "stream begin"
- * notification.
- */
- struct action action = {
- .type = ACTION_TYPE_ADD_STREAM_STATE,
- .payload.add_stream_state = {
- .stream = bt_get(notif_stream),
- .stream_state = NULL,
- },
- };
-
- stream_state = create_stream_state(notif_stream);
- if (!stream_state) {
- BT_LOGE_STR("Cannot create stream state.");
- goto error;
- }
-
- action.payload.add_stream_state.stream_state = stream_state;
- add_action(iterator, &action);
-
- if (stream_begin_notif) {
- add_action_push_notif(iterator, stream_begin_notif);
- } else {
- ret = add_action_push_notif_stream_begin(iterator,
- notif_stream);
- if (ret) {
- BT_LOGE_STR("Cannot add \"push stream beginning notification\" action.");
- goto error;
- }
- }
- }
- goto end;
-
-error:
- destroy_stream_state(stream_state);
- stream_state = NULL;
- ret = -1;
-
-end:
- *_stream_state = stream_state;
- return ret;