endpoint: allow derived classes of endpoint-link to finish async construction
This commit is contained in:
@@ -737,9 +737,6 @@ wp_endpoint_get_links (WpEndpoint * self)
|
||||
typedef struct _WpEndpointLinkPrivate WpEndpointLinkPrivate;
|
||||
struct _WpEndpointLinkPrivate
|
||||
{
|
||||
/* The task to signal the endpoint link is initialized */
|
||||
GTask *init_task;
|
||||
|
||||
GWeakRef src;
|
||||
guint32 src_stream;
|
||||
GWeakRef sink;
|
||||
@@ -768,9 +765,6 @@ endpoint_link_finalize (GObject * object)
|
||||
WpEndpointLinkPrivate *priv =
|
||||
wp_endpoint_link_get_instance_private (WP_ENDPOINT_LINK (object));
|
||||
|
||||
/* Destroy the init task */
|
||||
g_clear_object(&priv->init_task);
|
||||
|
||||
/* Clear the endpoint weak reaferences */
|
||||
g_weak_ref_clear(&priv->src);
|
||||
g_weak_ref_clear(&priv->sink);
|
||||
@@ -837,34 +831,27 @@ wp_endpoint_link_init_async (GAsyncInitable *initable, int io_priority,
|
||||
wp_endpoint_link_get_instance_private (WP_ENDPOINT_LINK (initable));
|
||||
g_autoptr (WpEndpoint) src = g_weak_ref_get (&priv->src);
|
||||
g_autoptr (WpEndpoint) sink = g_weak_ref_get (&priv->sink);
|
||||
g_autoptr (GError) error = NULL;
|
||||
g_autoptr (GVariant) src_props = NULL;
|
||||
g_autoptr (GVariant) sink_props = NULL;
|
||||
WpEndpointPrivate *endpoint_priv;
|
||||
|
||||
/* Create the async task */
|
||||
priv->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Prepare the endpoints */
|
||||
if (!WP_ENDPOINT_GET_CLASS (src)->prepare_link (src, priv->src_stream, link,
|
||||
&src_props, &error)) {
|
||||
g_task_return_error (priv->init_task, error);
|
||||
g_clear_object(&priv->init_task);
|
||||
&src_props, NULL)) {
|
||||
g_critical ("Failed to prepare link on source endpoint");
|
||||
return;
|
||||
}
|
||||
if (!WP_ENDPOINT_GET_CLASS (sink)->prepare_link (sink, priv->sink_stream,
|
||||
link, &sink_props, &error)) {
|
||||
g_task_return_error (priv->init_task, error);
|
||||
g_clear_object(&priv->init_task);
|
||||
link, &sink_props, NULL)) {
|
||||
g_critical ("Failed to prepare link on sink endpoint");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create the link */
|
||||
g_return_if_fail (WP_ENDPOINT_LINK_GET_CLASS (link)->create);
|
||||
if (!WP_ENDPOINT_LINK_GET_CLASS (link)->create (link, src_props,
|
||||
sink_props, &error)) {
|
||||
g_task_return_error (priv->init_task, error);
|
||||
g_clear_object(&priv->init_task);
|
||||
sink_props, NULL)) {
|
||||
g_critical ("Failed to create link in src and sink endpoints");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -873,10 +860,6 @@ wp_endpoint_link_init_async (GAsyncInitable *initable, int io_priority,
|
||||
g_ptr_array_add (endpoint_priv->links, g_object_ref (link));
|
||||
endpoint_priv = wp_endpoint_get_instance_private (sink);
|
||||
g_ptr_array_add (endpoint_priv->links, g_object_ref (link));
|
||||
|
||||
/* Finish the creation of the endpoint */
|
||||
g_task_return_boolean (priv->init_task, TRUE);
|
||||
g_clear_object(&priv->init_task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -27,8 +27,11 @@ struct _WpPipewireSimpleEndpointLink
|
||||
{
|
||||
WpEndpointLink parent;
|
||||
|
||||
/* The wireplumber core */
|
||||
/* Props */
|
||||
GWeakRef core;
|
||||
|
||||
/* The task to signal the simple endpoint link is initialized */
|
||||
GTask *init_task;
|
||||
};
|
||||
|
||||
enum {
|
||||
@@ -36,11 +39,50 @@ enum {
|
||||
PROP_CORE,
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *wp_simple_endpoint_link_parent_interface = NULL;
|
||||
static void wp_simple_endpoint_link_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
G_DECLARE_FINAL_TYPE (WpPipewireSimpleEndpointLink,
|
||||
simple_endpoint_link, WP_PIPEWIRE, SIMPLE_ENDPOINT_LINK, WpEndpointLink)
|
||||
|
||||
G_DEFINE_TYPE (WpPipewireSimpleEndpointLink,
|
||||
simple_endpoint_link, WP_TYPE_ENDPOINT_LINK)
|
||||
G_DEFINE_TYPE_WITH_CODE (WpPipewireSimpleEndpointLink, simple_endpoint_link,
|
||||
WP_TYPE_ENDPOINT_LINK,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
||||
wp_simple_endpoint_link_async_initable_init))
|
||||
|
||||
static void
|
||||
wp_simple_endpoint_link_init_async (GAsyncInitable *initable, int io_priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||
{
|
||||
WpPipewireSimpleEndpointLink *self =
|
||||
WP_PIPEWIRE_SIMPLE_ENDPOINT_LINK (initable);
|
||||
|
||||
/* Create the async task */
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Call the parent interface */
|
||||
wp_simple_endpoint_link_parent_interface->init_async (initable,
|
||||
io_priority, cancellable, callback, data);
|
||||
|
||||
/* Finish the creation of the endpoint */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object(&self->init_task);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_simple_endpoint_link_async_initable_init (gpointer iface,
|
||||
gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
|
||||
/* Set the parent interface */
|
||||
wp_simple_endpoint_link_parent_interface =
|
||||
g_type_interface_peek_parent (iface);
|
||||
|
||||
/* Only set the init_async */
|
||||
ai_iface->init_async = wp_simple_endpoint_link_init_async;
|
||||
}
|
||||
|
||||
static void
|
||||
simple_endpoint_link_init (WpPipewireSimpleEndpointLink * self)
|
||||
@@ -54,6 +96,9 @@ simple_endpoint_link_finalize (GObject * object)
|
||||
{
|
||||
WpPipewireSimpleEndpointLink *self = WP_PIPEWIRE_SIMPLE_ENDPOINT_LINK(object);
|
||||
|
||||
/* Destroy the init task */
|
||||
g_clear_object(&self->init_task);
|
||||
|
||||
/* Clear the core weak reference */
|
||||
g_weak_ref_clear (&self->core);
|
||||
}
|
||||
|
Reference in New Issue
Block a user