proxy: throw an error if the proxy is destroyed during async constructions

This commit is contained in:
Julian Bouzas
2019-07-11 12:06:04 -04:00
committed by George Kiagiadakis
parent 3fc9582b6a
commit dbd763bc9c
5 changed files with 69 additions and 2 deletions

View File

@@ -6,6 +6,7 @@
* SPDX-License-Identifier: MIT
*/
#include "error.h"
#include "proxy-node.h"
#include <pipewire/pipewire.h>
@@ -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