mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
WIP
Change object model
This commit is contained in:
parent
d0f95fc323
commit
190f01d88e
38 changed files with 1594 additions and 3562 deletions
|
|
@ -24,43 +24,19 @@
|
|||
|
||||
#include "pinos/dbus/org-pinos.h"
|
||||
|
||||
struct _PinosClientPrivate
|
||||
typedef struct
|
||||
{
|
||||
PinosClient client;
|
||||
PinosObject object;
|
||||
PinosInterface ifaces[1];
|
||||
PinosDaemon *daemon;
|
||||
PinosClient1 *iface;
|
||||
|
||||
guint id;
|
||||
gchar *sender;
|
||||
PinosClient1 *iface;
|
||||
gchar *object_path;
|
||||
PinosProperties *properties;
|
||||
|
||||
GList *objects;
|
||||
};
|
||||
|
||||
#define PINOS_CLIENT_GET_PRIVATE(obj) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_CLIENT, PinosClientPrivate))
|
||||
|
||||
G_DEFINE_TYPE (PinosClient, pinos_client, G_TYPE_OBJECT);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DAEMON,
|
||||
PROP_SENDER,
|
||||
PROP_OBJECT_PATH,
|
||||
PROP_PROPERTIES,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIGNAL_APPEARED,
|
||||
SIGNAL_VANISHED,
|
||||
SIGNAL_REMOVE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
} PinosClientImpl;
|
||||
|
||||
static void
|
||||
client_name_appeared_handler (GDBusConnection *connection,
|
||||
|
|
@ -68,11 +44,11 @@ client_name_appeared_handler (GDBusConnection *connection,
|
|||
const gchar *name_owner,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosClient *client = user_data;
|
||||
PinosClientImpl *impl = user_data;
|
||||
PinosClient *client = &impl->client;
|
||||
|
||||
pinos_log_debug ("client %p: appeared %s %s", client, name, name_owner);
|
||||
|
||||
g_signal_emit (client, signals[SIGNAL_APPEARED], 0, NULL);
|
||||
pinos_signal_emit (&client->appeared, client, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -80,274 +56,124 @@ client_name_vanished_handler (GDBusConnection *connection,
|
|||
const gchar *name,
|
||||
gpointer user_data)
|
||||
{
|
||||
PinosClient *client = user_data;
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
PinosClientImpl *impl = user_data;
|
||||
PinosClient *client = &impl->client;
|
||||
|
||||
pinos_log_debug ("client %p: vanished %s", client, name);
|
||||
|
||||
g_signal_emit (client, signals[SIGNAL_VANISHED], 0, NULL);
|
||||
g_bus_unwatch_name (priv->id);
|
||||
pinos_signal_emit (&client->vanished, client, NULL);
|
||||
g_bus_unwatch_name (impl->id);
|
||||
}
|
||||
|
||||
static void
|
||||
client_watch_name (PinosClient *client)
|
||||
{
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
GDBusConnection *connection;
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
GDBusConnection *connection = NULL;
|
||||
|
||||
g_object_get (priv->daemon, "connection", &connection, NULL);
|
||||
// g_object_get (impl->daemon, "connection", &connection, NULL);
|
||||
|
||||
priv->id = g_bus_watch_name_on_connection (connection,
|
||||
priv->sender,
|
||||
impl->id = g_bus_watch_name_on_connection (connection,
|
||||
client->sender,
|
||||
G_BUS_NAME_WATCHER_FLAGS_NONE,
|
||||
client_name_appeared_handler,
|
||||
client_name_vanished_handler,
|
||||
client,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_get_property (GObject *_object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (_object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
g_value_set_object (value, priv->daemon);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
g_value_set_string (value, priv->sender);
|
||||
break;
|
||||
|
||||
case PROP_OBJECT_PATH:
|
||||
g_value_set_string (value, priv->object_path);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
g_value_set_boxed (value, priv->properties);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (client, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_set_property (GObject *_object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (_object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DAEMON:
|
||||
priv->daemon = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
case PROP_SENDER:
|
||||
priv->sender = g_value_dup_string (value);
|
||||
pinos_client1_set_sender (priv->iface, priv->sender);
|
||||
break;
|
||||
|
||||
case PROP_PROPERTIES:
|
||||
if (priv->properties)
|
||||
pinos_properties_free (priv->properties);
|
||||
priv->properties = g_value_dup_boxed (value);
|
||||
pinos_client1_set_properties (priv->iface, priv->properties ?
|
||||
pinos_properties_to_variant (priv->properties) : NULL);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (client, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
impl,
|
||||
(GDestroyNotify) pinos_client_destroy);
|
||||
}
|
||||
|
||||
static void
|
||||
client_register_object (PinosClient *client)
|
||||
{
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
PinosDaemon *daemon = impl->daemon;
|
||||
PinosObjectSkeleton *skel;
|
||||
|
||||
skel = pinos_object_skeleton_new (PINOS_DBUS_OBJECT_CLIENT);
|
||||
|
||||
pinos_object_skeleton_set_client1 (skel, priv->iface);
|
||||
pinos_object_skeleton_set_client1 (skel, impl->iface);
|
||||
|
||||
g_free (priv->object_path);
|
||||
priv->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_free (impl->object_path);
|
||||
impl->object_path = pinos_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
|
||||
g_object_unref (skel);
|
||||
|
||||
pinos_log_debug ("client %p: register %s", client, priv->object_path);
|
||||
pinos_log_debug ("client %p: register %s", client, impl->object_path);
|
||||
}
|
||||
|
||||
static void
|
||||
client_unregister_object (PinosClient *client)
|
||||
{
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
PinosDaemon *daemon = priv->daemon;
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
PinosDaemon *daemon = impl->daemon;
|
||||
|
||||
pinos_log_debug ("client %p: unregister", client);
|
||||
pinos_daemon_unexport (daemon, priv->object_path);
|
||||
pinos_daemon_unexport (daemon, impl->object_path);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_dispose (GObject * object)
|
||||
client_destroy (PinosObject * object)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (object, PinosClientImpl, object);
|
||||
PinosClient *client = &impl->client;
|
||||
GList *copy;
|
||||
|
||||
pinos_log_debug ("client %p: dispose", client);
|
||||
copy = g_list_copy (priv->objects);
|
||||
g_list_free_full (copy, g_object_unref);
|
||||
g_list_free (priv->objects);
|
||||
pinos_log_debug ("client %p: destroy", client);
|
||||
pinos_registry_remove_object (&client->core->registry, &impl->object);
|
||||
|
||||
copy = g_list_copy (impl->objects);
|
||||
g_list_free_full (copy, NULL);
|
||||
g_list_free (impl->objects);
|
||||
|
||||
client_unregister_object (client);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_parent_class)->dispose (object);
|
||||
}
|
||||
free (client->sender);
|
||||
if (client->properties)
|
||||
pinos_properties_free (client->properties);
|
||||
|
||||
static void
|
||||
pinos_client_finalize (GObject * object)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
pinos_log_debug ("client %p: finalize", client);
|
||||
|
||||
pinos_registry_remove_object (&priv->daemon->registry, &client->object);
|
||||
|
||||
g_clear_object (&priv->daemon);
|
||||
g_clear_object (&priv->iface);
|
||||
g_free (priv->sender);
|
||||
g_free (priv->object_path);
|
||||
if (priv->properties)
|
||||
pinos_properties_free (priv->properties);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_constructed (GObject * object)
|
||||
{
|
||||
PinosClient *client = PINOS_CLIENT (object);
|
||||
PinosClientPrivate *priv = client->priv;
|
||||
|
||||
pinos_log_debug ("client %p: constructed", client);
|
||||
|
||||
pinos_object_init (&client->object,
|
||||
priv->daemon->registry.uri.client,
|
||||
client,
|
||||
NULL);
|
||||
|
||||
pinos_registry_add_object (&priv->daemon->registry, &client->object);
|
||||
|
||||
client_watch_name (client);
|
||||
client_register_object (client);
|
||||
|
||||
G_OBJECT_CLASS (pinos_client_parent_class)->constructed (object);
|
||||
g_clear_object (&impl->iface);
|
||||
free (impl->object_path);
|
||||
free (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
pinos_client_class_init (PinosClientClass * klass)
|
||||
client_add_object (PinosClient *client,
|
||||
PinosObject *object)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
|
||||
g_type_class_add_private (klass, sizeof (PinosClientPrivate));
|
||||
g_return_if_fail (client);
|
||||
g_return_if_fail (object);
|
||||
|
||||
gobject_class->constructed = pinos_client_constructed;
|
||||
gobject_class->dispose = pinos_client_dispose;
|
||||
gobject_class->finalize = pinos_client_finalize;
|
||||
gobject_class->set_property = pinos_client_set_property;
|
||||
gobject_class->get_property = pinos_client_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DAEMON,
|
||||
g_param_spec_object ("daemon",
|
||||
"Daemon",
|
||||
"The daemon",
|
||||
PINOS_TYPE_DAEMON,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SENDER,
|
||||
g_param_spec_string ("sender",
|
||||
"Sender",
|
||||
"The sender",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_OBJECT_PATH,
|
||||
g_param_spec_string ("object-path",
|
||||
"Object Path",
|
||||
"The object path",
|
||||
NULL,
|
||||
G_PARAM_READABLE |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_PROPERTIES,
|
||||
g_param_spec_boxed ("properties",
|
||||
"Properties",
|
||||
"Client properties",
|
||||
PINOS_TYPE_PROPERTIES,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT |
|
||||
G_PARAM_STATIC_STRINGS));
|
||||
|
||||
signals[SIGNAL_APPEARED] = g_signal_new ("appeared",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
signals[SIGNAL_VANISHED] = g_signal_new ("vanished",
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
g_cclosure_marshal_generic,
|
||||
G_TYPE_NONE,
|
||||
0,
|
||||
G_TYPE_NONE);
|
||||
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);
|
||||
impl->objects = g_list_prepend (impl->objects, object);
|
||||
}
|
||||
|
||||
static void
|
||||
pinos_client_init (PinosClient * client)
|
||||
client_remove_object (PinosClient *client,
|
||||
PinosObject *object)
|
||||
{
|
||||
PinosClientPrivate *priv = client->priv = PINOS_CLIENT_GET_PRIVATE (client);
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
|
||||
priv->iface = pinos_client1_skeleton_new ();
|
||||
pinos_log_debug ("client %p: new", client);
|
||||
g_return_if_fail (client);
|
||||
g_return_if_fail (object);
|
||||
|
||||
impl->objects = g_list_remove (impl->objects, object);
|
||||
pinos_object_destroy (object);
|
||||
}
|
||||
|
||||
static bool
|
||||
client_has_object (PinosClient *client,
|
||||
PinosObject *object)
|
||||
{
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
GList *found;
|
||||
|
||||
g_return_val_if_fail (client, false);
|
||||
g_return_val_if_fail (object, false);
|
||||
|
||||
found = g_list_find (impl->objects, object);
|
||||
|
||||
return found != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -362,93 +188,57 @@ pinos_client_init (PinosClient * client)
|
|||
* Returns: a new #PinosClient
|
||||
*/
|
||||
PinosClient *
|
||||
pinos_client_new (PinosDaemon *daemon,
|
||||
pinos_client_new (PinosCore *core,
|
||||
const gchar *sender,
|
||||
PinosProperties *properties)
|
||||
{
|
||||
g_return_val_if_fail (PINOS_IS_DAEMON (daemon), NULL);
|
||||
PinosClient *client;
|
||||
PinosClientImpl *impl;
|
||||
|
||||
return g_object_new (PINOS_TYPE_CLIENT, "daemon", daemon,
|
||||
"sender", sender,
|
||||
"properties", properties,
|
||||
NULL);
|
||||
impl = calloc (1, sizeof (PinosClientImpl *));
|
||||
client = &impl->client;
|
||||
client->core = core;
|
||||
client->sender = strdup (sender);
|
||||
client->properties = properties;
|
||||
client->add_object = client_add_object;
|
||||
client->remove_object = client_remove_object;
|
||||
client->has_object = client_has_object;
|
||||
|
||||
impl->ifaces[0].type = client->core->registry.uri.client;
|
||||
impl->ifaces[0].iface = client;
|
||||
|
||||
pinos_object_init (&impl->object,
|
||||
client_destroy,
|
||||
1,
|
||||
impl->ifaces);
|
||||
|
||||
pinos_log_debug ("client %p: new", impl);
|
||||
|
||||
impl->iface = pinos_client1_skeleton_new ();
|
||||
|
||||
client_watch_name (client);
|
||||
client_register_object (client);
|
||||
|
||||
pinos_registry_add_object (&client->core->registry, &impl->object);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_client_remove:
|
||||
* pinos_client_destroy:
|
||||
* @client: a #PinosClient
|
||||
*
|
||||
* Trigger removal of @client
|
||||
*/
|
||||
void
|
||||
pinos_client_remove (PinosClient *client)
|
||||
pinos_client_destroy (PinosClient *client)
|
||||
{
|
||||
g_return_if_fail (PINOS_IS_CLIENT (client));
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
|
||||
pinos_log_debug ("client %p: remove", client);
|
||||
g_signal_emit (client, signals[SIGNAL_REMOVE], 0, NULL);
|
||||
}
|
||||
g_return_if_fail (client);
|
||||
|
||||
void
|
||||
pinos_client_add_object (PinosClient *client,
|
||||
GObject *object)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_CLIENT (client));
|
||||
g_return_if_fail (G_IS_OBJECT (object));
|
||||
priv = client->priv;
|
||||
|
||||
priv->objects = g_list_prepend (priv->objects, g_object_ref (object));
|
||||
}
|
||||
|
||||
void
|
||||
pinos_client_remove_object (PinosClient *client,
|
||||
GObject *object)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
|
||||
g_return_if_fail (PINOS_IS_CLIENT (client));
|
||||
g_return_if_fail (G_IS_OBJECT (object));
|
||||
priv = client->priv;
|
||||
|
||||
priv->objects = g_list_remove (priv->objects, object);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
gboolean
|
||||
pinos_client_has_object (PinosClient *client,
|
||||
GObject *object)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
GList *found;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_CLIENT (client), FALSE);
|
||||
g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
|
||||
priv = client->priv;
|
||||
|
||||
found = g_list_find (priv->objects, object);
|
||||
|
||||
return found != NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* pinos_client_get_sender:
|
||||
* @client: a #PinosClient
|
||||
*
|
||||
* Get the sender of @client.
|
||||
*
|
||||
* Returns: the sender of @client
|
||||
*/
|
||||
const gchar *
|
||||
pinos_client_get_sender (PinosClient *client)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_CLIENT (client), NULL);
|
||||
priv = client->priv;
|
||||
|
||||
return priv->sender;
|
||||
pinos_log_debug ("client %p: destroy", client);
|
||||
pinos_object_destroy (&impl->object);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -462,10 +252,9 @@ pinos_client_get_sender (PinosClient *client)
|
|||
const gchar *
|
||||
pinos_client_get_object_path (PinosClient *client)
|
||||
{
|
||||
PinosClientPrivate *priv;
|
||||
PinosClientImpl *impl = SPA_CONTAINER_OF (client, PinosClientImpl, client);
|
||||
|
||||
g_return_val_if_fail (PINOS_IS_CLIENT (client), NULL);
|
||||
priv = client->priv;
|
||||
g_return_val_if_fail (client, NULL);
|
||||
|
||||
return priv->object_path;
|
||||
return impl->object_path;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue