- enum bt_component_class_type upstream_comp_class_type;
- struct bt_notification_iterator_private_connection *iterator = NULL;
- struct bt_port *upstream_port = NULL;
- struct bt_component *upstream_component = NULL;
- struct bt_component_class *upstream_comp_class = NULL;
- struct bt_connection *connection = NULL;
- bt_component_class_notification_iterator_init_method init_method = NULL;
- enum bt_connection_status status;
-
- if (!private_connection) {
- BT_LOGW_STR("Invalid parameter: private connection is NULL.");
- status = BT_CONNECTION_STATUS_INVALID;
- goto end;
- }
-
- if (!user_iterator) {
- BT_LOGW_STR("Invalid parameter: notification iterator pointer is NULL.");
- status = BT_CONNECTION_STATUS_INVALID;
- goto end;
- }
-
- connection = bt_connection_borrow_from_private(private_connection);
-
- if (bt_graph_is_canceled(bt_connection_borrow_graph(connection))) {
- BT_LOGW("Cannot create notification iterator from connection: "
- "connection's graph is canceled: "
- "conn-addr=%p, upstream-port-addr=%p, "
- "upstream-port-name=\"%s\", upstream-comp-addr=%p, "
- "upstream-comp-name=\"%s\", graph-addr=%p",
- connection, connection->upstream_port,
- bt_port_get_name(connection->upstream_port),
- upstream_component,
- bt_component_get_name(upstream_component),
- bt_connection_borrow_graph(connection));
- status = BT_CONNECTION_STATUS_GRAPH_IS_CANCELED;
- goto end;
- }
-
- if (bt_connection_is_ended(connection)) {
- BT_LOGW("Invalid parameter: connection is ended: "
- "conn-addr=%p", connection);
- status = BT_CONNECTION_STATUS_IS_ENDED;
- goto end;
- }
-
- upstream_port = connection->upstream_port;
- BT_ASSERT(upstream_port);
- upstream_component = bt_port_get_component(upstream_port);
- BT_ASSERT(upstream_component);
- upstream_comp_class = upstream_component->class;
- BT_LOGD("Creating notification iterator from connection: "
- "conn-addr=%p, upstream-port-addr=%p, "
- "upstream-port-name=\"%s\", upstream-comp-addr=%p, "
- "upstream-comp-name=\"%s\"",
- connection, connection->upstream_port,
- bt_port_get_name(connection->upstream_port),
- upstream_component, bt_component_get_name(upstream_component));
- upstream_comp_class_type =
- bt_component_get_class_type(upstream_component);
- BT_ASSERT(upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
- upstream_comp_class_type == BT_COMPONENT_CLASS_TYPE_FILTER);
- status = bt_private_connection_notification_iterator_create(upstream_component,
- upstream_port, connection, &iterator);
- if (status != BT_CONNECTION_STATUS_OK) {
- BT_LOGW("Cannot create notification iterator from connection.");
- goto end;
- }
-
- switch (upstream_comp_class_type) {
- case BT_COMPONENT_CLASS_TYPE_SOURCE:
- {
- struct bt_component_class_source *source_class =
- container_of(upstream_comp_class,
- struct bt_component_class_source, parent);
- init_method = source_class->methods.iterator.init;
- break;
- }
- case BT_COMPONENT_CLASS_TYPE_FILTER:
- {
- struct bt_component_class_filter *filter_class =
- container_of(upstream_comp_class,
- struct bt_component_class_filter, parent);
- init_method = filter_class->methods.iterator.init;
- break;
- }
- default:
- /* Unreachable. */
- BT_LOGF("Unknown component class type: type=%d",
- upstream_comp_class_type);
- abort();
- }
-
- if (init_method) {
- enum bt_notification_iterator_status iter_status;
-
- BT_LOGD("Calling user's initialization method: iter-addr=%p",
- iterator);
- iter_status = init_method(
- bt_private_connection_private_notification_iterator_from_notification_iterator((void *) iterator),
- bt_private_port_from_port(upstream_port));
- BT_LOGD("User method returned: status=%s",
- bt_notification_iterator_status_string(iter_status));
- if (iter_status != BT_NOTIFICATION_ITERATOR_STATUS_OK) {
- BT_LOGW_STR("Initialization method failed.");
- status = bt_connection_status_from_notification_iterator_status(
- iter_status);
- goto end;
- }
- }
-
- iterator->state = BT_PRIVATE_CONNECTION_NOTIFICATION_ITERATOR_STATE_ACTIVE;
- g_ptr_array_add(connection->iterators, iterator);
- BT_LOGD("Created notification iterator from connection: "
- "conn-addr=%p, upstream-port-addr=%p, "
- "upstream-port-name=\"%s\", upstream-comp-addr=%p, "
- "upstream-comp-name=\"%s\", iter-addr=%p",
- connection, connection->upstream_port,
- bt_port_get_name(connection->upstream_port),
- upstream_component, bt_component_get_name(upstream_component),
- iterator);
-
- /* Move reference to user */
- *user_iterator = (void *) iterator;
- iterator = NULL;
-
-end:
- bt_object_put_ref(upstream_component);
- bt_object_put_ref(iterator);
- return status;