* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <telepathy-glib/connection-manager.h>
-#include <telepathy-glib/util.h>
-
+#include "config.h"
#include "empathy-connection-managers.h"
+
#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
static GObject *managers = NULL;
TpDBusDaemon *dbus;
};
-#define EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
- EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv))
-
static void
empathy_connection_managers_init (EmpathyConnectionManagers *obj)
{
EmpathyConnectionManagersPriv *priv =
- EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (obj);
+ G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
+ EMPATHY_TYPE_CONNECTION_MANAGERS, EmpathyConnectionManagersPriv);
+
+ obj->priv = priv;
priv->dbus = tp_dbus_daemon_dup (NULL);
g_assert (priv->dbus != NULL);
}
static void empathy_connection_managers_dispose (GObject *object);
-static void empathy_connection_managers_finalize (GObject *object);
static GObject *
empathy_connection_managers_constructor (GType type,
GValue *value,
GParamSpec *pspec)
{
- EmpathyConnectionManagers *managers = EMPATHY_CONNECTION_MANAGERS (object);
- EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
+ EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
switch (prop_id)
{
object_class->constructor = empathy_connection_managers_constructor;
object_class->dispose = empathy_connection_managers_dispose;
- object_class->finalize = empathy_connection_managers_finalize;
object_class->get_property = empathy_connection_managers_get_property;
g_object_class_install_property (object_class, PROP_READY,
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
+ g_cclosure_marshal_generic,
G_TYPE_NONE, 0);
}
G_OBJECT_CLASS (empathy_connection_managers_parent_class)->dispose (object);
}
-void
-empathy_connection_managers_finalize (GObject *object)
-{
-#if 0
- EmpathyConnectionManagers *self = EMPATHY_CONNECTION_MANAGERS (object);
- EmpathyConnectionManagersPriv *priv =
- EMPATHY_CONNECTION_MANAGERS_GET_PRIVATE (self);
-
- /* free any data held directly by the object here */
-
- G_OBJECT_CLASS (empathy_connection_managers_parent_class)->finalize (object);
-#endif
-}
-
EmpathyConnectionManagers *
empathy_connection_managers_dup_singleton (void)
{
}
gboolean
-empathy_connection_managers_is_ready (EmpathyConnectionManagers *managers)
+empathy_connection_managers_is_ready (EmpathyConnectionManagers *self)
{
- EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
return priv->ready;
}
static void
-empathy_connection_managers_listed_cb (TpConnectionManager * const *cms,
- gsize n_cms,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
+empathy_connection_managers_listed_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- EmpathyConnectionManagers *self =
- EMPATHY_CONNECTION_MANAGERS (weak_object);
- EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
- TpConnectionManager * const *iter;
+ TpWeakRef *wr = user_data;
+ GError *error = NULL;
+ EmpathyConnectionManagers *self = tp_weak_ref_dup_object (wr);
+ GList *cms, *l;
+ EmpathyConnectionManagersPriv *priv;
+
+ if (self == NULL)
+ {
+ tp_weak_ref_destroy (wr);
+ return;
+ }
+
+ priv = GET_PRIV (self);
empathy_connection_managers_free_cm_list (self);
+ cms = tp_list_connection_managers_finish (result, &error);
if (error != NULL)
{
DEBUG ("Failed to get connection managers: %s", error->message);
+ g_error_free (error);
goto out;
}
- for (iter = cms ; iter != NULL && *iter != NULL; iter++)
+ for (l = cms ; l != NULL; l = g_list_next (l))
{
+ TpConnectionManager *cm = l->data;
+
/* only list cms that didn't hit errors */
- if (tp_connection_manager_is_ready(*iter))
- priv->cms = g_list_prepend (priv->cms, g_object_ref (*iter));
+ if (tp_proxy_is_prepared (cm, TP_CONNECTION_MANAGER_FEATURE_CORE))
+ priv->cms = g_list_prepend (priv->cms, g_object_ref (cm));
}
out:
if (!priv->ready)
{
priv->ready = TRUE;
- g_object_notify (weak_object, "ready");
+ g_object_notify (G_OBJECT (self), "ready");
}
- g_signal_emit (weak_object, signals[UPDATED], 0);
+
+ g_signal_emit (self, signals[UPDATED], 0);
+ g_object_unref (self);
+ tp_weak_ref_destroy (wr);
}
void
-empathy_connection_managers_update (EmpathyConnectionManagers *managers)
+empathy_connection_managers_update (EmpathyConnectionManagers *self)
{
- EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
- tp_list_connection_managers (priv->dbus,
+ tp_list_connection_managers_async (priv->dbus,
empathy_connection_managers_listed_cb,
- NULL, NULL, G_OBJECT (managers));
+ tp_weak_ref_new (self, NULL, NULL));
}
GList *
-empathy_connection_managers_get_cms (EmpathyConnectionManagers *managers)
+empathy_connection_managers_get_cms (EmpathyConnectionManagers *self)
{
- EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
return priv->cms;
}
TpConnectionManager *
-empathy_connection_managers_get_cm (EmpathyConnectionManagers *managers,
+empathy_connection_managers_get_cm (EmpathyConnectionManagers *self,
const gchar *cm)
{
- EmpathyConnectionManagersPriv *priv = GET_PRIV (managers);
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
GList *l;
for (l = priv->cms ; l != NULL; l = g_list_next (l))
{
TpConnectionManager *c = TP_CONNECTION_MANAGER (l->data);
- if (!tp_strdiff (c->name, cm))
+ if (!tp_strdiff (tp_connection_manager_get_name (c), cm))
return c;
}
return NULL;
}
+
+guint
+empathy_connection_managers_get_cms_num (EmpathyConnectionManagers *self)
+{
+ EmpathyConnectionManagersPriv *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_CONNECTION_MANAGERS (self), 0);
+
+ priv = GET_PRIV (self);
+
+ return g_list_length (priv->cms);
+}
+
+static void
+notify_ready_cb (EmpathyConnectionManagers *self,
+ GParamSpec *spec,
+ GSimpleAsyncResult *result)
+{
+ g_simple_async_result_complete (result);
+ g_object_unref (result);
+}
+
+void
+empathy_connection_managers_prepare_async (
+ EmpathyConnectionManagers *self,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ EmpathyConnectionManagersPriv *priv = GET_PRIV (self);
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (managers),
+ callback, user_data, empathy_connection_managers_prepare_finish);
+
+ if (priv->ready)
+ {
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+ return;
+ }
+
+ g_signal_connect (self, "notify::ready", G_CALLBACK (notify_ready_cb),
+ result);
+}
+
+gboolean
+empathy_connection_managers_prepare_finish (
+ EmpathyConnectionManagers *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (self), empathy_connection_managers_prepare_finish), FALSE);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ return TRUE;
+}