From c379854bdc7eb3d7c636253879ee58b37ef21879 Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Thu, 18 Feb 2010 18:26:17 +0000 Subject: Added Open Channel retrieval. This allow the logging of channels which are already open and thus no further NewChannel signal will be sent. --- telepathy-logger/observer.c | 124 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 8 deletions(-) diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index 27f0e8b..3cc297c 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,16 @@ static void got_tpl_channel_text_ready_cb (GObject *obj, GAsyncResult *result, static TplChannelFactory tpl_observer_get_channel_factory (TplObserver *self); static GHashTable *tpl_observer_get_channel_map (TplObserver *self); +/* Get open channels API */ +static void tpl_observer_get_open_channels (void); +static void tpl_observer_prepared_account_manager_cb (GObject *obj, + GAsyncResult *result, gpointer user_data); +static void tpl_observer_got_channel_list_cb (TpProxy *proxy, + const GValue *out_Value, const GError *error, gpointer user_data, + GObject *weak_object); + +/* end of Get open channels API */ + #define GET_PRIV(obj) TPL_GET_PRIV (obj, TplObserver) struct _TplObserverPriv @@ -225,8 +236,7 @@ tpl_observer_observe_channels (TpSvcClientObserver *self, if (tpl_chan == NULL) { DEBUG ("%s", error->message); - g_error_free (error); - error = NULL; + g_clear_error (&error); continue; } PATH_DEBUG (tpl_chan, "Starting preparation fo TplChannel instance"); @@ -249,9 +259,13 @@ error: g_object_unref (tp_bus_daemon); g_clear_error (&error); - DEBUG ("Returning from observe channels on error condition. " + /* observer_channels has been called by the Channel Dispatcher */ + if (dbus_context != NULL) + { + DEBUG ("Returning from observe channels on error condition. " "Unable to log the channel"); - tp_svc_client_observer_return_from_observe_channels (dbus_context); + tp_svc_client_observer_return_from_observe_channels (dbus_context); + } } @@ -266,8 +280,12 @@ got_tpl_channel_text_ready_cb (GObject *obj, observing_ctx->chan_n -= 1; if (observing_ctx->chan_n == 0) { - DEBUG ("Returning from observe channels"); - tp_svc_client_observer_return_from_observe_channels (dbus_ctx); + /* observer_channels has been called by the Channel Dispatcher */ + if (dbus_ctx != NULL) + { + DEBUG ("Returning from observe channels"); + tp_svc_client_observer_return_from_observe_channels (dbus_ctx); + } g_slice_free (ObservingContext, observing_ctx); } } @@ -427,6 +445,8 @@ tpl_observer_init (TplObserver *self) priv->channel_map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); priv->logmanager = tpl_log_manager_dup_singleton (); + + tpl_observer_get_open_channels (); } @@ -622,11 +642,99 @@ tpl_observer_set_channel_factory (TplObserver *self, { TplObserverPriv *priv = GET_PRIV (self); - g_return_if_fail (TPL_IS_OBSERVER (self)); - g_return_if_fail (factory != NULL); g_return_if_fail (factory != NULL); g_return_if_fail (priv->channel_factory == NULL); + g_return_if_fail (TPL_IS_OBSERVER (self)); priv->channel_factory = factory; +} + +/* Retrieving open channel */ +/* This part can be removed when the Channel Dispatcher will implement a + * proper API for + * org.freedesktop.Telepathy.Connection.Interface.Requests.Channels */ +static void +tpl_observer_get_open_channels (void) +{ + const GQuark features[2] = { TP_ACCOUNT_MANAGER_FEATURE_CORE, 0 }; + + TpAccountManager *acc_man = tp_account_manager_dup (); + tp_account_manager_prepare_async (acc_man, features, + tpl_observer_prepared_account_manager_cb, NULL); +} + + +static void +tpl_observer_prepared_account_manager_cb (GObject *obj, + GAsyncResult *result, + gpointer user_data) +{ + TpAccountManager *am = TP_ACCOUNT_MANAGER (obj); + GList *list, *l; + GError *error = NULL; + + if (!tp_account_manager_prepare_finish (TP_ACCOUNT_MANAGER (obj), result, + &error)) + { + DEBUG ("Unable to prepare connection manager: %s", error->message); + return; + } + + list = tp_account_manager_get_valid_accounts (am); + + for (l = list; l != NULL; l = g_list_next (l)) + { + TpConnection *conn = NULL; + TpAccount *acc = l->data; + g_assert (TP_IS_ACCOUNT (acc)); + + if (!tp_account_is_enabled (acc)) + continue; + + conn = tp_account_get_connection (acc); + /* account's connection is offline */ + if (conn == NULL) + continue; + + tp_cli_dbus_properties_call_get (conn, -1, + TP_IFACE_CONNECTION_INTERFACE_REQUESTS, + "Channels", + tpl_observer_got_channel_list_cb, acc, NULL, NULL); + } + g_list_free (list); +} + + +void tpl_observer_got_channel_list_cb (TpProxy *proxy, + const GValue *out_Value, + const GError *error, + gpointer user_data, + GObject *weak_object) +{ + TpAccount *acc = TP_ACCOUNT (user_data); + TpConnection *conn = TP_CONNECTION (proxy); + TplObserver *observer = tpl_observer_new (); + GPtrArray *channels; + + if (error != NULL) + { + DEBUG ("%s", error->message); + return; + } + + g_return_if_fail (G_VALUE_HOLDS (out_Value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST)); + + channels = g_value_get_boxed (out_Value); + + /* call observe_channels with + * Dispatch_Operation = NULL, Requests_Satisfied = NULL, + * Observer_Info = NULL and DBusGMethodInvocation = NULL + * so that it will undertand that it's not been called by a Channel + * Dispatcher */ + tpl_observer_observe_channels (TP_SVC_CLIENT_OBSERVER (observer), + tp_proxy_get_object_path (TP_PROXY (acc)), + tp_proxy_get_object_path (TP_PROXY (conn)), + channels, NULL, NULL, NULL, NULL); + g_object_unref (observer); } -- cgit v1.2.1 From 8d884a2f125a1f96256ec2511fd10a0590a77c85 Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Thu, 18 Feb 2010 19:33:28 +0000 Subject: Improved debug while called during open channel inspection Also fixed the code comments --- telepathy-logger/observer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index 3cc297c..22b9aac 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -162,6 +162,10 @@ tpl_observer_observe_channels (TpSvcClientObserver *self, g_return_if_fail (!TPL_STR_EMPTY (account)); g_return_if_fail (!TPL_STR_EMPTY (connection)); + if (dbus_context == NULL) + DEBUG ("called during open channel inspection, not by the Channel " + "Dispatcher. OK."); + chan_factory = tpl_observer_get_channel_factory (TPL_OBSERVER (self)); /* Check if logging if enabled globally and for the given account_path, @@ -280,9 +284,9 @@ got_tpl_channel_text_ready_cb (GObject *obj, observing_ctx->chan_n -= 1; if (observing_ctx->chan_n == 0) { - /* observer_channels has been called by the Channel Dispatcher */ if (dbus_ctx != NULL) { + /* observer_channels has been called by the Channel Dispatcher */ DEBUG ("Returning from observe channels"); tp_svc_client_observer_return_from_observe_channels (dbus_ctx); } -- cgit v1.2.1 From bee2939e886835e90108f72c25bd38435d4128b5 Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Thu, 25 Feb 2010 14:48:43 +0000 Subject: Preparing TpAccount and TpChannel before channel retrieval. --- telepathy-logger/observer.c | 148 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 127 insertions(+), 21 deletions(-) diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index 22b9aac..6c5ff5d 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -96,6 +96,12 @@ static void tpl_observer_prepared_account_manager_cb (GObject *obj, static void tpl_observer_got_channel_list_cb (TpProxy *proxy, const GValue *out_Value, const GError *error, gpointer user_data, GObject *weak_object); +static void tpl_observer_get_open_channels_prepare_account_cb (GObject *proxy, + GAsyncResult *result, gpointer user_data); +static void tpl_observer_get_open_channels_prepared_connection (TpConnection *conn, + const GError *error, gpointer user_data); + + /* end of Get open channels API */ @@ -660,10 +666,8 @@ tpl_observer_set_channel_factory (TplObserver *self, static void tpl_observer_get_open_channels (void) { - const GQuark features[2] = { TP_ACCOUNT_MANAGER_FEATURE_CORE, 0 }; - TpAccountManager *acc_man = tp_account_manager_dup (); - tp_account_manager_prepare_async (acc_man, features, + tp_account_manager_prepare_async (acc_man, NULL, tpl_observer_prepared_account_manager_cb, NULL); } @@ -681,31 +685,107 @@ tpl_observer_prepared_account_manager_cb (GObject *obj, &error)) { DEBUG ("Unable to prepare connection manager: %s", error->message); + g_object_unref (am); return; } + /* accountspointed by the list are not referenced */ list = tp_account_manager_get_valid_accounts (am); for (l = list; l != NULL; l = g_list_next (l)) { - TpConnection *conn = NULL; TpAccount *acc = l->data; + g_assert (TP_IS_ACCOUNT (acc)); - if (!tp_account_is_enabled (acc)) - continue; + /* ref here, unref in callbacks on error or at the end of the + * chain */ + tp_account_prepare_async (g_object_ref (acc), NULL, + tpl_observer_get_open_channels_prepare_account_cb, NULL); + } + g_list_free (list); +} + + +static void +tpl_observer_get_open_channels_prepare_account_cb (GObject *proxy, + GAsyncResult *result, + gpointer user_data) +{ + TpAccount *account = TP_ACCOUNT (proxy); + TpConnection *conn; + GError *error = NULL; + + g_return_if_fail (TP_IS_ACCOUNT (account)); - conn = tp_account_get_connection (acc); - /* account's connection is offline */ - if (conn == NULL) - continue; + if (!tp_account_is_enabled (account)) + goto early_out; - tp_cli_dbus_properties_call_get (conn, -1, - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, - "Channels", - tpl_observer_got_channel_list_cb, acc, NULL, NULL); + if (!tp_account_prepare_finish (account, result, &error)) + { + DEBUG ("unable to prapare account: %s", error->message); + goto early_out; } - g_list_free (list); + + conn = tp_account_get_connection (account); + /* account's connection is offline */ + if (conn == NULL) + goto early_out; + + /* ref here, unref in callbacks on error or at the end of the chain */ + tp_connection_call_when_ready (g_object_ref (conn), + tpl_observer_get_open_channels_prepared_connection, account); + + return; + +early_out: + if (error != NULL) + g_error_free (error); + if (account != NULL) + g_object_unref (account); +} + + +static void +tpl_observer_get_open_channels_prepared_connection (TpConnection *conn, + const GError *error, + gpointer user_data) +{ + TpAccount *account = TP_ACCOUNT (user_data); + + /* not use g_return_* or it will leak refs */ + if (!TP_IS_CONNECTION (conn)) + { + DEBUG ("conn is not TP_CONNECTION"); + goto err; + } + if (!TP_IS_ACCOUNT (account)) + { + DEBUG ("account is not TP_ACCOUNT"); + goto err; + } + + + if (error != NULL) + { + DEBUG ("unable to prepare connection for open channel retrieval: %s", + error->message); + goto err; + } + + /* I do not pass the observer as a weak_object or I will leak some + * references to account and connection in the callback in case is destroyed + * and the call canceled */ + tp_cli_dbus_properties_call_get (conn, -1, + TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels", + tpl_observer_got_channel_list_cb, account, NULL, NULL); + return; + +err: + if (conn != NULL) + g_object_unref (conn); + if (account != NULL) + g_object_unref (account); } @@ -715,18 +795,38 @@ void tpl_observer_got_channel_list_cb (TpProxy *proxy, gpointer user_data, GObject *weak_object) { - TpAccount *acc = TP_ACCOUNT (user_data); + TpAccount *account = TP_ACCOUNT (user_data); TpConnection *conn = TP_CONNECTION (proxy); TplObserver *observer = tpl_observer_new (); GPtrArray *channels; + /* not use g_return_* or it will leak refs */ + if (!TP_IS_CONNECTION (conn)) + { + DEBUG ("conn is not TP_CONNECTION"); + goto out; + } + if (!TP_IS_ACCOUNT (account)) + { + DEBUG ("account is not TP_ACCOUNT"); + goto out; + } + if (error != NULL) { - DEBUG ("%s", error->message); - return; + DEBUG ("unable to retrieve channels for connection %s: %s", + tp_proxy_get_object_path (TP_PROXY (conn)), + error->message); + goto out; } - g_return_if_fail (G_VALUE_HOLDS (out_Value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST)); + /* not use g_return_* or it will leak refs */ + if (!G_VALUE_HOLDS (out_Value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST)) + { + g_critical ("channel list GValue does not hold " + "TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST"); + goto out; + } channels = g_value_get_boxed (out_Value); @@ -736,9 +836,15 @@ void tpl_observer_got_channel_list_cb (TpProxy *proxy, * so that it will undertand that it's not been called by a Channel * Dispatcher */ tpl_observer_observe_channels (TP_SVC_CLIENT_OBSERVER (observer), - tp_proxy_get_object_path (TP_PROXY (acc)), + tp_proxy_get_object_path (TP_PROXY (account)), tp_proxy_get_object_path (TP_PROXY (conn)), channels, NULL, NULL, NULL, NULL); - g_object_unref (observer); +out: + if (account != NULL) + g_object_unref (account); + if (conn != NULL) + g_object_unref (conn); + if (observer != NULL) + g_object_unref (observer); } -- cgit v1.2.1 From f460f051e89dc0088bc12b59aca2664f0d5e8a66 Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Thu, 25 Feb 2010 15:27:51 +0000 Subject: Improving debug messaes for log-manager and log-store-emapthy Plus some typos in comments --- telepathy-logger/debug.h | 4 ++-- telepathy-logger/log-manager.c | 8 +++++++- telepathy-logger/log-store-empathy.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/telepathy-logger/debug.h b/telepathy-logger/debug.h index 1766b2c..db9b35a 100644 --- a/telepathy-logger/debug.h +++ b/telepathy-logger/debug.h @@ -61,8 +61,8 @@ G_END_DECLS #define DEBUGGING gabble_debug_flag_is_set (DEBUG_FLAG) -/* The same of DEBUG, printing also the object-path property for the TpProxy - * passed as first arg. prepending '_' not not shadow any local variable */ +/* The same of DEBUG, printing also the object-path property for the TpProxy, + * passed as first arg. prepending '_' to avoid shadowing local variables */ #define PATH_DEBUG(_proxy, _format, ...) \ G_STMT_START { \ const gchar *_path; \ diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c index 98ebe37..01c83b1 100644 --- a/telepathy-logger/log-manager.c +++ b/telepathy-logger/log-manager.c @@ -151,6 +151,8 @@ tpl_log_manager_init (TplLogManager *self) self->priv = priv; + DEBUG ("Initialising the Log Manager"); + /* The TPL's default read-write logstore */ tplogger = g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, "name", TPL_LOG_MANAGER_LOG_STORE_DEFAULT, @@ -158,7 +160,8 @@ tpl_log_manager_init (TplLogManager *self) "readable", TRUE, NULL); if (tplogger == NULL) - g_critical ("Error during TplLogStoreEmpathy (name=TpLogger) initialisation."); + g_critical ("Error during TplLogStoreEmpathy (name=TpLogger) " + "initialisation."); else { /* manual registration, to set up priv->stores for @@ -187,6 +190,9 @@ tpl_log_manager_init (TplLogManager *self) /* internally referenced within register_logstore */ if (empathy != NULL) g_object_unref (empathy); + + + DEBUG ("Log Manager initialised"); } diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c index 14ce05f..e3893b3 100644 --- a/telepathy-logger/log-store-empathy.c +++ b/telepathy-logger/log-store-empathy.c @@ -437,8 +437,8 @@ _log_store_empathy_write_to_store (TplLogStore *self, if (file != NULL) fseek (file, -strlen (LOG_FOOTER), SEEK_END); } - g_fprintf (file, "%s", entry); + DEBUG ("%s: written: %s", filename, entry); fclose (file); g_free (filename); -- cgit v1.2.1 From 6a769d860f6a7cf5d16bc5acb130afd63bd9535a Mon Sep 17 00:00:00 2001 From: Danielle Madeley Date: Fri, 26 Feb 2010 14:35:39 +1100 Subject: observer: clean up referencing --- telepathy-logger/observer.c | 245 ++++++++++++++++++-------------------------- 1 file changed, 98 insertions(+), 147 deletions(-) diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index 6c5ff5d..aa7fa0f 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -88,22 +88,7 @@ static void got_tpl_channel_text_ready_cb (GObject *obj, GAsyncResult *result, gpointer user_data); static TplChannelFactory tpl_observer_get_channel_factory (TplObserver *self); static GHashTable *tpl_observer_get_channel_map (TplObserver *self); - -/* Get open channels API */ static void tpl_observer_get_open_channels (void); -static void tpl_observer_prepared_account_manager_cb (GObject *obj, - GAsyncResult *result, gpointer user_data); -static void tpl_observer_got_channel_list_cb (TpProxy *proxy, - const GValue *out_Value, const GError *error, gpointer user_data, - GObject *weak_object); -static void tpl_observer_get_open_channels_prepare_account_cb (GObject *proxy, - GAsyncResult *result, gpointer user_data); -static void tpl_observer_get_open_channels_prepared_connection (TpConnection *conn, - const GError *error, gpointer user_data); - - - -/* end of Get open channels API */ #define GET_PRIV(obj) TPL_GET_PRIV (obj, TplObserver) @@ -659,51 +644,78 @@ tpl_observer_set_channel_factory (TplObserver *self, priv->channel_factory = factory; } -/* Retrieving open channel */ -/* This part can be removed when the Channel Dispatcher will implement a - * proper API for - * org.freedesktop.Telepathy.Connection.Interface.Requests.Channels */ + static void -tpl_observer_get_open_channels (void) +tpl_observer_got_channel_list_cb (TpProxy *proxy, + const GValue *value, + const GError *error, + gpointer user_data, + GObject *weak_object) { - TpAccountManager *acc_man = tp_account_manager_dup (); - tp_account_manager_prepare_async (acc_man, NULL, - tpl_observer_prepared_account_manager_cb, NULL); -} + TpAccount *account = TP_ACCOUNT (user_data); + TpConnection *conn = TP_CONNECTION (proxy); + TplObserver *observer = tpl_observer_new (); + GPtrArray *channels; + g_return_if_fail (TP_IS_CONNECTION (conn)); + g_return_if_fail (TP_IS_ACCOUNT (account)); -static void -tpl_observer_prepared_account_manager_cb (GObject *obj, - GAsyncResult *result, - gpointer user_data) -{ - TpAccountManager *am = TP_ACCOUNT_MANAGER (obj); - GList *list, *l; - GError *error = NULL; + if (error != NULL) + { + DEBUG ("unable to retrieve channels for connection %s: %s", + tp_proxy_get_object_path (TP_PROXY (conn)), + error->message); + return; + } - if (!tp_account_manager_prepare_finish (TP_ACCOUNT_MANAGER (obj), result, - &error)) + if (!G_VALUE_HOLDS (value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST)) { - DEBUG ("Unable to prepare connection manager: %s", error->message); - g_object_unref (am); + g_critical ("channel list GValue does not hold " + "TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST"); return; } - /* accountspointed by the list are not referenced */ - list = tp_account_manager_get_valid_accounts (am); + channels = g_value_get_boxed (value); - for (l = list; l != NULL; l = g_list_next (l)) - { - TpAccount *acc = l->data; + /* call observe_channels with + * Dispatch_Operation = NULL, Requests_Satisfied = NULL, + * Observer_Info = NULL and DBusGMethodInvocation = NULL + * so that it will undertand that it's not been called by a Channel + * Dispatcher */ + tpl_observer_observe_channels (TP_SVC_CLIENT_OBSERVER (observer), + tp_proxy_get_object_path (TP_PROXY (account)), + tp_proxy_get_object_path (TP_PROXY (conn)), + channels, NULL, NULL, NULL, NULL); +} - g_assert (TP_IS_ACCOUNT (acc)); - /* ref here, unref in callbacks on error or at the end of the - * chain */ - tp_account_prepare_async (g_object_ref (acc), NULL, - tpl_observer_get_open_channels_prepare_account_cb, NULL); +static void +tpl_observer_get_open_channels_prepared_connection (TpConnection *conn, + const GError *error, + gpointer user_data) +{ + TpAccount *account = TP_ACCOUNT (user_data); + + g_return_if_fail (TP_IS_CONNECTION (conn)); + g_return_if_fail (TP_IS_ACCOUNT (account)); + + if (error != NULL) + { + DEBUG ("unable to prepare connection for open channel retrieval: %s", + error->message); + goto out; } - g_list_free (list); + + /* I do not pass the observer as a weak_object or I will leak some + * references to account and connection in the callback in case is destroyed + * and the call canceled */ + tp_cli_dbus_properties_call_get (conn, -1, + TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels", + tpl_observer_got_channel_list_cb, + g_object_ref (account), g_object_unref, NULL); + +out: + g_object_unref (account); } @@ -718,133 +730,72 @@ tpl_observer_get_open_channels_prepare_account_cb (GObject *proxy, g_return_if_fail (TP_IS_ACCOUNT (account)); - if (!tp_account_is_enabled (account)) - goto early_out; - if (!tp_account_prepare_finish (account, result, &error)) { DEBUG ("unable to prapare account: %s", error->message); - goto early_out; + g_error_free (error); } + if (!tp_account_is_enabled (account)) + return; + conn = tp_account_get_connection (account); - /* account's connection is offline */ + + /* check if account's connection is offline */ if (conn == NULL) - goto early_out; + return; /* ref here, unref in callbacks on error or at the end of the chain */ - tp_connection_call_when_ready (g_object_ref (conn), - tpl_observer_get_open_channels_prepared_connection, account); - - return; - -early_out: - if (error != NULL) - g_error_free (error); - if (account != NULL) - g_object_unref (account); + tp_connection_call_when_ready (conn, + tpl_observer_get_open_channels_prepared_connection, + g_object_ref (account)); } static void -tpl_observer_get_open_channels_prepared_connection (TpConnection *conn, - const GError *error, +tpl_observer_prepared_account_manager_cb (GObject *obj, + GAsyncResult *result, gpointer user_data) { - TpAccount *account = TP_ACCOUNT (user_data); + TpAccountManager *am = TP_ACCOUNT_MANAGER (obj); + GList *list, *l; + GError *error = NULL; - /* not use g_return_* or it will leak refs */ - if (!TP_IS_CONNECTION (conn)) - { - DEBUG ("conn is not TP_CONNECTION"); - goto err; - } - if (!TP_IS_ACCOUNT (account)) + if (!tp_account_manager_prepare_finish (TP_ACCOUNT_MANAGER (obj), result, + &error)) { - DEBUG ("account is not TP_ACCOUNT"); - goto err; + DEBUG ("Unable to prepare connection manager: %s", error->message); + return; } + /* accountspointed by the list are not referenced */ + list = tp_account_manager_get_valid_accounts (am); - if (error != NULL) + for (l = list; l != NULL; l = g_list_next (l)) { - DEBUG ("unable to prepare connection for open channel retrieval: %s", - error->message); - goto err; - } - - /* I do not pass the observer as a weak_object or I will leak some - * references to account and connection in the callback in case is destroyed - * and the call canceled */ - tp_cli_dbus_properties_call_get (conn, -1, - TP_IFACE_CONNECTION_INTERFACE_REQUESTS, "Channels", - tpl_observer_got_channel_list_cb, account, NULL, NULL); - return; - -err: - if (conn != NULL) - g_object_unref (conn); - if (account != NULL) - g_object_unref (account); -} - + TpAccount *account = l->data; -void tpl_observer_got_channel_list_cb (TpProxy *proxy, - const GValue *out_Value, - const GError *error, - gpointer user_data, - GObject *weak_object) -{ - TpAccount *account = TP_ACCOUNT (user_data); - TpConnection *conn = TP_CONNECTION (proxy); - TplObserver *observer = tpl_observer_new (); - GPtrArray *channels; + g_assert (TP_IS_ACCOUNT (account)); - /* not use g_return_* or it will leak refs */ - if (!TP_IS_CONNECTION (conn)) - { - DEBUG ("conn is not TP_CONNECTION"); - goto out; - } - if (!TP_IS_ACCOUNT (account)) - { - DEBUG ("account is not TP_ACCOUNT"); - goto out; + tp_account_prepare_async (account, NULL, + tpl_observer_get_open_channels_prepare_account_cb, NULL); } - if (error != NULL) - { - DEBUG ("unable to retrieve channels for connection %s: %s", - tp_proxy_get_object_path (TP_PROXY (conn)), - error->message); - goto out; - } + g_list_free (list); +} - /* not use g_return_* or it will leak refs */ - if (!G_VALUE_HOLDS (out_Value, TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST)) - { - g_critical ("channel list GValue does not hold " - "TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST"); - goto out; - } - channels = g_value_get_boxed (out_Value); +/* Retrieving open channel */ +/* This part can be removed when the Channel Dispatcher will implement a + * proper API for + * org.freedesktop.Telepathy.Connection.Interface.Requests.Channels */ +static void +tpl_observer_get_open_channels (void) +{ + TpAccountManager *am = tp_account_manager_dup (); - /* call observe_channels with - * Dispatch_Operation = NULL, Requests_Satisfied = NULL, - * Observer_Info = NULL and DBusGMethodInvocation = NULL - * so that it will undertand that it's not been called by a Channel - * Dispatcher */ - tpl_observer_observe_channels (TP_SVC_CLIENT_OBSERVER (observer), - tp_proxy_get_object_path (TP_PROXY (account)), - tp_proxy_get_object_path (TP_PROXY (conn)), - channels, NULL, NULL, NULL, NULL); + tp_account_manager_prepare_async (am, NULL, + tpl_observer_prepared_account_manager_cb, NULL); -out: - if (account != NULL) - g_object_unref (account); - if (conn != NULL) - g_object_unref (conn); - if (observer != NULL) - g_object_unref (observer); + g_object_unref (am); } -- cgit v1.2.1