Move CreateSourceOutput to client object

Move the CreateSourceOutput method back to the client object so that we
can leave the selection of the source in the server.
This commit is contained in:
Wim Taymans 2015-05-11 16:08:34 +02:00
parent d9444ab360
commit 7bb3ae2562
10 changed files with 124 additions and 84 deletions

View file

@ -103,6 +103,53 @@ pv_client_set_property (GObject *_object,
}
}
static gboolean
handle_create_source_output (PvClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_source,
GVariant *arg_properties,
gpointer user_data)
{
PvClient *client = user_data;
PvClientPrivate *priv = client->priv;
PvSource *source;
PvSourceOutput *output;
const gchar *object_path, *sender;
source = pv_daemon_find_source (priv->daemon, arg_source, arg_properties);
if (source == NULL)
goto no_source;
output = pv_source_create_source_output (source, arg_properties, priv->object_path);
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_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
return TRUE;
/* ERRORS */
no_source:
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pulsevideo.Error", "Can't create sourc");
return TRUE;
}
no_output:
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pulsevideo.Error", "Can't create output");
return TRUE;
}
}
static void
client_register_object (PvClient *client, const gchar *prefix)
{
@ -117,6 +164,9 @@ client_register_object (PvClient *client, const gchar *prefix)
priv->client1 = pv_client1_skeleton_new ();
pv_client1_set_name (priv->client1, priv->sender);
g_signal_connect (priv->client1, "handle-create-source-output",
(GCallback) handle_create_source_output,
client);
pv_object_skeleton_set_client1 (skel, priv->client1);
g_free (priv->object_path);

View file

@ -38,6 +38,8 @@ struct _PvDaemonPrivate
GDBusObjectManagerServer *server_manager;
PvSubscribe *subscribe;
GList *sources;
GHashTable *senders;
};
@ -62,14 +64,8 @@ on_server_subscription_event (PvSubscribe *subscribe,
g_print ("got event %d %d %s:%s\n", event, flags, name, object_path);
switch (event) {
case PV_SUBSCRIPTION_EVENT_NEW:
break;
case PV_SUBSCRIPTION_EVENT_CHANGE:
break;
case PV_SUBSCRIPTION_EVENT_REMOVE:
switch (flags) {
default:
break;
}
}
@ -347,6 +343,44 @@ pv_daemon_track_object (PvDaemon *daemon,
data->objects = g_list_prepend (data->objects, object);
}
void
pv_daemon_add_source (PvDaemon *daemon, PvSource *source)
{
PvDaemonPrivate *priv;
g_return_if_fail (PV_IS_DAEMON (daemon));
g_return_if_fail (PV_IS_SOURCE (source));
priv = daemon->priv;
priv->sources = g_list_prepend (priv->sources, source);
}
void
pv_daemon_remove_source (PvDaemon *daemon, PvSource *source)
{
PvDaemonPrivate *priv;
g_return_if_fail (PV_IS_DAEMON (daemon));
g_return_if_fail (PV_IS_SOURCE (source));
priv = daemon->priv;
priv->sources = g_list_remove (priv->sources, source);
}
PvSource *
pv_daemon_find_source (PvDaemon *daemon, const gchar *name, GVariant *props)
{
PvDaemonPrivate *priv;
g_return_val_if_fail (PV_IS_DAEMON (daemon), NULL);
priv = daemon->priv;
if (priv->sources == NULL)
return NULL;
return priv->sources->data;
}
G_DEFINE_TYPE (PvDaemon, pv_daemon, G_TYPE_OBJECT);
static void

View file

@ -73,6 +73,10 @@ void pv_daemon_unexport (PvDaemon *daemon, const gchar *nam
void pv_daemon_track_object (PvDaemon *daemon, const gchar *sender, GObject *object);
void pv_daemon_add_source (PvDaemon *daemon, PvSource *source);
void pv_daemon_remove_source (PvDaemon *daemon, PvSource *source);
PvSource * pv_daemon_find_source (PvDaemon *daemon, const gchar *name, GVariant *props);
G_END_DECLS
#endif /* __PV_DAEMON_H__ */

View file

@ -128,40 +128,6 @@ pv_source_set_property (GObject *_object,
}
}
static gboolean
handle_create_source_output (PvSource1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
gpointer user_data)
{
PvSource *source = user_data;
PvSourcePrivate *priv = source->priv;
PvSourceOutput *output;
const gchar *object_path, *sender;
output = pv_source_create_source_output (source, arg_properties, priv->object_path);
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_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
return TRUE;
/* ERRORS */
no_output:
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pulsevideo.Error", "Can't create output");
return TRUE;
}
}
static gboolean
handle_get_capabilities (PvSource1 *interface,
GDBusMethodInvocation *invocation,
@ -194,9 +160,6 @@ source_register_object (PvSource *source)
"state", priv->state,
"properties", priv->properties,
NULL);
g_signal_connect (priv->iface, "handle-create-source-output",
(GCallback) handle_create_source_output,
source);
g_signal_connect (priv->iface, "handle-get-capabilities",
(GCallback) handle_get_capabilities,
source);
@ -204,6 +167,7 @@ source_register_object (PvSource *source)
g_free (priv->object_path);
priv->object_path = pv_daemon_export_uniquely (daemon, G_DBUS_OBJECT_SKELETON (skel));
pv_daemon_add_source (daemon, source);
return;
}
@ -213,6 +177,7 @@ source_unregister_object (PvSource *source)
{
PvSourcePrivate *priv = source->priv;
pv_daemon_remove_source (priv->daemon, source);
pv_daemon_unexport (priv->daemon, priv->object_path);
g_clear_object (&priv->iface);
}