+ BT_ASSERT(comp);
+ BT_ASSERT(port);
+
+ switch (comp->class->type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ {
+ struct bt_component_class_source *src_cc = (void *) comp->class;
+
+ switch (port->type) {
+ case BT_PORT_TYPE_OUTPUT:
+ method = (method_t) src_cc->methods.output_port_disconnected;
+ break;
+ default:
+ abort();
+ }
+
+ break;
+ }
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ {
+ struct bt_component_class_filter *flt_cc = (void *) comp->class;
+
+ switch (port->type) {
+ case BT_PORT_TYPE_INPUT:
+ method = (method_t) flt_cc->methods.input_port_disconnected;
+ break;
+ case BT_PORT_TYPE_OUTPUT:
+ method = (method_t) flt_cc->methods.output_port_disconnected;
+ break;
+ default:
+ abort();
+ }
+
+ break;
+ }
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ {
+ struct bt_component_class_sink *sink_cc = (void *) comp->class;
+
+ switch (port->type) {
+ case BT_PORT_TYPE_INPUT:
+ method = (method_t) sink_cc->methods.input_port_disconnected;
+ break;
+ default:
+ abort();
+ }
+
+ break;
+ }
+ default:
+ abort();
+ }
+
+ if (method) {
+ BT_LIB_LOGD("Calling user's \"port disconnected\" method: "
+ "%![comp-]+c, %![port-]+p", comp, port);
+ method(comp, port);
+ }
+}
+
+BT_HIDDEN
+void bt_component_add_destroy_listener(struct bt_component *component,
+ bt_component_destroy_listener_func func, void *data)
+{
+ struct bt_component_destroy_listener listener;
+
+ BT_ASSERT(component);
+ BT_ASSERT(func);
+ listener.func = func;
+ listener.data = data;
+ g_array_append_val(component->destroy_listeners, listener);
+ BT_LIB_LOGV("Added destroy listener: %![comp-]+c, "
+ "func-addr=%p, data-addr=%p",
+ component, func, data);
+}
+
+BT_HIDDEN
+void bt_component_remove_destroy_listener(struct bt_component *component,
+ bt_component_destroy_listener_func func, void *data)
+{
+ uint64_t i;
+
+ BT_ASSERT(component);
+ BT_ASSERT(func);
+
+ for (i = 0; i < component->destroy_listeners->len; i++) {
+ struct bt_component_destroy_listener *listener =
+ &g_array_index(component->destroy_listeners,
+ struct bt_component_destroy_listener, i);
+
+ if (listener->func == func && listener->data == data) {
+ g_array_remove_index(component->destroy_listeners, i);
+ i--;
+ BT_LIB_LOGV("Removed destroy listener: %![comp-]+c, "
+ "func-addr=%p, data-addr=%p",
+ component, func, data);
+ }