mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
more cleanup fixes
This commit is contained in:
parent
ac6d73f913
commit
273a5d35dc
9 changed files with 257 additions and 67 deletions
|
|
@ -51,6 +51,14 @@ enum
|
|||
PROP_PROPERTIES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_DISCONNECT,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
pv_client_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
|
|
@ -132,6 +140,10 @@ handle_create_source_output (PvClient1 *interface,
|
|||
GBytes *formats;
|
||||
GError *error = NULL;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (pv_client_get_sender (client), sender) != 0)
|
||||
goto not_allowed;
|
||||
|
||||
formats = g_bytes_new (arg_accepted_formats, strlen (arg_accepted_formats) + 1);
|
||||
|
||||
source = pv_daemon_find_source (priv->daemon,
|
||||
|
|
@ -150,17 +162,25 @@ handle_create_source_output (PvClient1 *interface,
|
|||
if (output == NULL)
|
||||
goto no_output;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
|
||||
pv_daemon_track_object (priv->daemon, sender, G_OBJECT (output));
|
||||
|
||||
object_path = pv_source_output_get_object_path (output);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (client),
|
||||
object_path,
|
||||
output,
|
||||
g_object_unref);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(o)", object_path));
|
||||
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
not_allowed:
|
||||
{
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pulsevideo.Error", "not client owner");
|
||||
return TRUE;
|
||||
}
|
||||
no_source:
|
||||
{
|
||||
g_dbus_method_invocation_return_gerror (invocation, error);
|
||||
|
|
@ -191,13 +211,20 @@ handle_create_source_input (PvClient1 *interface,
|
|||
GBytes *formats;
|
||||
GError *error = NULL;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
if (g_strcmp0 (pv_client_get_sender (client), sender) != 0)
|
||||
goto not_allowed;
|
||||
|
||||
source = pv_client_source_new (priv->daemon);
|
||||
if (source == NULL)
|
||||
goto no_source;
|
||||
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
g_object_set_data_full (G_OBJECT (client),
|
||||
pv_source_get_object_path (PV_SOURCE (source)),
|
||||
source,
|
||||
g_object_unref);
|
||||
|
||||
pv_daemon_track_object (priv->daemon, sender, G_OBJECT (source));
|
||||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
|
||||
formats = g_bytes_new (arg_possible_formats, strlen (arg_possible_formats) + 1);
|
||||
|
||||
|
|
@ -209,9 +236,13 @@ handle_create_source_input (PvClient1 *interface,
|
|||
if (input == NULL)
|
||||
goto no_input;
|
||||
|
||||
pv_daemon_track_object (priv->daemon, sender, G_OBJECT (input));
|
||||
|
||||
source_input_path = pv_source_output_get_object_path (input);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (client),
|
||||
source_input_path,
|
||||
input,
|
||||
g_object_unref);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("(o)",
|
||||
source_input_path));
|
||||
|
|
@ -219,6 +250,12 @@ handle_create_source_input (PvClient1 *interface,
|
|||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
not_allowed:
|
||||
{
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
"org.pulsevideo.Error", "not client owner");
|
||||
return TRUE;
|
||||
}
|
||||
no_source:
|
||||
{
|
||||
g_dbus_method_invocation_return_dbus_error (invocation,
|
||||
|
|
@ -233,6 +270,19 @@ no_input:
|
|||
return TRUE;
|
||||
}
|
||||
}
|
||||
static gboolean
|
||||
handle_disconnect (PvClient1 *interface,
|
||||
GDBusMethodInvocation *invocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
PvClient *client = user_data;
|
||||
|
||||
g_signal_emit (client, signals[SIGNAL_DISCONNECT], 0, NULL);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation,
|
||||
g_variant_new ("()"));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
client_register_object (PvClient *client, const gchar *prefix)
|
||||
|
|
@ -254,6 +304,9 @@ client_register_object (PvClient *client, const gchar *prefix)
|
|||
g_signal_connect (priv->client1, "handle-create-source-input",
|
||||
(GCallback) handle_create_source_input,
|
||||
client);
|
||||
g_signal_connect (priv->client1, "handle-disconnect",
|
||||
(GCallback) handle_disconnect,
|
||||
client);
|
||||
pv_object_skeleton_set_client1 (skel, priv->client1);
|
||||
|
||||
g_free (priv->object_path);
|
||||
|
|
@ -347,6 +400,18 @@ pv_client_class_init (PvClientClass * klass)
|
|||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_DISCONNECT] = g_signal_new ("disconnect",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -381,6 +446,25 @@ pv_client_new (PvDaemon *daemon,
|
|||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* pv_client_get_sender:
|
||||
* @client: a #PvClient
|
||||
*
|
||||
* Get the sender of @client.
|
||||
*
|
||||
* Returns: the sender of @client
|
||||
*/
|
||||
const gchar *
|
||||
pv_client_get_sender (PvClient *client)
|
||||
{
|
||||
PvClientPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PV_IS_CLIENT (client), NULL);
|
||||
priv = client->priv;
|
||||
|
||||
return priv->sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* pv_client_get_object_path:
|
||||
* @client: a #PvClient
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ PvClient * pv_client_new (PvDaemon *daemon,
|
|||
const gchar *prefix,
|
||||
GVariant *properties);
|
||||
|
||||
const gchar * pv_client_get_sender (PvClient *client);
|
||||
const gchar * pv_client_get_object_path (PvClient *client);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
|||
|
|
@ -105,6 +105,24 @@ sender_data_new (PvDaemon *daemon, const gchar *sender)
|
|||
return data;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_disconnect_client (PvClient *client,
|
||||
gpointer user_data)
|
||||
{
|
||||
PvDaemon *daemon = user_data;
|
||||
PvDaemonPrivate *priv = daemon->priv;
|
||||
const gchar *sender;
|
||||
SenderData *data;
|
||||
|
||||
sender = pv_client_get_sender (client);
|
||||
|
||||
data = g_hash_table_lookup (priv->senders, sender);
|
||||
if (data == NULL)
|
||||
return;
|
||||
|
||||
data->objects = g_list_remove (data->objects, client);
|
||||
g_object_unref (client);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
handle_connect_client (PvDaemon1 *interface,
|
||||
|
|
@ -119,6 +137,7 @@ handle_connect_client (PvDaemon1 *interface,
|
|||
sender = g_dbus_method_invocation_get_sender (invocation);
|
||||
|
||||
client = pv_client_new (daemon, sender, PV_DBUS_OBJECT_PREFIX, arg_properties);
|
||||
g_signal_connect (client, "disconnect", (GCallback) handle_disconnect_client, daemon);
|
||||
|
||||
pv_daemon_track_object (daemon, sender, G_OBJECT (client));
|
||||
|
||||
|
|
|
|||
|
|
@ -63,6 +63,14 @@ enum
|
|||
PROP_SOCKET,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_REMOVE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
static void
|
||||
pv_source_output_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
|
|
@ -239,6 +247,8 @@ handle_remove (PvSourceOutput1 *interface,
|
|||
|
||||
stop_transfer (output);
|
||||
|
||||
g_signal_emit (output, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
|
||||
g_dbus_method_invocation_return_value (invocation, NULL);
|
||||
|
||||
return TRUE;
|
||||
|
|
@ -287,8 +297,8 @@ pv_source_output_finalize (GObject * object)
|
|||
PvSourceOutput *output = PV_SOURCE_OUTPUT (object);
|
||||
PvSourceOutputPrivate *priv = output->priv;
|
||||
|
||||
g_object_unref (priv->daemon);
|
||||
g_object_unref (priv->iface);
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->client_path);
|
||||
g_free (priv->object_path);
|
||||
g_free (priv->source_path);
|
||||
|
|
@ -395,6 +405,17 @@ pv_source_output_class_init (PvSourceOutputClass * klass)
|
|||
G_TYPE_SOCKET,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_REMOVE] = g_signal_new ("remove",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -194,6 +194,15 @@ default_set_state (PvSource *source, PvSourceState state)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
handle_remove_output (PvSourceOutput *output,
|
||||
gpointer user_data)
|
||||
{
|
||||
PvSource *source = user_data;
|
||||
|
||||
pv_source_release_source_output (source, output);
|
||||
}
|
||||
|
||||
static PvSourceOutput *
|
||||
default_create_source_output (PvSource *source,
|
||||
const gchar *client_path,
|
||||
|
|
@ -202,13 +211,18 @@ default_create_source_output (PvSource *source,
|
|||
GError **error)
|
||||
{
|
||||
PvSourcePrivate *priv = source->priv;
|
||||
PvSourceOutput *output;
|
||||
|
||||
return g_object_new (PV_TYPE_SOURCE_OUTPUT, "daemon", priv->daemon,
|
||||
"object-path", prefix,
|
||||
"client-path", client_path,
|
||||
"source-path", priv->object_path,
|
||||
"possible-formats", format_filter,
|
||||
NULL);
|
||||
output = g_object_new (PV_TYPE_SOURCE_OUTPUT, "daemon", priv->daemon,
|
||||
"object-path", prefix,
|
||||
"client-path", client_path,
|
||||
"source-path", priv->object_path,
|
||||
"possible-formats", format_filter,
|
||||
NULL);
|
||||
|
||||
g_signal_connect (output, "remove", (GCallback) handle_remove_output, source);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue