diff --git a/lib/wp/proxy-link.c b/lib/wp/proxy-link.c index a0f6733f..c7b5adee 100644 --- a/lib/wp/proxy-link.c +++ b/lib/wp/proxy-link.c @@ -6,6 +6,7 @@ * SPDX-License-Identifier: MIT */ +#include "error.h" #include "proxy-link.h" #include @@ -15,7 +16,7 @@ struct _WpProxyLink /* The task to signal the proxy is initialized */ GTask *init_task; - + /* The link proxy listener */ struct spa_hook listener; @@ -69,6 +70,22 @@ wp_proxy_link_finalize (GObject * object) G_OBJECT_CLASS (wp_proxy_link_parent_class)->finalize (object); } +static void +wp_proxy_link_destroy (WpProxy * proxy) +{ + WpProxyLink *self = WP_PROXY_LINK(proxy); + GError *error = NULL; + + /* Return error if the pipewire destruction happened while the async creation + * of this proxy link object has not finished */ + if (self->init_task) { + g_set_error (&error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED, + "pipewire link proxy destroyed before finishing"); + g_task_return_error (self->init_task, error); + g_clear_object (&self->init_task); + } +} + static void wp_proxy_link_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data) @@ -105,8 +122,11 @@ static void wp_proxy_link_class_init (WpProxyLinkClass * klass) { GObjectClass *object_class = (GObjectClass *) klass; + WpProxyClass *proxy_class = (WpProxyClass *) klass; object_class->finalize = wp_proxy_link_finalize; + + proxy_class->destroy = wp_proxy_link_destroy; } void diff --git a/lib/wp/proxy-node.c b/lib/wp/proxy-node.c index 89ca19e5..46569e31 100644 --- a/lib/wp/proxy-node.c +++ b/lib/wp/proxy-node.c @@ -6,6 +6,7 @@ * SPDX-License-Identifier: MIT */ +#include "error.h" #include "proxy-node.h" #include @@ -15,7 +16,7 @@ struct _WpProxyNode /* The task to signal the proxy is initialized */ GTask *init_task; - + /* The node proxy listener */ struct spa_hook listener; @@ -69,6 +70,22 @@ wp_proxy_node_finalize (GObject * object) G_OBJECT_CLASS (wp_proxy_node_parent_class)->finalize (object); } +static void +wp_proxy_node_destroy (WpProxy * proxy) +{ + WpProxyNode *self = WP_PROXY_NODE(proxy); + GError *error = NULL; + + /* Return error if the pipewire destruction happened while the async creation + * of this proxy node object has not finished */ + if (self->init_task) { + g_set_error (&error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED, + "pipewire node proxy destroyed before finishing"); + g_task_return_error (self->init_task, error); + g_clear_object (&self->init_task); + } +} + static void wp_proxy_node_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data) @@ -105,8 +122,11 @@ static void wp_proxy_node_class_init (WpProxyNodeClass * klass) { GObjectClass *object_class = (GObjectClass *) klass; + WpProxyClass *proxy_class = (WpProxyClass *) klass; object_class->finalize = wp_proxy_node_finalize; + + proxy_class->destroy = wp_proxy_node_destroy; } void diff --git a/lib/wp/proxy-port.c b/lib/wp/proxy-port.c index 4255381b..c796e5a2 100644 --- a/lib/wp/proxy-port.c +++ b/lib/wp/proxy-port.c @@ -6,6 +6,7 @@ * SPDX-License-Identifier: MIT */ +#include "error.h" #include "proxy-port.h" #include #include @@ -99,6 +100,22 @@ wp_proxy_port_finalize (GObject * object) G_OBJECT_CLASS (wp_proxy_port_parent_class)->finalize (object); } +static void +wp_proxy_port_destroy (WpProxy * proxy) +{ + WpProxyPort *self = WP_PROXY_PORT(proxy); + GError *error = NULL; + + /* Return error if the pipewire destruction happened while the async creation + * of this proxy port object has not finished */ + if (self->init_task) { + g_set_error (&error, WP_DOMAIN_LIBRARY, WP_LIBRARY_ERROR_OPERATION_FAILED, + "pipewire port proxy destroyed before finishing"); + g_task_return_error (self->init_task, error); + g_clear_object (&self->init_task); + } +} + static void wp_proxy_port_init_async (GAsyncInitable *initable, int io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data) @@ -139,8 +156,11 @@ static void wp_proxy_port_class_init (WpProxyPortClass * klass) { GObjectClass *object_class = (GObjectClass *) klass; + WpProxyClass *proxy_class = (WpProxyClass *) klass; object_class->finalize = wp_proxy_port_finalize; + + proxy_class->destroy = wp_proxy_port_destroy; } void diff --git a/lib/wp/proxy.c b/lib/wp/proxy.c index 360b50df..b14608b4 100644 --- a/lib/wp/proxy.c +++ b/lib/wp/proxy.c @@ -50,6 +50,10 @@ proxy_event_destroy (void *data) /* Set the proxy to NULL */ self->proxy = NULL; + + /* Call the destroy method */ + if (WP_PROXY_GET_CLASS (data)->destroy) + WP_PROXY_GET_CLASS (data)->destroy (data); } static void diff --git a/lib/wp/proxy.h b/lib/wp/proxy.h index 5dab6a80..52889874 100644 --- a/lib/wp/proxy.h +++ b/lib/wp/proxy.h @@ -23,6 +23,9 @@ struct _WpProxyClass { GObjectClass parent_class; + /* Methods */ + void (*destroy) (WpProxy * self); + /* Signals */ void (*done)(WpProxy *wp_proxy, gpointer data); };