more cleanup fixes

This commit is contained in:
Wim Taymans 2015-05-27 18:16:52 +02:00
parent ac6d73f913
commit 273a5d35dc
9 changed files with 257 additions and 67 deletions

View file

@ -68,7 +68,7 @@ pv_context_get_property (GObject *_object,
switch (prop_id) {
case PROP_MAIN_CONTEXT:
g_value_set_pointer (value, priv->context);
g_value_set_boxed (value, priv->context);
break;
case PROP_NAME:
@ -108,7 +108,7 @@ pv_context_set_property (GObject *_object,
switch (prop_id) {
case PROP_MAIN_CONTEXT:
priv->context = g_value_get_pointer (value);
priv->context = g_value_dup_boxed (value);
break;
case PROP_NAME:
@ -138,15 +138,17 @@ pv_context_finalize (GObject * object)
PvContext *context = PV_CONTEXT (object);
PvContextPrivate *priv = context->priv;
g_clear_pointer (&priv->context, g_main_context_unref);
g_free (priv->name);
g_clear_error (&priv->error);
if (priv->properties)
g_variant_unref (priv->properties);
g_clear_object (&priv->subscribe);
g_clear_error (&priv->error);
G_OBJECT_CLASS (pv_context_parent_class)->finalize (object);
}
static void
pv_context_class_init (PvContextClass * klass)
{
@ -165,12 +167,13 @@ pv_context_class_init (PvContextClass * klass)
*/
g_object_class_install_property (gobject_class,
PROP_MAIN_CONTEXT,
g_param_spec_pointer ("main-context",
"Main Context",
"The main context to use",
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_param_spec_boxed ("main-context",
"Main Context",
"The main context to use",
G_TYPE_MAIN_CONTEXT,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* PvContext:name
*
@ -344,8 +347,7 @@ on_client_connected (GObject *source_object,
PvContextPrivate *priv = context->priv;
GVariant *ret;
GError *error = NULL;
g_assert (g_main_context_get_thread_default () == priv->context);
const gchar *client_path;
ret = g_dbus_proxy_call_finish (priv->daemon, res, &error);
if (ret == NULL) {
@ -355,16 +357,16 @@ on_client_connected (GObject *source_object,
return;
}
g_variant_get (ret, "(o)", &priv->client_path);
g_variant_unref (ret);
g_variant_get (ret, "(&o)", &client_path);
pv_subscribe_get_proxy (priv->subscribe,
PV_DBUS_SERVICE,
priv->client_path,
client_path,
"org.pulsevideo.Client1",
NULL,
on_client_proxy,
context);
g_variant_unref (ret);
}
static void
@ -375,8 +377,6 @@ on_daemon_connected (GObject *source_object,
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
g_assert (g_main_context_get_thread_default () == priv->context);
context_set_state (context, PV_CONTEXT_STATE_REGISTERING);
g_dbus_proxy_call (priv->daemon,
@ -399,11 +399,9 @@ subscription_cb (PvSubscribe *subscribe,
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
g_assert (g_main_context_get_thread_default () == priv->context);
switch (flags) {
case PV_SUBSCRIPTION_FLAGS_DAEMON:
priv->daemon = object;
priv->daemon = g_object_ref (object);
break;
case PV_SUBSCRIPTION_FLAGS_CLIENT:
@ -439,7 +437,6 @@ subscription_state (GObject *object,
PvContextPrivate *priv = context->priv;
PvSubscriptionState state;
g_assert (g_main_context_get_thread_default () == priv->context);
g_assert (object == G_OBJECT (priv->subscribe));
state = pv_subscribe_get_state (priv->subscribe);
@ -464,8 +461,6 @@ on_name_appeared (GDBusConnection *connection,
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
g_assert (g_main_context_get_thread_default () == priv->context);
priv->connection = connection;
g_object_set (priv->subscribe, "connection", priv->connection,
@ -480,8 +475,6 @@ on_name_vanished (GDBusConnection *connection,
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
g_assert (g_main_context_get_thread_default () == priv->context);
priv->connection = connection;
g_object_set (priv->subscribe, "connection", connection, NULL);
@ -510,7 +503,7 @@ do_connect (PvContext *context)
on_name_appeared,
on_name_vanished,
context,
NULL);
g_object_unref);
return FALSE;
}
@ -536,7 +529,9 @@ pv_context_connect (PvContext *context, PvContextFlags flags)
priv->flags = flags;
context_set_state (context, PV_CONTEXT_STATE_CONNECTING);
g_main_context_invoke (priv->context, (GSourceFunc) do_connect, context);
g_main_context_invoke (priv->context,
(GSourceFunc) do_connect,
g_object_ref (context));
return TRUE;
}
@ -556,6 +551,7 @@ on_client_disconnected (GObject *source_object,
g_error ("failed to disconnect client: %s", error->message);
priv->error = error;
context_set_state (context, PV_CONTEXT_STATE_ERROR);
g_object_unref (context);
return;
}
g_variant_unref (ret);
@ -566,6 +562,7 @@ on_client_disconnected (GObject *source_object,
priv->id = 0;
context_set_state (context, PV_CONTEXT_STATE_UNCONNECTED);
g_object_unref (context);
}
static gboolean
@ -603,7 +600,9 @@ pv_context_disconnect (PvContext *context)
priv = context->priv;
g_return_val_if_fail (priv->client != NULL, FALSE);
g_main_context_invoke (priv->context, (GSourceFunc) do_disconnect, context);
g_main_context_invoke (priv->context,
(GSourceFunc) do_disconnect,
g_object_ref (context));
return TRUE;
}

View file

@ -33,8 +33,6 @@ struct _PvContextPrivate
GError *error;
GDBusProxy *daemon;
gchar *client_path;
GDBusProxy *client;
PvSubscriptionFlags subscription_mask;

View file

@ -33,15 +33,17 @@ struct _PvStreamPrivate
PvContext *context;
gchar *name;
GVariant *properties;
gchar *target;
PvStreamState state;
GError *error;
gchar *target;
GBytes *accepted_formats;
gboolean provide;
GBytes *accepted_formats;
GBytes *possible_formats;
GBytes *format;
gchar *source_output_path;
GDBusProxy *source_output;
PvStreamMode mode;
@ -156,6 +158,22 @@ pv_stream_finalize (GObject * object)
PvStream *stream = PV_STREAM (object);
PvStreamPrivate *priv = stream->priv;
g_clear_object (&priv->source_output);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
if (priv->format)
g_bytes_unref (priv->format);
g_free (priv->target);
if (priv->accepted_formats)
g_bytes_unref (priv->accepted_formats);
g_clear_error (&priv->error);
if (priv->properties)
g_variant_unref (priv->properties);
g_clear_object (&priv->context);
g_free (priv->name);
G_OBJECT_CLASS (pv_stream_parent_class)->finalize (object);
@ -408,6 +426,7 @@ on_source_output_proxy (GObject *source_object,
stream);
stream_set_state (stream, PV_STREAM_STATE_READY);
g_object_unref (stream);
return;
@ -416,6 +435,7 @@ source_output_failed:
priv->error = error;
stream_set_state (stream, PV_STREAM_STATE_ERROR);
g_error ("failed to get source output proxy: %s", error->message);
g_object_unref (stream);
return;
}
}
@ -430,23 +450,22 @@ on_source_output_created (GObject *source_object,
PvContext *context = priv->context;
GVariant *ret;
GError *error = NULL;
g_assert (g_main_context_get_thread_default () == priv->context->priv->context);
const gchar *source_output_path;
ret = g_dbus_proxy_call_finish (context->priv->client, res, &error);
if (ret == NULL)
goto create_failed;
g_variant_get (ret, "(o)", &priv->source_output_path);
g_variant_unref (ret);
g_variant_get (ret, "(o)", &source_output_path);
pv_subscribe_get_proxy (context->priv->subscribe,
PV_DBUS_SERVICE,
priv->source_output_path,
source_output_path,
"org.pulsevideo.SourceOutput1",
NULL,
on_source_output_proxy,
stream);
g_variant_unref (ret);
return;
@ -456,6 +475,7 @@ create_failed:
priv->error = error;
stream_set_state (stream, PV_STREAM_STATE_ERROR);
g_warning ("failed to get connect capture: %s", error->message);
g_object_unref (stream);
return;
}
}
@ -466,8 +486,6 @@ do_connect_capture (PvStream *stream)
PvStreamPrivate *priv = stream->priv;
PvContext *context = priv->context;
g_assert (g_main_context_get_thread_default () == priv->context->priv->context);
g_dbus_proxy_call (context->priv->client,
"CreateSourceOutput",
g_variant_new ("(ss)",
@ -509,13 +527,18 @@ pv_stream_connect_capture (PvStream *stream,
context = priv->context;
g_return_val_if_fail (pv_context_get_state (context) == PV_CONTEXT_STATE_READY, FALSE);
g_free (priv->target);
priv->target = g_strdup (source);
if (priv->accepted_formats)
g_bytes_unref (priv->accepted_formats);
priv->accepted_formats = g_bytes_ref (accepted_formats);
priv->provide = FALSE;
stream_set_state (stream, PV_STREAM_STATE_CONNECTING);
g_main_context_invoke (context->priv->context, (GSourceFunc) do_connect_capture, stream);
g_main_context_invoke (context->priv->context,
(GSourceFunc) do_connect_capture,
g_object_ref (stream));
return TRUE;
}
@ -526,8 +549,6 @@ do_connect_provide (PvStream *stream)
PvStreamPrivate *priv = stream->priv;
PvContext *context = priv->context;
g_assert (g_main_context_get_thread_default () == priv->context->priv->context);
g_dbus_proxy_call (context->priv->client,
"CreateSourceInput",
g_variant_new ("(s)", g_bytes_get_data (priv->possible_formats, NULL)),
@ -565,12 +586,16 @@ pv_stream_connect_provide (PvStream *stream,
context = priv->context;
g_return_val_if_fail (pv_context_get_state (context) == PV_CONTEXT_STATE_READY, FALSE);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
priv->possible_formats = g_bytes_ref (possible_formats);
priv->provide = TRUE;
stream_set_state (stream, PV_STREAM_STATE_CONNECTING);
g_main_context_invoke (context->priv->context, (GSourceFunc) do_connect_provide, stream);
g_main_context_invoke (context->priv->context,
(GSourceFunc) do_connect_provide,
g_object_ref (stream));
return TRUE;
}
@ -585,19 +610,18 @@ on_source_output_removed (GObject *source_object,
GVariant *ret;
GError *error = NULL;
g_assert (g_main_context_get_thread_default () == priv->context->priv->context);
ret = g_dbus_proxy_call_finish (priv->source_output, res, &error);
if (ret == NULL) {
priv->error = error;
stream_set_state (stream, PV_STREAM_STATE_ERROR);
g_warning ("failed to disconnect: %s", error->message);
g_object_unref (stream);
return;
}
g_clear_pointer (&priv->source_output_path, g_free);
g_clear_object (&priv->source_output);
stream_set_state (stream, PV_STREAM_STATE_UNCONNECTED);
g_object_unref (stream);
}
static gboolean
@ -605,8 +629,6 @@ do_disconnect (PvStream *stream)
{
PvStreamPrivate *priv = stream->priv;
g_assert (g_main_context_get_thread_default () == priv->context->priv->context);
g_dbus_proxy_call (priv->source_output,
"Remove",
g_variant_new ("()"),
@ -640,7 +662,9 @@ pv_stream_disconnect (PvStream *stream)
context = priv->context;
g_return_val_if_fail (pv_context_get_state (context) == PV_CONTEXT_STATE_READY, FALSE);
g_main_context_invoke (context->priv->context, (GSourceFunc) do_disconnect, stream);
g_main_context_invoke (context->priv->context,
(GSourceFunc) do_disconnect,
g_object_ref (stream));
return TRUE;
}