summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2007-11-26 18:28:28 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2007-11-26 18:28:28 +0000
commit9e41deb8ad62476c6f144300da3758a1e7c5f1a4 (patch)
treedbbfe21f2e5a76380b8df7c81da2e9e734297c3b
parent1e202a0917143c90aabbf556eabf4f71ff54afc8 (diff)
Add full weak-object support to tp_list_connection_managers
-rw-r--r--examples/client/inspect-connection.c2
-rw-r--r--examples/client/list-managers.c5
-rw-r--r--telepathy-glib/connection-manager.c41
-rw-r--r--telepathy-glib/connection-manager.h5
4 files changed, 33 insertions, 20 deletions
diff --git a/examples/client/inspect-connection.c b/examples/client/inspect-connection.c
index e7dfa42bc..10458efbf 100644
--- a/examples/client/inspect-connection.c
+++ b/examples/client/inspect-connection.c
@@ -74,7 +74,7 @@ connection_ready (TpConnection *connection,
if (tp_cli_connection_call_list_channels (connection, -1,
/* If ListChannels() needed any arguments, they'd go here */
got_channels, g_main_loop_ref (mainloop),
- (GDestroyNotify) g_main_loop_unref) != NULL)
+ (GDestroyNotify) g_main_loop_unref, NULL) != NULL)
{
return;
}
diff --git a/examples/client/list-managers.c b/examples/client/list-managers.c
index e0b42b4ec..d4970bf12 100644
--- a/examples/client/list-managers.c
+++ b/examples/client/list-managers.c
@@ -14,7 +14,8 @@
void
got_connection_managers (TpConnectionManager **cms,
const GError *error,
- gpointer user_data)
+ gpointer user_data,
+ GObject *unused)
{
GMainLoop *mainloop = user_data;
@@ -57,7 +58,7 @@ main (int argc,
mainloop = g_main_loop_new (NULL, FALSE);
tp_list_connection_managers (tp_dbus_daemon_new (tp_get_bus ()),
- got_connection_managers, mainloop);
+ got_connection_managers, mainloop, NULL, NULL);
g_main_loop_run (mainloop);
diff --git a/telepathy-glib/connection-manager.c b/telepathy-glib/connection-manager.c
index 330d08eab..d0ea471ca 100644
--- a/telepathy-glib/connection-manager.c
+++ b/telepathy-glib/connection-manager.c
@@ -1082,24 +1082,22 @@ typedef struct
GHashTable *table;
TpConnectionManagerListCb callback;
gpointer user_data;
+ GDestroyNotify destroy;
+ TpProxyPendingCall *pending_call;
+ GObject *weak_object;
size_t base_len;
gboolean getting_names:1;
guint refcount:2;
} _ListContext;
-void
+static void
list_context_unref (_ListContext *list_context)
{
if (--list_context->refcount > 0)
return;
- if (list_context->callback != NULL)
- {
- GError error = { TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
- "Unable to query D-Bus daemon for list of connection managers" };
-
- list_context->callback (NULL, &error, list_context->user_data);
- }
+ if (list_context->destroy != NULL)
+ list_context->destroy (list_context->user_data);
g_hash_table_destroy (list_context->table);
g_slice_free (_ListContext, list_context);
@@ -1117,8 +1115,9 @@ tp_list_connection_managers_got_names (TpProxy *proxy,
if (error != NULL)
{
- list_context->callback (NULL, error, list_context->user_data);
- list_context->callback = NULL;
+ list_context->callback (NULL, error, list_context->user_data,
+ list_context->weak_object);
+ return;
}
for (iter = names; iter != NULL && *iter != NULL; iter++)
@@ -1148,7 +1147,7 @@ tp_list_connection_managers_got_names (TpProxy *proxy,
arr);
list_context->callback ((TpConnectionManager **) g_ptr_array_free (arr,
FALSE),
- NULL, list_context->user_data);
+ NULL, list_context->user_data, list_context->weak_object);
list_context->callback = NULL;
}
else
@@ -1157,15 +1156,22 @@ tp_list_connection_managers_got_names (TpProxy *proxy,
list_context->refcount++;
tp_cli_dbus_daemon_call_list_names (bus_daemon, 2000,
tp_list_connection_managers_got_names, list_context,
- (GDestroyNotify) list_context_unref, NULL);
+ (GDestroyNotify) list_context_unref, list_context->weak_object);
}
}
/**
* tp_list_connection_managers:
* @bus_daemon: proxy for the D-Bus daemon
- * @callback: callback to be called when listing the CMs succeeds or fails
+ * @callback: callback to be called when listing the CMs succeeds or fails;
+ * not called if the D-Bus connection fails completely or if the
+ * @weak_object goes away
* @user_data: user-supplied data for the callback
+ * @destroy: callback to destroy the user-supplied data, called after
+ * @callback, but also if the D-Bus connection fails or if the @weak_object
+ * goes away
+ * @weak_object: if not %NULL, will be weakly referenced; the callback will
+ * not be called, and the call will be cancelled, if the object has vanished
*
* List the available (running or installed) connection managers. Call the
* callback when done.
@@ -1173,13 +1179,18 @@ tp_list_connection_managers_got_names (TpProxy *proxy,
void
tp_list_connection_managers (TpDBusDaemon *bus_daemon,
TpConnectionManagerListCb callback,
- gpointer user_data)
+ gpointer user_data,
+ GDestroyNotify destroy,
+ GObject *weak_object)
{
_ListContext *list_context = g_slice_new0 (_ListContext);
list_context->base_len = strlen (TP_CM_BUS_NAME_BASE);
list_context->callback = callback;
list_context->user_data = user_data;
+ list_context->destroy = destroy;
+ list_context->weak_object = weak_object;
+
list_context->getting_names = FALSE;
list_context->refcount = 1;
list_context->table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
@@ -1187,5 +1198,5 @@ tp_list_connection_managers (TpDBusDaemon *bus_daemon,
tp_cli_dbus_daemon_call_list_activatable_names (bus_daemon, 2000,
tp_list_connection_managers_got_names, list_context,
- (GDestroyNotify) list_context_unref, NULL);
+ (GDestroyNotify) list_context_unref, weak_object);
}
diff --git a/telepathy-glib/connection-manager.h b/telepathy-glib/connection-manager.h
index b3578a0e9..3641005d7 100644
--- a/telepathy-glib/connection-manager.h
+++ b/telepathy-glib/connection-manager.h
@@ -88,11 +88,12 @@ TpConnectionManager *tp_connection_manager_new (TpDBusDaemon *dbus,
gboolean tp_connection_manager_activate (TpConnectionManager *self);
typedef void (*TpConnectionManagerListCb) (TpConnectionManager **cms,
- const GError *error, gpointer user_data);
+ const GError *error, gpointer user_data, GObject *weak_object);
void tp_list_connection_managers (TpDBusDaemon *bus_daemon,
TpConnectionManagerListCb callback,
- gpointer user_data);
+ gpointer user_data, GDestroyNotify destroy,
+ GObject *weak_object);
G_END_DECLS