]> git.0d.be Git - empathy.git/commitdiff
Add a function to request a channel from a string handle
authorXavier Claessens <xclaesse@src.gnome.org>
Thu, 7 Aug 2008 14:40:46 +0000 (14:40 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Thu, 7 Aug 2008 14:40:46 +0000 (14:40 +0000)
svn path=/trunk/; revision=1310

libempathy/empathy-utils.c
libempathy/empathy-utils.h

index 6c28a116e38206bb598f27cd78fb02ed3d440c32..a815ea7a1a197b61c4a682a4a21a877084d718b5 100644 (file)
@@ -40,7 +40,6 @@
 #include "empathy-utils.h"
 #include "empathy-contact-factory.h"
 #include "empathy-contact-manager.h"
-#include "empathy-tp-group.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include "empathy-debug.h"
@@ -657,3 +656,121 @@ empathy_proxy_equal (gconstpointer a,
               g_str_equal (proxy_a->bus_name, proxy_b->bus_name);
 }
 
+typedef struct {
+       gint timeout_ms;
+       gchar *channel_type;
+       guint handle_type;
+       empathy_connection_callback_for_request_channel callback;
+       gpointer user_data;
+       GDestroyNotify destroy;
+       TpHandle handle;
+       gboolean suppress_handler;
+       guint ref_count;
+} ConnectionRequestChannelData;
+
+static void
+connection_request_channel_data_unref (gpointer user_data)
+{
+       ConnectionRequestChannelData *data = (ConnectionRequestChannelData*) user_data;
+
+       if (--data->ref_count == 0) {
+               g_free (data->channel_type);
+               if (data->destroy) {
+                       data->destroy (data->user_data);
+               }
+               g_slice_free (ConnectionRequestChannelData, data);
+       }
+}
+
+static void
+connection_request_channel_cb (TpConnection *connection,
+                              const gchar *object_path,
+                              const GError *error,
+                              gpointer user_data,
+                              GObject *weak_object)
+{
+       ConnectionRequestChannelData *data = (ConnectionRequestChannelData*) user_data;
+       TpChannel *channel;
+
+       if (!data->callback) {
+               return;
+       }
+
+       if (error) {
+               data->callback (connection, NULL, error, data->user_data, weak_object);
+               return;
+       }
+
+       channel = tp_channel_new (connection, object_path,
+                                 data->channel_type,
+                                 data->handle_type,
+                                 data->handle, NULL);
+
+       data->callback (connection, channel, NULL, data->user_data, weak_object);
+       g_object_unref (channel);
+}
+
+static void
+connection_request_handles_cb (TpConnection *connection,
+                              const GArray *handles,
+                              const GError *error,
+                              gpointer user_data,
+                              GObject *weak_object)
+{
+       ConnectionRequestChannelData *data = (ConnectionRequestChannelData*) user_data;
+
+       if (error) {
+               if (data->callback) {
+                       data->callback (connection, NULL, error, data->user_data, weak_object);
+               }
+               return;
+       }
+
+       data->handle = g_array_index (handles, guint, 0);
+       data->ref_count++;
+       tp_cli_connection_call_request_channel (connection, data->timeout_ms,
+                                               data->channel_type,
+                                               data->handle_type,
+                                               data->handle,
+                                               data->suppress_handler,
+                                               connection_request_channel_cb,
+                                               data,
+                                               (GDestroyNotify) connection_request_channel_data_unref,
+                                               weak_object);
+}
+
+void
+empathy_connection_request_channel (TpConnection *connection,
+                                   gint timeout_ms,
+                                   const gchar *channel_type,
+                                   guint handle_type,
+                                   const gchar *name,
+                                   gboolean suppress_handler,
+                                   empathy_connection_callback_for_request_channel callback,
+                                   gpointer user_data,
+                                   GDestroyNotify destroy,
+                                   GObject *weak_object)
+{
+       const gchar *names[] = {name, NULL};
+       ConnectionRequestChannelData *data;
+
+       data = g_slice_new (ConnectionRequestChannelData);
+       data->timeout_ms = timeout_ms;
+       data->channel_type = g_strdup (channel_type);
+       data->handle_type = handle_type;
+       data->callback = callback;
+       data->user_data = user_data;
+       data->destroy = destroy;
+       data->handle = 0;
+       data->suppress_handler = suppress_handler;
+       data->ref_count = 1;
+       tp_cli_connection_call_request_handles (connection,
+                                               timeout_ms,
+                                               handle_type,
+                                               names,
+                                               connection_request_handles_cb,
+                                               data,
+                                               (GDestroyNotify) connection_request_channel_data_unref,
+                                               weak_object);
+}
+
index 92ba44a946253746912b9769f45aa8d8876c51b8..a320c6246325c646bf1dd9ff335a92968b456915 100644 (file)
@@ -107,7 +107,21 @@ gboolean     empathy_proxy_equal                    (gconstpointer    a,
                                                     gconstpointer    b);
 guint        empathy_proxy_hash                     (gconstpointer    key);
 
-
+typedef void (*empathy_connection_callback_for_request_channel) (TpConnection *connection,
+                                                                TpChannel *channel,
+                                                                const GError *error,
+                                                                gpointer user_data,
+                                                                GObject *weak_object);
+void empathy_connection_request_channel (TpConnection *proxy,
+                                        gint timeout_ms,
+                                        const gchar *channel_type,
+                                        guint handle_type,
+                                        const gchar *name,
+                                        gboolean suppress_handler,
+                                        empathy_connection_callback_for_request_channel callback,
+                                        gpointer user_data,
+                                        GDestroyNotify destroy,
+                                        GObject *weak_object);
 
 G_END_DECLS