-struct stream_state {
- struct bt_ctf_stream *stream; /* owned by this */
- struct bt_ctf_packet *cur_packet; /* owned by this */
- bt_bool is_ended;
-};
-
-enum action_type {
- ACTION_TYPE_PUSH_NOTIF,
- ACTION_TYPE_MAP_PORT_TO_COMP_IN_STREAM,
- ACTION_TYPE_ADD_STREAM_STATE,
- ACTION_TYPE_SET_STREAM_STATE_IS_ENDED,
- ACTION_TYPE_SET_STREAM_STATE_CUR_PACKET,
-};
-
-struct action {
- enum action_type type;
- union {
- /* ACTION_TYPE_PUSH_NOTIF */
- struct {
- struct bt_notification *notif; /* owned by this */
- } push_notif;
-
- /* ACTION_TYPE_MAP_PORT_TO_COMP_IN_STREAM */
- struct {
- struct bt_ctf_stream *stream; /* owned by this */
- struct bt_component *component; /* owned by this */
- struct bt_port *port; /* owned by this */
- } map_port_to_comp_in_stream;
-
- /* ACTION_TYPE_ADD_STREAM_STATE */
- struct {
- struct bt_ctf_stream *stream; /* owned by this */
- struct stream_state *stream_state; /* owned by this */
- } add_stream_state;
-
- /* ACTION_TYPE_SET_STREAM_STATE_IS_ENDED */
- struct {
- struct stream_state *stream_state; /* weak */
- } set_stream_state_is_ended;
-
- /* ACTION_TYPE_SET_STREAM_STATE_CUR_PACKET */
- struct {
- struct stream_state *stream_state; /* weak */
- struct bt_ctf_packet *packet; /* owned by this */
- } set_stream_state_cur_packet;
- } payload;
-};
-
-static
-void stream_destroy_listener(struct bt_ctf_stream *stream, void *data)
-{
- struct bt_notification_iterator *iterator = data;
-
- /* Remove associated stream state */
- g_hash_table_remove(iterator->stream_states, stream);
-}
-
-static
-void destroy_stream_state(struct stream_state *stream_state)
-{
- if (!stream_state) {
- return;
- }
-
- BT_LOGV("Destroying stream state: stream-state-addr=%p", stream_state);
- BT_LOGV_STR("Putting stream state's current packet.");
- bt_put(stream_state->cur_packet);
- BT_LOGV_STR("Putting stream state's stream.");
- bt_put(stream_state->stream);
- g_free(stream_state);
-}
-
-static
-void destroy_action(struct action *action)
-{
- assert(action);
-
- switch (action->type) {
- case ACTION_TYPE_PUSH_NOTIF:
- BT_PUT(action->payload.push_notif.notif);
- break;
- case ACTION_TYPE_MAP_PORT_TO_COMP_IN_STREAM:
- BT_PUT(action->payload.map_port_to_comp_in_stream.stream);
- BT_PUT(action->payload.map_port_to_comp_in_stream.component);
- BT_PUT(action->payload.map_port_to_comp_in_stream.port);
- break;
- case ACTION_TYPE_ADD_STREAM_STATE:
- BT_PUT(action->payload.add_stream_state.stream);
- destroy_stream_state(
- action->payload.add_stream_state.stream_state);
- action->payload.add_stream_state.stream_state = NULL;
- break;
- case ACTION_TYPE_SET_STREAM_STATE_CUR_PACKET:
- BT_PUT(action->payload.set_stream_state_cur_packet.packet);
- break;
- case ACTION_TYPE_SET_STREAM_STATE_IS_ENDED:
- break;
- default:
- abort();
- }
-}
-
-static
-void add_action(struct bt_notification_iterator *iterator,
- struct action *action)
-{
- g_array_append_val(iterator->actions, *action);
-}
-
-static
-void clear_actions(struct bt_notification_iterator *iterator)
-{
- size_t i;
-
- for (i = 0; i < iterator->actions->len; i++) {
- struct action *action = &g_array_index(iterator->actions,
- struct action, i);
-
- destroy_action(action);
- }