mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-02 14:28:11 +02:00
proxy: allow derived classes to finish its creation
This commit is contained in:
parent
51facef4e4
commit
682bc6a6eb
4 changed files with 63 additions and 58 deletions
|
|
@ -12,6 +12,9 @@
|
|||
struct _WpProxyLink
|
||||
{
|
||||
WpProxy parent;
|
||||
|
||||
/* The task to signal the proxy is initialized */
|
||||
GTask *init_task;
|
||||
|
||||
/* The link proxy listener */
|
||||
struct spa_hook listener;
|
||||
|
|
@ -20,7 +23,6 @@ struct _WpProxyLink
|
|||
struct pw_link_info *info;
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *proxy_link_parent_interface = NULL;
|
||||
static void wp_proxy_link_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
|
|
@ -33,8 +35,16 @@ link_event_info(void *data, const struct pw_link_info *info)
|
|||
{
|
||||
WpProxyLink *self = data;
|
||||
|
||||
/* Make sure the task is valid */
|
||||
if (!self->init_task)
|
||||
return;
|
||||
|
||||
/* Update the link info */
|
||||
self->info = pw_link_info_update(self->info, info);
|
||||
|
||||
/* Finish the creation of the proxy */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object (&self->init_task);
|
||||
}
|
||||
|
||||
static const struct pw_link_proxy_events link_events = {
|
||||
|
|
@ -47,6 +57,9 @@ wp_proxy_link_finalize (GObject * object)
|
|||
{
|
||||
WpProxyLink *self = WP_PROXY_LINK(object);
|
||||
|
||||
/* Destroy the init task */
|
||||
g_clear_object (&self->init_task);
|
||||
|
||||
/* Clear the info */
|
||||
if (self->info) {
|
||||
pw_link_info_free(self->info);
|
||||
|
|
@ -64,24 +77,20 @@ wp_proxy_link_init_async (GAsyncInitable *initable, int io_priority,
|
|||
WpProxy *wp_proxy = WP_PROXY(initable);
|
||||
struct pw_link_proxy *proxy = NULL;
|
||||
|
||||
/* Create the async task */
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Get the proxy from the base class */
|
||||
proxy = wp_proxy_get_pw_proxy(wp_proxy);
|
||||
|
||||
/* Add the link proxy listener */
|
||||
pw_link_proxy_add_listener(proxy, &self->listener, &link_events, self);
|
||||
|
||||
/* Call the parent interface */
|
||||
proxy_link_parent_interface->init_async (initable, io_priority, cancellable,
|
||||
callback, data);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_proxy_link_async_initable_init (gpointer iface, gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
|
||||
/* Set the parent interface */
|
||||
proxy_link_parent_interface = g_type_interface_peek_parent (iface);
|
||||
|
||||
/* Only set the init_async */
|
||||
ai_iface->init_async = wp_proxy_link_init_async;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@
|
|||
struct _WpProxyNode
|
||||
{
|
||||
WpProxy parent;
|
||||
|
||||
/* The task to signal the proxy is initialized */
|
||||
GTask *init_task;
|
||||
|
||||
/* The node proxy listener */
|
||||
struct spa_hook listener;
|
||||
|
|
@ -20,7 +23,6 @@ struct _WpProxyNode
|
|||
struct pw_node_info *info;
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *proxy_node_parent_interface = NULL;
|
||||
static void wp_proxy_node_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
|
|
@ -33,8 +35,16 @@ node_event_info(void *data, const struct pw_node_info *info)
|
|||
{
|
||||
WpProxyNode *self = data;
|
||||
|
||||
/* Make sure the task is valid */
|
||||
if (!self->init_task)
|
||||
return;
|
||||
|
||||
/* Update the node info */
|
||||
self->info = pw_node_info_update(self->info, info);
|
||||
|
||||
/* Finish the creation of the proxy */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object (&self->init_task);
|
||||
}
|
||||
|
||||
static const struct pw_node_proxy_events node_events = {
|
||||
|
|
@ -47,6 +57,9 @@ wp_proxy_node_finalize (GObject * object)
|
|||
{
|
||||
WpProxyNode *self = WP_PROXY_NODE(object);
|
||||
|
||||
/* Destroy the init task */
|
||||
g_clear_object (&self->init_task);
|
||||
|
||||
/* Clear the info */
|
||||
if (self->info) {
|
||||
pw_node_info_free(self->info);
|
||||
|
|
@ -64,24 +77,20 @@ wp_proxy_node_init_async (GAsyncInitable *initable, int io_priority,
|
|||
WpProxy *wp_proxy = WP_PROXY(initable);
|
||||
struct pw_node_proxy *proxy = NULL;
|
||||
|
||||
/* Create the async task */
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Get the proxy from the base class */
|
||||
proxy = wp_proxy_get_pw_proxy(wp_proxy);
|
||||
|
||||
/* Add the node proxy listener */
|
||||
pw_node_proxy_add_listener(proxy, &self->listener, &node_events, self);
|
||||
|
||||
/* Call the parent interface */
|
||||
proxy_node_parent_interface->init_async (initable, io_priority, cancellable,
|
||||
callback, data);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_proxy_node_async_initable_init (gpointer iface, gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
|
||||
/* Set the parent interface */
|
||||
proxy_node_parent_interface = g_type_interface_peek_parent (iface);
|
||||
|
||||
/* Only set the init_async */
|
||||
ai_iface->init_async = wp_proxy_node_init_async;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,10 @@
|
|||
struct _WpProxyPort
|
||||
{
|
||||
WpProxy parent;
|
||||
|
||||
|
||||
/* The task to signal the proxy is initialized */
|
||||
GTask *init_task;
|
||||
|
||||
/* The port proxy listener */
|
||||
struct spa_hook listener;
|
||||
|
||||
|
|
@ -26,7 +29,6 @@ struct _WpProxyPort
|
|||
struct spa_audio_info_raw format;
|
||||
};
|
||||
|
||||
static GAsyncInitableIface *proxy_port_parent_interface = NULL;
|
||||
static void wp_proxy_port_async_initable_init (gpointer iface,
|
||||
gpointer iface_data);
|
||||
|
||||
|
|
@ -49,6 +51,10 @@ port_event_param(void *data, int seq, uint32_t id, uint32_t index,
|
|||
{
|
||||
WpProxyPort *self = data;
|
||||
|
||||
/* Make sure the task is valid */
|
||||
if (!self->init_task)
|
||||
return;
|
||||
|
||||
/* Only handle EnumFormat */
|
||||
if (id != SPA_PARAM_EnumFormat)
|
||||
return;
|
||||
|
|
@ -64,6 +70,10 @@ port_event_param(void *data, int seq, uint32_t id, uint32_t index,
|
|||
/* Parse the raw audio format */
|
||||
spa_pod_fixate((struct spa_pod*)param);
|
||||
spa_format_audio_raw_parse(param, &self->format);
|
||||
|
||||
/* Finish the creation of the proxy */
|
||||
g_task_return_boolean (self->init_task, TRUE);
|
||||
g_clear_object (&self->init_task);
|
||||
}
|
||||
|
||||
static const struct pw_port_proxy_events port_events = {
|
||||
|
|
@ -77,6 +87,9 @@ wp_proxy_port_finalize (GObject * object)
|
|||
{
|
||||
WpProxyPort *self = WP_PROXY_PORT(object);
|
||||
|
||||
/* Destroy the init task */
|
||||
g_clear_object (&self->init_task);
|
||||
|
||||
/* Clear the indo */
|
||||
if (self->info) {
|
||||
pw_port_info_free(self->info);
|
||||
|
|
@ -94,6 +107,9 @@ wp_proxy_port_init_async (GAsyncInitable *initable, int io_priority,
|
|||
WpProxy *wp_proxy = WP_PROXY(initable);
|
||||
struct pw_port_proxy *proxy = NULL;
|
||||
|
||||
/* Create the async task */
|
||||
self->init_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Get the proxy from the base class */
|
||||
proxy = wp_proxy_get_pw_proxy(wp_proxy);
|
||||
|
||||
|
|
@ -103,19 +119,12 @@ wp_proxy_port_init_async (GAsyncInitable *initable, int io_priority,
|
|||
/* Emit the EnumFormat param */
|
||||
pw_port_proxy_enum_params((struct pw_port_proxy*)proxy, 0,
|
||||
SPA_PARAM_EnumFormat, 0, -1, NULL);
|
||||
|
||||
/* Call the parent interface */
|
||||
proxy_port_parent_interface->init_async (initable, io_priority, cancellable,
|
||||
callback, data);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_proxy_port_async_initable_init (gpointer iface, gpointer iface_data)
|
||||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
|
||||
/* Set the parent interface */
|
||||
proxy_port_parent_interface = g_type_interface_peek_parent (iface);
|
||||
|
||||
/* Only set the init_async */
|
||||
ai_iface->init_async = wp_proxy_port_init_async;
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@ struct _WpProxyPrivate
|
|||
|
||||
/* The proxy listener */
|
||||
struct spa_hook listener;
|
||||
|
||||
/* The done info */
|
||||
GTask *done_task;
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -58,21 +55,8 @@ proxy_event_destroy (void *data)
|
|||
static void
|
||||
proxy_event_done (void *data, int seq)
|
||||
{
|
||||
WpProxyPrivate *self = wp_proxy_get_instance_private (WP_PROXY(data));
|
||||
|
||||
/* Emit the done signal */
|
||||
g_signal_emit (data, wp_proxy_signals[SIGNAL_DONE], 0);
|
||||
|
||||
/* Make sure the task is valid */
|
||||
if (!self->done_task)
|
||||
return;
|
||||
|
||||
/* Execute the task */
|
||||
g_task_return_boolean (self->done_task, TRUE);
|
||||
|
||||
/* Clean up */
|
||||
g_object_unref (self->done_task);
|
||||
self->done_task = NULL;
|
||||
}
|
||||
|
||||
static const struct pw_proxy_events proxy_events = {
|
||||
|
|
@ -81,6 +65,15 @@ static const struct pw_proxy_events proxy_events = {
|
|||
.done = proxy_event_done,
|
||||
};
|
||||
|
||||
static void
|
||||
wp_proxy_constructed (GObject * object)
|
||||
{
|
||||
WpProxyPrivate *self = wp_proxy_get_instance_private (WP_PROXY(object));
|
||||
|
||||
/* Add the event listener */
|
||||
pw_proxy_add_listener (self->proxy, &self->listener, &proxy_events, object);
|
||||
}
|
||||
|
||||
static void
|
||||
wp_proxy_finalize (GObject * object)
|
||||
{
|
||||
|
|
@ -136,22 +129,6 @@ wp_proxy_get_property (GObject * object, guint property_id, GValue * value,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
wp_proxy_init_async (GAsyncInitable *initable, int io_priority,
|
||||
GCancellable *cancellable, GAsyncReadyCallback callback, gpointer data)
|
||||
{
|
||||
WpProxyPrivate *self = wp_proxy_get_instance_private (WP_PROXY(initable));
|
||||
|
||||
/* Create the async task */
|
||||
self->done_task = g_task_new (initable, cancellable, callback, data);
|
||||
|
||||
/* Add the event listener */
|
||||
pw_proxy_add_listener (self->proxy, &self->listener, &proxy_events, initable);
|
||||
|
||||
/* Trigger the done callback */
|
||||
wp_proxy_sync(WP_PROXY(initable));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
wp_proxy_init_finish (GAsyncInitable *initable, GAsyncResult *result,
|
||||
GError **error)
|
||||
|
|
@ -166,7 +143,7 @@ wp_proxy_async_initable_init (gpointer iface, gpointer iface_data)
|
|||
{
|
||||
GAsyncInitableIface *ai_iface = iface;
|
||||
|
||||
ai_iface->init_async = wp_proxy_init_async;
|
||||
/* The init_async must be implemented in the derived classes */
|
||||
ai_iface->init_finish = wp_proxy_init_finish;
|
||||
}
|
||||
|
||||
|
|
@ -180,6 +157,7 @@ wp_proxy_class_init (WpProxyClass * klass)
|
|||
{
|
||||
GObjectClass *object_class = (GObjectClass *) klass;
|
||||
|
||||
object_class->constructed = wp_proxy_constructed;
|
||||
object_class->finalize = wp_proxy_finalize;
|
||||
object_class->get_property = wp_proxy_get_property;
|
||||
object_class->set_property = wp_proxy_set_property;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue