proxy: throw an error if the proxy is destroyed during async constructions
This commit is contained in:

committed by
George Kiagiadakis

parent
3fc9582b6a
commit
dbd763bc9c
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "proxy-link.h"
|
#include "proxy-link.h"
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ struct _WpProxyLink
|
|||||||
|
|
||||||
/* The task to signal the proxy is initialized */
|
/* The task to signal the proxy is initialized */
|
||||||
GTask *init_task;
|
GTask *init_task;
|
||||||
|
|
||||||
/* The link proxy listener */
|
/* The link proxy listener */
|
||||||
struct spa_hook 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);
|
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
|
static void
|
||||||
wp_proxy_link_init_async (GAsyncInitable *initable, int io_priority,
|
wp_proxy_link_init_async (GAsyncInitable *initable, int io_priority,
|
||||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||||
@@ -105,8 +122,11 @@ static void
|
|||||||
wp_proxy_link_class_init (WpProxyLinkClass * klass)
|
wp_proxy_link_class_init (WpProxyLinkClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = (GObjectClass *) klass;
|
GObjectClass *object_class = (GObjectClass *) klass;
|
||||||
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||||
|
|
||||||
object_class->finalize = wp_proxy_link_finalize;
|
object_class->finalize = wp_proxy_link_finalize;
|
||||||
|
|
||||||
|
proxy_class->destroy = wp_proxy_link_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "proxy-node.h"
|
#include "proxy-node.h"
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ struct _WpProxyNode
|
|||||||
|
|
||||||
/* The task to signal the proxy is initialized */
|
/* The task to signal the proxy is initialized */
|
||||||
GTask *init_task;
|
GTask *init_task;
|
||||||
|
|
||||||
/* The node proxy listener */
|
/* The node proxy listener */
|
||||||
struct spa_hook 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);
|
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
|
static void
|
||||||
wp_proxy_node_init_async (GAsyncInitable *initable, int io_priority,
|
wp_proxy_node_init_async (GAsyncInitable *initable, int io_priority,
|
||||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||||
@@ -105,8 +122,11 @@ static void
|
|||||||
wp_proxy_node_class_init (WpProxyNodeClass * klass)
|
wp_proxy_node_class_init (WpProxyNodeClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = (GObjectClass *) klass;
|
GObjectClass *object_class = (GObjectClass *) klass;
|
||||||
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||||
|
|
||||||
object_class->finalize = wp_proxy_node_finalize;
|
object_class->finalize = wp_proxy_node_finalize;
|
||||||
|
|
||||||
|
proxy_class->destroy = wp_proxy_node_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "error.h"
|
||||||
#include "proxy-port.h"
|
#include "proxy-port.h"
|
||||||
#include <pipewire/pipewire.h>
|
#include <pipewire/pipewire.h>
|
||||||
#include <spa/param/audio/format-utils.h>
|
#include <spa/param/audio/format-utils.h>
|
||||||
@@ -99,6 +100,22 @@ wp_proxy_port_finalize (GObject * object)
|
|||||||
G_OBJECT_CLASS (wp_proxy_port_parent_class)->finalize (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
|
static void
|
||||||
wp_proxy_port_init_async (GAsyncInitable *initable, int io_priority,
|
wp_proxy_port_init_async (GAsyncInitable *initable, int io_priority,
|
||||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||||
@@ -139,8 +156,11 @@ static void
|
|||||||
wp_proxy_port_class_init (WpProxyPortClass * klass)
|
wp_proxy_port_class_init (WpProxyPortClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = (GObjectClass *) klass;
|
GObjectClass *object_class = (GObjectClass *) klass;
|
||||||
|
WpProxyClass *proxy_class = (WpProxyClass *) klass;
|
||||||
|
|
||||||
object_class->finalize = wp_proxy_port_finalize;
|
object_class->finalize = wp_proxy_port_finalize;
|
||||||
|
|
||||||
|
proxy_class->destroy = wp_proxy_port_destroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@@ -50,6 +50,10 @@ proxy_event_destroy (void *data)
|
|||||||
|
|
||||||
/* Set the proxy to NULL */
|
/* Set the proxy to NULL */
|
||||||
self->proxy = NULL;
|
self->proxy = NULL;
|
||||||
|
|
||||||
|
/* Call the destroy method */
|
||||||
|
if (WP_PROXY_GET_CLASS (data)->destroy)
|
||||||
|
WP_PROXY_GET_CLASS (data)->destroy (data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@@ -23,6 +23,9 @@ struct _WpProxyClass
|
|||||||
{
|
{
|
||||||
GObjectClass parent_class;
|
GObjectClass parent_class;
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
|
void (*destroy) (WpProxy * self);
|
||||||
|
|
||||||
/* Signals */
|
/* Signals */
|
||||||
void (*done)(WpProxy *wp_proxy, gpointer data);
|
void (*done)(WpProxy *wp_proxy, gpointer data);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user