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);

View file

@ -51,7 +51,7 @@ bus_handler (GstBus * bus, GstMessage * message, gpointer user_data)
gchar *debug;
gst_message_parse_error (message, &error, &debug);
g_print ("got error %s (%s)\n", error->message, debug);
g_warning ("got error %s (%s)\n", error->message, debug);
g_free (debug);
pv_source_report_error (source, error);
@ -171,8 +171,6 @@ on_socket_notify (GObject *gobject,
g_object_get (gobject, "socket", &socket, NULL);
g_print ("source socket %p\n", socket);
if (socket == NULL) {
GSocket *prev_socket = g_object_get_data (gobject, "last-socket");
if (prev_socket) {
@ -184,7 +182,6 @@ on_socket_notify (GObject *gobject,
g_object_set_data (gobject, "last-socket", socket);
g_object_get (priv->sink, "num-handles", &num_handles, NULL);
g_print ("num handles %d\n", num_handles);
if (num_handles == 0) {
gst_element_set_state (priv->pipeline, GST_STATE_READY);
g_object_set (priv->filter, "caps", NULL, NULL);
@ -214,7 +211,6 @@ on_socket_notify (GObject *gobject,
gst_caps_unref (caps);
}
/* this is what we use as the final format for the output */
g_print ("final format %s\n", (gchar *) g_bytes_get_data (format, NULL));
g_object_set (gobject, "format", format, NULL);
g_bytes_unref (format);
@ -234,7 +230,6 @@ v4l2_create_source_output (PvSource *source,
gchar *str;
str = (gchar *) g_bytes_get_data (format_filter, NULL);
g_print ("input filter %s\n", str);
caps = gst_caps_from_string (str);
if (caps == NULL)
goto invalid_caps;
@ -244,7 +239,6 @@ v4l2_create_source_output (PvSource *source,
goto no_format;
str = gst_caps_to_string (filtered);
g_print ("output filter %s\n", str);
format_filter = g_bytes_new_take (str, strlen (str) + 1);
output = PV_SOURCE_CLASS (pv_v4l2_source_parent_class)

View file

@ -62,8 +62,6 @@ on_server_subscription_event (PvSubscribe *subscribe,
name = g_dbus_proxy_get_name (object);
object_path = g_dbus_proxy_get_object_path (object);
g_print ("got event %d %d %s:%s\n", event, flags, name, object_path);
switch (flags) {
default:
break;
@ -82,8 +80,6 @@ client_name_appeared_handler (GDBusConnection *connection,
if (!g_strcmp0 (name, g_dbus_connection_get_unique_name (connection)))
return;
g_print ("appeared client %s %p\n", name, data);
}
static void
@ -93,16 +89,12 @@ client_name_vanished_handler (GDBusConnection *connection,
{
SenderData *data = user_data;
g_print ("vanished client %s %p\n", name, data);
g_bus_unwatch_name (data->id);
}
static void
data_free (SenderData *data)
{
g_print ("free client %s %p\n", data->sender, data);
g_list_free_full (data->objects, g_object_unref);
g_hash_table_remove (data->daemon->priv->senders, data->sender);
g_free (data->sender);
@ -119,8 +111,6 @@ sender_data_new (PvDaemon *daemon, const gchar *sender)
data->daemon = daemon;
data->sender = g_strdup (sender);
g_print ("watch name %s %p\n", sender, data);
data->id = g_bus_watch_name_on_connection (priv->connection,
sender,
G_BUS_NAME_WATCHER_FLAGS_NONE,
@ -146,7 +136,6 @@ handle_connect_client (PvDaemon1 *interface,
sender = g_dbus_method_invocation_get_sender (invocation);
g_print ("connect client %s\n", sender);
client = pv_client_new (daemon, sender, PV_DBUS_OBJECT_PREFIX, arg_properties);
pv_daemon_track_object (daemon, sender, G_OBJECT (client));

View file

@ -33,16 +33,14 @@ static void
subscription_cb (PvContext *context, PvSubscriptionEvent type, PvSubscriptionFlags flags,
GDBusProxy *object, gpointer user_data)
{
g_print ("got event %d %d %s:%s\n", type, flags,
g_dbus_proxy_get_name (object),
g_dbus_proxy_get_object_path (object));
switch (type) {
case PV_SUBSCRIPTION_EVENT_NEW:
g_print ("object added %s\n", g_dbus_proxy_get_object_path (object));
dump_object (object);
break;
case PV_SUBSCRIPTION_EVENT_CHANGE:
g_print ("object changed %s\n", g_dbus_proxy_get_object_path (object));
dump_object (object);
break;
@ -58,21 +56,17 @@ on_state_notify (GObject *gobject,
gpointer user_data)
{
PvContextState state;
PvContext *c = user_data;
g_object_get (gobject, "state", &state, NULL);
g_print ("got state %d\n", state);
g_print ("got context state %d\n", state);
switch (state) {
case PV_CONTEXT_STATE_ERROR:
g_main_loop_quit (loop);
break;
case PV_CONTEXT_STATE_READY:
{
g_object_set (c, "subscription-mask", PV_SUBSCRIPTION_FLAGS_ALL, NULL);
g_signal_connect (c, "subscription-event", (GCallback) subscription_cb, NULL);
break;
}
default:
break;
@ -90,6 +84,8 @@ main (gint argc, gchar *argv[])
c = pv_context_new (NULL, "test-client", NULL);
g_signal_connect (c, "notify::state", (GCallback) on_state_notify, c);
g_object_set (c, "subscription-mask", PV_SUBSCRIPTION_FLAGS_ALL, NULL);
g_signal_connect (c, "subscription-event", (GCallback) subscription_cb, NULL);
pv_context_connect(c, PV_CONTEXT_FLAGS_NOFAIL);
g_main_loop_run (loop);