implement interface remove

Clean up some g_print
This commit is contained in:
Wim Taymans 2015-05-21 10:18:21 +02:00
parent 4a61f988dc
commit e24398fe8c
6 changed files with 51 additions and 66 deletions

View file

@ -329,7 +329,6 @@ on_client_connected (GObject *source_object,
}
g_variant_get (ret, "(o)", &priv->client_path);
g_print ("got client %s\n", priv->client_path);
g_variant_unref (ret);
}
@ -365,8 +364,6 @@ subscription_cb (PvSubscribe *subscribe,
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
g_print ("got event %d %d\n", event, flags);
g_assert (g_main_context_get_thread_default () == priv->context);
switch (flags) {
@ -415,7 +412,6 @@ subscription_state (GObject *object,
g_assert (object == G_OBJECT (priv->subscribe));
state = pv_subscribe_get_state (priv->subscribe);
g_print ("got subscription state %d\n", state);
switch (state) {
case PV_SUBSCRIPTION_STATE_READY:
@ -439,8 +435,6 @@ on_name_appeared (GDBusConnection *connection,
g_assert (g_main_context_get_thread_default () == priv->context);
g_print ("context: on name appeared\n");
priv->connection = connection;
g_object_set (priv->subscribe, "connection", priv->connection,
@ -457,8 +451,6 @@ on_name_vanished (GDBusConnection *connection,
g_assert (g_main_context_get_thread_default () == priv->context);
g_print ("context: on name vanished\n");
priv->connection = connection;
g_object_set (priv->subscribe, "connection", connection, NULL);

View file

@ -390,15 +390,11 @@ on_source_output_proxy (GObject *source_object,
if (priv->source_output == NULL)
goto source_output_failed;
g_print ("got source-output %s\n", priv->source_output_path);
v = g_dbus_proxy_get_cached_property (priv->source_output, "PossibleFormats");
if (v) {
str = g_variant_dup_string (v, NULL);
g_variant_unref (v);
g_print ("got possible formats %s\n", str);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
priv->possible_formats = g_bytes_new_take (str, strlen (str) + 1);
@ -459,7 +455,7 @@ create_failed:
{
priv->error = error;
stream_set_state (stream, PV_STREAM_STATE_ERROR);
g_print ("failed to get connect capture: %s", error->message);
g_warning ("failed to get connect capture: %s", error->message);
return;
}
}
@ -595,7 +591,7 @@ on_source_output_removed (GObject *source_object,
if (ret == NULL) {
priv->error = error;
stream_set_state (stream, PV_STREAM_STATE_ERROR);
g_print ("failed to disconnect: %s", error->message);
g_warning ("failed to disconnect: %s", error->message);
return;
}
g_clear_pointer (&priv->source_output_path, g_free);
@ -703,7 +699,7 @@ on_socket_condition (GSocket *socket,
break;
}
case G_IO_OUT:
g_print ("can do IO\n");
g_warning ("can do IO\n");
break;
default:
@ -719,7 +715,6 @@ handle_socket (PvStream *stream, gint fd)
PvStreamPrivate *priv = stream->priv;
GError *error = NULL;
g_print ("got fd %d\n", fd);
priv->socket = g_socket_new_from_fd (fd, &error);
if (priv->socket == NULL)
goto socket_failed;

View file

@ -48,6 +48,7 @@ typedef struct
gboolean pending;
GDBusProxy *proxy;
GList *tasks;
gboolean removed;
} PvObjectData;
@ -120,6 +121,30 @@ on_proxy_properties_changed (GDBusProxy *proxy,
notify_event (data->subscribe, data, PV_SUBSCRIPTION_EVENT_CHANGE);
}
static void
object_data_free (PvObjectData *data)
{
g_object_unref (data->proxy);
g_free (data->sender_name);
g_free (data->object_path);
g_free (data->interface_name);
g_free (data);
}
static void
remove_data (PvSubscribe *subscribe, PvObjectData *data)
{
PvSubscribePrivate *priv = subscribe->priv;
if (data->pending) {
data->removed = TRUE;
} else {
priv->objects = g_list_remove (priv->objects, data);
notify_event (subscribe, data, PV_SUBSCRIPTION_EVENT_REMOVE);
object_data_free (data);
}
}
static void
on_proxy_created (GObject *source_object,
GAsyncResult *res,
@ -142,8 +167,6 @@ on_proxy_created (GObject *source_object,
return;
}
g_print ("got proxy for %s:%s\n", data->object_path, data->interface_name);
g_signal_connect (data->proxy,
"g-properties-changed",
(GCallback) on_proxy_properties_changed,
@ -161,8 +184,12 @@ on_proxy_created (GObject *source_object,
if (--priv->pending_proxies == 0)
subscription_set_state (subscribe, PV_SUBSCRIPTION_STATE_READY);
if (data->removed)
remove_data (subscribe, data);
}
static void
add_interface (PvSubscribe *subscribe,
const gchar *object_path,
@ -182,8 +209,6 @@ add_interface (PvSubscribe *subscribe,
priv->objects = g_list_prepend (priv->objects, data);
priv->pending_proxies++;
g_print ("making proxy for %s:%s\n", object_path, interface_name);
g_dbus_proxy_new (priv->connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo* */
@ -200,7 +225,18 @@ remove_interface (PvSubscribe *subscribe,
const gchar *object_path,
const gchar *interface_name)
{
g_print ("remove interface %s\n", interface_name);
PvSubscribePrivate *priv = subscribe->priv;
GList *walk;
for (walk = priv->objects; walk; walk = g_list_next (walk)) {
PvObjectData *data = walk->data;
if (g_strcmp0 (data->object_path, object_path) == 0 &&
g_strcmp0 (data->interface_name, interface_name) == 0) {
remove_data (subscribe, data);
break;
}
}
}
static void
@ -246,8 +282,6 @@ on_manager_proxy_signal (GDBusProxy *proxy,
PvSubscribe *subscribe = user_data;
const gchar *object_path;
g_print ("proxy signal %s %p\n", signal_name, g_main_context_get_thread_default ());
if (g_strcmp0 (signal_name, "InterfacesAdded") == 0) {
GVariant *ifaces_and_properties;
@ -317,8 +351,6 @@ manager_proxy_appeared (PvSubscribe *subscribe)
{
PvSubscribePrivate *priv = subscribe->priv;
g_print ("client manager appeared def: %p\n", g_main_context_get_thread_default ());
g_dbus_proxy_call (priv->manager_proxy,
"GetManagedObjects",
NULL, /* parameters */
@ -343,12 +375,7 @@ on_manager_proxy_name_owner (GObject *object,
PvSubscribePrivate *priv = subscribe->priv;
gchar *name_owner;
g_print ("client manager owner def: %p\n", g_main_context_get_thread_default ());
g_object_get (priv->manager_proxy, "g-name-owner", &name_owner, NULL);
g_print ("client manager %s %s\n",
g_dbus_proxy_get_name (G_DBUS_PROXY (priv->manager_proxy)),
name_owner);
if (name_owner) {
manager_proxy_appeared (subscribe);
@ -364,8 +391,6 @@ connect_client_signals (PvSubscribe *subscribe)
{
PvSubscribePrivate *priv = subscribe->priv;
g_print ("add signals def: %p\n", g_main_context_get_thread_default ());
g_signal_connect (priv->manager_proxy, "notify::g-name-owner",
(GCallback) on_manager_proxy_name_owner, subscribe);
@ -382,8 +407,6 @@ on_manager_proxy_ready (GObject *source_object,
PvSubscribePrivate *priv = subscribe->priv;
GError *error = NULL;
g_print ("manager proyx ready def: %p\n", g_main_context_get_thread_default ());
priv->manager_proxy = g_dbus_proxy_new_finish (res, &error);
if (priv->manager_proxy == NULL)
goto manager_error;
@ -413,9 +436,6 @@ install_subscription (PvSubscribe *subscribe)
subscription_set_state (subscribe, PV_SUBSCRIPTION_STATE_CONNECTING);
g_print ("new client manager def: %p\n", g_main_context_get_thread_default ());
g_print ("new client manager for %s\n", priv->service);
g_dbus_proxy_new (priv->connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo* */
@ -511,7 +531,6 @@ pv_subscribe_finalize (GObject * object)
PvSubscribe *subscribe = PV_SUBSCRIBE (object);
PvSubscribePrivate *priv = subscribe->priv;
g_print ("cancel\n");
g_cancellable_cancel (priv->cancellable);
if (priv->manager_proxy)
g_object_unref (priv->manager_proxy);