1 /* * Copyright (C) 2007-2009 Collabora Ltd.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 * Authors: Xavier Claessens <xclaesse@gmail.com>
18 * Sjoerd Simons <sjoerd.simons@collabora.co.uk>
19 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
26 #include <glib/gi18n-lib.h>
28 #include <telepathy-glib/enums.h>
29 #include <telepathy-glib/connection.h>
30 #include <telepathy-glib/util.h>
31 #include <telepathy-glib/dbus.h>
32 #include <telepathy-glib/proxy-subclass.h>
33 #include <telepathy-glib/gtypes.h>
35 #include <libmissioncontrol/mission-control.h>
37 #include <extensions/extensions.h>
39 #include "empathy-dispatcher.h"
40 #include "empathy-utils.h"
41 #include "empathy-tube-handler.h"
42 #include "empathy-account-manager.h"
43 #include "empathy-tp-contact-factory.h"
44 #include "empathy-chatroom-manager.h"
45 #include "empathy-utils.h"
47 #define DEBUG_FLAG EMPATHY_DEBUG_DISPATCHER
48 #include <libempathy/empathy-debug.h>
50 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDispatcher)
53 EmpathyAccountManager *account_manager;
55 /* connection to connection data mapping */
56 GHashTable *connections;
57 GHashTable *outstanding_classes_requests;
61 /* channels which the dispatcher is listening "invalidated" */
64 GHashTable *request_channel_class_async_ids;
65 } EmpathyDispatcherPriv;
67 G_DEFINE_TYPE (EmpathyDispatcher, empathy_dispatcher, G_TYPE_OBJECT);
77 static guint signals[LAST_SIGNAL];
78 static EmpathyDispatcher *dispatcher = NULL;
80 static GList * empathy_dispatcher_find_channel_classes
81 (EmpathyDispatcher *dispatcher, TpConnection *connection,
82 const gchar *channel_type, guint handle_type, GArray *fixed_properties);
87 EmpathyDispatcher *dispatcher;
88 EmpathyDispatchOperation *operation;
89 TpConnection *connection;
93 EmpathyContact *contact;
95 /* Properties to pass to the channel when requesting it */
97 EmpathyDispatcherRequestCb *cb;
99 gpointer *request_data;
100 } DispatcherRequestData;
105 /* Channel type specific wrapper object */
106 GObject *channel_wrapper;
111 /* ObjectPath => DispatchData.. */
112 GHashTable *dispatched_channels;
113 /* ObjectPath -> EmpathyDispatchOperations */
114 GHashTable *dispatching_channels;
116 /* ObjectPath -> EmpathyDispatchOperations
118 * This holds channels which were announced with NewChannel while we have an
119 * outstanding channel request for a channel of this type. On the Requests
120 * interface, CreateChannel and EnsureChannel are guaranteed by the spec to
121 * return before NewChannels is emitted, but there was no guarantee of the
122 * ordering of RequestChannel vs. NewChannel. So if necessary, channels are
123 * held in limbo here until we know whether they were requested.
125 GHashTable *outstanding_channels;
126 /* List of DispatcherRequestData */
127 GList *outstanding_requests;
128 /* List of requestable channel classes */
129 GPtrArray *requestable_channels;
134 EmpathyDispatcher *dispatcher;
135 TpConnection *connection;
139 EmpathyDispatcherFindChannelClassCb *callback;
141 } FindChannelRequest;
143 static DispatchData *
144 new_dispatch_data (TpChannel *channel,
145 GObject *channel_wrapper)
147 DispatchData *d = g_slice_new0 (DispatchData);
148 d->channel = g_object_ref (channel);
149 if (channel_wrapper != NULL)
150 d->channel_wrapper = g_object_ref (channel_wrapper);
156 free_dispatch_data (DispatchData *data)
158 g_object_unref (data->channel);
159 if (data->channel_wrapper != NULL)
160 g_object_unref (data->channel_wrapper);
162 g_slice_free (DispatchData, data);
165 static DispatcherRequestData *
166 new_dispatcher_request_data (EmpathyDispatcher *dispatcher,
167 TpConnection *connection,
168 const gchar *channel_type,
172 EmpathyContact *contact,
173 EmpathyDispatcherRequestCb *cb,
176 DispatcherRequestData *result = g_slice_new0 (DispatcherRequestData);
178 result->dispatcher = g_object_ref (dispatcher);
179 result->connection = connection;
181 result->channel_type = g_strdup (channel_type);
182 result->handle_type = handle_type;
183 result->handle = handle;
184 result->request = request;
187 result->contact = g_object_ref (contact);
190 result->user_data = user_data;
196 free_dispatcher_request_data (DispatcherRequestData *r)
198 g_free (r->channel_type);
200 if (r->dispatcher != NULL)
201 g_object_unref (r->dispatcher);
203 if (r->contact != NULL)
204 g_object_unref (r->contact);
206 if (r->request != NULL)
207 g_hash_table_unref (r->request);
209 g_slice_free (DispatcherRequestData, r);
212 static ConnectionData *
213 new_connection_data (void)
215 ConnectionData *cd = g_slice_new0 (ConnectionData);
217 cd->dispatched_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
218 g_free, (GDestroyNotify) free_dispatch_data);
220 cd->dispatching_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
221 g_free, g_object_unref);
223 cd->outstanding_channels = g_hash_table_new_full (g_str_hash, g_str_equal,
230 free_connection_data (ConnectionData *cd)
234 g_hash_table_destroy (cd->dispatched_channels);
235 g_hash_table_destroy (cd->dispatching_channels);
238 for (l = cd->outstanding_requests ; l != NULL; l = g_list_delete_link (l,l))
240 free_dispatcher_request_data (l->data);
243 if (cd->requestable_channels != NULL)
245 for (i = 0 ; i < cd->requestable_channels->len ; i++)
247 g_ptr_array_index (cd->requestable_channels, i));
248 g_ptr_array_free (cd->requestable_channels, TRUE);
253 free_find_channel_request (FindChannelRequest *r)
258 g_object_unref (r->dispatcher);
259 g_free (r->channel_type);
261 if (r->properties != NULL)
263 for (idx = 0; idx < r->properties->len ; idx++)
265 str = g_array_index (r->properties, char *, idx);
269 g_array_free (r->properties, TRUE);
272 g_slice_free (FindChannelRequest, r);
276 dispatcher_connection_invalidated_cb (TpConnection *connection,
280 EmpathyDispatcher *dispatcher)
282 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
284 DEBUG ("Error: %s", message);
285 g_hash_table_remove (priv->connections, connection);
289 dispatcher_operation_can_start (EmpathyDispatcher *self,
290 EmpathyDispatchOperation *operation,
294 const gchar *channel_type =
295 empathy_dispatch_operation_get_channel_type (operation);
297 for (l = cd->outstanding_requests; l != NULL; l = g_list_next (l))
299 DispatcherRequestData *d = (DispatcherRequestData *) l->data;
301 if (d->operation == NULL && !tp_strdiff (d->channel_type, channel_type))
311 dispatch_operation_flush_requests (EmpathyDispatcher *dispatcher,
312 EmpathyDispatchOperation *operation,
318 l = cd->outstanding_requests;
321 DispatcherRequestData *d = (DispatcherRequestData *) l->data;
326 if (d->operation == operation)
331 d->cb (NULL, error, d->user_data);
333 d->cb (operation, NULL, d->user_data);
336 cd->outstanding_requests = g_list_delete_link
337 (cd->outstanding_requests, lt);
339 free_dispatcher_request_data (d);
345 dispatcher_channel_invalidated_cb (TpProxy *proxy,
349 EmpathyDispatcher *dispatcher)
351 /* Channel went away... */
352 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
353 TpConnection *connection;
354 EmpathyDispatchOperation *operation;
356 const gchar *object_path;
358 connection = tp_channel_borrow_connection (TP_CHANNEL (proxy));
360 cd = g_hash_table_lookup (priv->connections, connection);
361 /* Connection itself invalidated? */
365 object_path = tp_proxy_get_object_path (proxy);
367 DEBUG ("Channel %s invalidated", object_path);
369 g_hash_table_remove (cd->dispatched_channels, object_path);
370 g_hash_table_remove (cd->dispatching_channels, object_path);
372 priv->channels = g_list_remove (priv->channels, proxy);
374 operation = g_hash_table_lookup (cd->outstanding_channels, object_path);
375 if (operation != NULL)
377 GError error = { domain, code, message };
378 dispatch_operation_flush_requests (dispatcher, operation, &error, cd);
379 g_hash_table_remove (cd->outstanding_channels, object_path);
380 g_object_unref (operation);
385 dispatch_operation_approved_cb (EmpathyDispatchOperation *operation,
386 EmpathyDispatcher *dispatcher)
388 g_assert (empathy_dispatch_operation_is_incoming (operation));
389 DEBUG ("Send of for dispatching: %s",
390 empathy_dispatch_operation_get_object_path (operation));
391 g_signal_emit (dispatcher, signals[DISPATCH], 0, operation);
395 dispatch_operation_claimed_cb (EmpathyDispatchOperation *operation,
396 EmpathyDispatcher *dispatcher)
398 /* Our job is done, remove the dispatch operation and mark the channel as
400 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
401 TpConnection *connection;
403 const gchar *object_path;
405 connection = empathy_dispatch_operation_get_tp_connection (operation);
406 cd = g_hash_table_lookup (priv->connections, connection);
407 g_assert (cd != NULL);
409 object_path = empathy_dispatch_operation_get_object_path (operation);
411 if (g_hash_table_lookup (cd->dispatched_channels, object_path) == NULL)
414 d = new_dispatch_data (
415 empathy_dispatch_operation_get_channel (operation),
416 empathy_dispatch_operation_get_channel_wrapper (operation));
417 g_hash_table_insert (cd->dispatched_channels,
418 g_strdup (object_path), d);
420 g_hash_table_remove (cd->dispatching_channels, object_path);
422 DEBUG ("Channel claimed: %s", object_path);
426 dispatch_operation_ready_cb (EmpathyDispatchOperation *operation,
427 EmpathyDispatcher *dispatcher)
429 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
430 TpConnection *connection;
432 EmpathyDispatchOperationState status;
434 g_signal_connect (operation, "approved",
435 G_CALLBACK (dispatch_operation_approved_cb), dispatcher);
437 g_signal_connect (operation, "claimed",
438 G_CALLBACK (dispatch_operation_claimed_cb), dispatcher);
440 /* Signal the observers */
441 DEBUG ("Send to observers: %s",
442 empathy_dispatch_operation_get_object_path (operation));
443 g_signal_emit (dispatcher, signals[OBSERVE], 0, operation);
445 empathy_dispatch_operation_start (operation);
447 /* Signal potential requestors */
448 connection = empathy_dispatch_operation_get_tp_connection (operation);
449 cd = g_hash_table_lookup (priv->connections, connection);
450 g_assert (cd != NULL);
452 g_object_ref (operation);
453 g_object_ref (dispatcher);
455 dispatch_operation_flush_requests (dispatcher, operation, NULL, cd);
456 status = empathy_dispatch_operation_get_status (operation);
457 g_object_unref (operation);
459 if (status == EMPATHY_DISPATCHER_OPERATION_STATE_CLAIMED)
462 if (status == EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING)
464 DEBUG ("Send to approvers: %s",
465 empathy_dispatch_operation_get_object_path (operation));
466 g_signal_emit (dispatcher, signals[APPROVE], 0, operation);
470 g_assert (status == EMPATHY_DISPATCHER_OPERATION_STATE_DISPATCHING);
471 DEBUG ("Send of for dispatching: %s",
472 empathy_dispatch_operation_get_object_path (operation));
473 g_signal_emit (dispatcher, signals[DISPATCH], 0, operation);
476 g_object_unref (dispatcher);
480 dispatcher_start_dispatching (EmpathyDispatcher *self,
481 EmpathyDispatchOperation *operation,
484 const gchar *object_path =
485 empathy_dispatch_operation_get_object_path (operation);
487 DEBUG ("Dispatching process started for %s", object_path);
489 if (g_hash_table_lookup (cd->dispatching_channels, object_path) == NULL)
491 g_assert (g_hash_table_lookup (cd->outstanding_channels,
492 object_path) == NULL);
494 g_hash_table_insert (cd->dispatching_channels,
495 g_strdup (object_path), operation);
497 switch (empathy_dispatch_operation_get_status (operation))
499 case EMPATHY_DISPATCHER_OPERATION_STATE_PREPARING:
500 g_signal_connect (operation, "ready",
501 G_CALLBACK (dispatch_operation_ready_cb), dispatcher);
503 case EMPATHY_DISPATCHER_OPERATION_STATE_PENDING:
504 dispatch_operation_ready_cb (operation, dispatcher);
507 g_assert_not_reached ();
511 else if (empathy_dispatch_operation_get_status (operation) >=
512 EMPATHY_DISPATCHER_OPERATION_STATE_PENDING)
514 /* Already dispatching and the operation is pending, thus the observers
515 * have seen it (if applicable), so we can flush the request right away.
517 dispatch_operation_flush_requests (self, operation, NULL, cd);
522 dispatcher_flush_outstanding_operations (EmpathyDispatcher *self,
528 g_hash_table_iter_init (&iter, cd->outstanding_channels);
529 while (g_hash_table_iter_next (&iter, NULL, &value))
531 EmpathyDispatchOperation *operation = EMPATHY_DISPATCH_OPERATION (value);
533 if (dispatcher_operation_can_start (self, operation, cd))
535 g_hash_table_iter_remove (&iter);
536 dispatcher_start_dispatching (dispatcher, operation, cd);
542 dispatcher_connection_new_channel (EmpathyDispatcher *dispatcher,
543 TpConnection *connection,
544 const gchar *object_path,
545 const gchar *channel_type,
548 GHashTable *properties,
551 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
554 EmpathyDispatchOperation *operation;
556 /* Channel types we never want to dispatch because they're either deprecated
557 * or can't sensibly be dispatch (e.g. channels that should always be
559 const char *blacklist[] = {
560 TP_IFACE_CHANNEL_TYPE_CONTACT_LIST,
561 TP_IFACE_CHANNEL_TYPE_TUBES,
562 TP_IFACE_CHANNEL_TYPE_ROOM_LIST,
566 cd = g_hash_table_lookup (priv->connections, connection);
568 /* Don't bother with channels we have already dispatched or are dispatching
569 * currently. This can happen when NewChannel(s) is fired after
570 * RequestChannel/CreateChannel/EnsureChannel */
571 if (g_hash_table_lookup (cd->dispatched_channels, object_path) != NULL)
574 if (g_hash_table_lookup (cd->dispatching_channels, object_path) != NULL)
577 /* Should never occur, but just in case a CM fires spurious NewChannel(s)
579 if (g_hash_table_lookup (cd->outstanding_channels, object_path) != NULL)
582 /* Only pick up non-requested text and file channels. For all other it
583 * doesn't make sense to handle it if we didn't request it. The same goes
584 * for channels we discovered by the Channels property or ListChannels */
585 if (!incoming && tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)
586 && tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
588 DEBUG ("Ignoring incoming channel of type %s on %s",
589 channel_type, object_path);
593 for (i = 0 ; blacklist[i] != NULL; i++)
595 if (!tp_strdiff (channel_type, blacklist[i]))
597 DEBUG ("Ignoring blacklisted channel type %s on %s",
598 channel_type, object_path);
603 DEBUG ("New channel of type %s on %s", channel_type, object_path);
605 if (properties == NULL)
606 channel = tp_channel_new (connection, object_path, channel_type,
607 handle_type, handle, NULL);
609 channel = tp_channel_new_from_properties (connection, object_path,
612 g_signal_connect (channel, "invalidated",
613 G_CALLBACK (dispatcher_channel_invalidated_cb),
616 priv->channels = g_list_prepend (priv->channels, channel);
618 operation = empathy_dispatch_operation_new (connection, channel, NULL,
621 g_object_unref (channel);
625 /* Request could either be by us or by a remote party. If there are no
626 * outstanding requests for this channel type we can assume it's remote.
627 * Otherwise we wait untill they are all satisfied */
628 if (dispatcher_operation_can_start (dispatcher, operation, cd))
629 dispatcher_start_dispatching (dispatcher, operation, cd);
631 g_hash_table_insert (cd->outstanding_channels,
632 g_strdup (object_path), operation);
636 dispatcher_start_dispatching (dispatcher, operation, cd);
641 dispatcher_connection_new_channel_cb (TpConnection *connection,
642 const gchar *object_path,
643 const gchar *channel_type,
646 gboolean suppress_handler,
650 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
652 /* Empathy heavily abuses surpress handler (don't try this at home), if
653 * surpress handler is true then it is an outgoing channel, which is
654 * requested either by us or some other party (like the megaphone applet).
655 * Otherwise it's an incoming channel */
656 dispatcher_connection_new_channel (dispatcher, connection,
657 object_path, channel_type, handle_type, handle, NULL, !suppress_handler);
661 dispatcher_connection_new_channel_with_properties (EmpathyDispatcher *dispatcher,
662 TpConnection *connection,
663 const gchar *object_path,
664 GHashTable *properties)
666 const gchar *channel_type;
673 channel_type = tp_asv_get_string (properties,
674 TP_IFACE_CHANNEL ".ChannelType");
675 if (channel_type == NULL)
677 g_message ("%s had an invalid ChannelType property", object_path);
681 handle_type = tp_asv_get_uint32 (properties,
682 TP_IFACE_CHANNEL ".TargetHandleType", &valid);
685 g_message ("%s had an invalid TargetHandleType property", object_path);
689 handle = tp_asv_get_uint32 (properties,
690 TP_IFACE_CHANNEL ".TargetHandle", &valid);
693 g_message ("%s had an invalid TargetHandle property", object_path);
697 /* We assume there is no channel dispather, so we're the only one dispatching
698 * it. Which means that a requested channel it is outgoing one */
699 requested = tp_asv_get_boolean (properties,
700 TP_IFACE_CHANNEL ".Requested", &valid);
703 g_message ("%s had an invalid Requested property", object_path);
707 dispatcher_connection_new_channel (dispatcher, connection,
708 object_path, channel_type, handle_type, handle, properties, !requested);
712 dispatcher_connection_new_channels_cb (TpConnection *connection,
713 const GPtrArray *channels,
717 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
720 for (i = 0; i < channels->len ; i++)
722 GValueArray *arr = g_ptr_array_index (channels, i);
723 const gchar *object_path;
724 GHashTable *properties;
726 object_path = g_value_get_boxed (g_value_array_get_nth (arr, 0));
727 properties = g_value_get_boxed (g_value_array_get_nth (arr, 1));
729 dispatcher_connection_new_channel_with_properties (dispatcher,
730 connection, object_path, properties);
735 dispatcher_connection_got_all (TpProxy *proxy,
736 GHashTable *properties,
741 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
742 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
744 GPtrArray *requestable_channels;
747 DEBUG ("Error: %s", error->message);
751 channels = tp_asv_get_boxed (properties, "Channels",
752 TP_ARRAY_TYPE_CHANNEL_DETAILS_LIST);
754 if (channels == NULL)
755 DEBUG ("No Channels property !?! on connection");
757 dispatcher_connection_new_channels_cb (TP_CONNECTION (proxy),
758 channels, NULL, object);
760 requestable_channels = tp_asv_get_boxed (properties,
761 "RequestableChannelClasses", TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST);
763 if (requestable_channels == NULL)
764 DEBUG ("No RequestableChannelClasses property !?! on connection");
769 FindChannelRequest *request;
772 cd = g_hash_table_lookup (priv->connections, proxy);
773 g_assert (cd != NULL);
775 cd->requestable_channels = g_boxed_copy (
776 TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, requestable_channels);
778 requests = g_hash_table_lookup (priv->outstanding_classes_requests,
781 for (l = requests; l != NULL; l = l->next)
785 retval = empathy_dispatcher_find_channel_classes (dispatcher,
786 TP_CONNECTION (proxy), request->channel_type,
787 request->handle_type, request->properties);
788 request->callback (retval, request->user_data);
790 free_find_channel_request (request);
791 g_list_free (retval);
794 g_list_free (requests);
796 g_hash_table_remove (priv->outstanding_classes_requests, proxy);
801 dispatcher_connection_list_channels_cb (TpConnection *connection,
802 const GPtrArray *channels,
811 DEBUG ("Error: %s", error->message);
815 for (i = 0; i < channels->len; i++)
819 values = g_ptr_array_index (channels, i);
820 /* We don't have any extra info, so assume already existing channels are
822 dispatcher_connection_new_channel (EMPATHY_DISPATCHER (dispatcher),
824 g_value_get_boxed (g_value_array_get_nth (values, 0)),
825 g_value_get_string (g_value_array_get_nth (values, 1)),
826 g_value_get_uint (g_value_array_get_nth (values, 2)),
827 g_value_get_uint (g_value_array_get_nth (values, 3)),
833 dispatcher_connection_advertise_capabilities_cb (TpConnection *connection,
834 const GPtrArray *capabilities,
840 DEBUG ("Error: %s", error->message);
844 dispatcher_new_connection_cb (EmpathyAccountManager *manager,
845 TpConnection *connection,
846 EmpathyDispatcher *dispatcher)
848 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
849 GPtrArray *capabilities;
852 const gchar *remove = NULL;
854 if (g_hash_table_lookup (priv->connections, connection) != NULL)
857 g_hash_table_insert (priv->connections, g_object_ref (connection),
858 new_connection_data ());
860 g_signal_connect (connection, "invalidated",
861 G_CALLBACK (dispatcher_connection_invalidated_cb), dispatcher);
863 if (tp_proxy_has_interface_by_id (TP_PROXY (connection),
864 TP_IFACE_QUARK_CONNECTION_INTERFACE_REQUESTS))
866 tp_cli_connection_interface_requests_connect_to_new_channels (connection,
867 dispatcher_connection_new_channels_cb,
868 NULL, NULL, G_OBJECT (dispatcher), NULL);
870 tp_cli_dbus_properties_call_get_all (connection, -1,
871 TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
872 dispatcher_connection_got_all,
873 NULL, NULL, G_OBJECT (dispatcher));
877 tp_cli_connection_connect_to_new_channel (connection,
878 dispatcher_connection_new_channel_cb,
879 NULL, NULL, G_OBJECT (dispatcher), NULL);
881 tp_cli_connection_call_list_channels (connection, -1,
882 dispatcher_connection_list_channels_cb, NULL, NULL,
883 G_OBJECT (dispatcher));
887 /* Advertise VoIP capabilities */
888 capabilities = g_ptr_array_sized_new (1);
889 cap_type = dbus_g_type_get_struct ("GValueArray", G_TYPE_STRING,
890 G_TYPE_UINT, G_TYPE_INVALID);
891 g_value_init (&cap, cap_type);
892 g_value_take_boxed (&cap, dbus_g_type_specialized_construct (cap_type));
893 dbus_g_type_struct_set (&cap,
894 0, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
895 1, TP_CHANNEL_MEDIA_CAPABILITY_AUDIO |
896 TP_CHANNEL_MEDIA_CAPABILITY_VIDEO |
897 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_STUN |
898 TP_CHANNEL_MEDIA_CAPABILITY_NAT_TRAVERSAL_GTALK_P2P, G_MAXUINT);
899 g_ptr_array_add (capabilities, g_value_get_boxed (&cap));
901 tp_cli_connection_interface_capabilities_call_advertise_capabilities (
902 connection, -1, capabilities, &remove,
903 dispatcher_connection_advertise_capabilities_cb,
904 NULL, NULL, G_OBJECT (dispatcher));
906 g_value_unset (&cap);
907 g_ptr_array_free (capabilities, TRUE);
911 remove_idle_handlers (gpointer key,
917 source_id = GPOINTER_TO_UINT (value);
918 g_source_remove (source_id);
922 dispatcher_constructor (GType type,
923 guint n_construct_params,
924 GObjectConstructParam *construct_params)
928 if (dispatcher == NULL)
930 retval = G_OBJECT_CLASS (empathy_dispatcher_parent_class)->constructor
931 (type, n_construct_params, construct_params);
933 dispatcher = EMPATHY_DISPATCHER (retval);
934 g_object_add_weak_pointer (retval, (gpointer) &dispatcher);
938 retval = g_object_ref (dispatcher);
945 dispatcher_finalize (GObject *object)
947 EmpathyDispatcherPriv *priv = GET_PRIV (object);
953 if (priv->request_channel_class_async_ids != NULL)
955 g_hash_table_foreach (priv->request_channel_class_async_ids,
956 remove_idle_handlers, NULL);
957 g_hash_table_destroy (priv->request_channel_class_async_ids);
960 g_signal_handlers_disconnect_by_func (priv->account_manager,
961 dispatcher_new_connection_cb, object);
963 for (l = priv->channels; l; l = l->next)
965 g_signal_handlers_disconnect_by_func (l->data,
966 dispatcher_channel_invalidated_cb, object);
969 g_list_free (priv->channels);
971 g_hash_table_iter_init (&iter, priv->connections);
972 while (g_hash_table_iter_next (&iter, &connection, NULL))
974 g_signal_handlers_disconnect_by_func (connection,
975 dispatcher_connection_invalidated_cb, object);
978 g_hash_table_iter_init (&iter, priv->outstanding_classes_requests);
979 while (g_hash_table_iter_next (&iter, &connection, (gpointer *) &list))
981 g_list_foreach (list, (GFunc) free_find_channel_request, NULL);
985 g_object_unref (priv->account_manager);
986 g_object_unref (priv->mc);
988 g_hash_table_destroy (priv->connections);
989 g_hash_table_destroy (priv->outstanding_classes_requests);
993 empathy_dispatcher_class_init (EmpathyDispatcherClass *klass)
995 GObjectClass *object_class = G_OBJECT_CLASS (klass);
997 object_class->finalize = dispatcher_finalize;
998 object_class->constructor = dispatcher_constructor;
1001 g_signal_new ("observe",
1002 G_TYPE_FROM_CLASS (klass),
1006 g_cclosure_marshal_VOID__OBJECT,
1008 1, EMPATHY_TYPE_DISPATCH_OPERATION);
1011 g_signal_new ("approve",
1012 G_TYPE_FROM_CLASS (klass),
1016 g_cclosure_marshal_VOID__OBJECT,
1018 1, EMPATHY_TYPE_DISPATCH_OPERATION);
1021 g_signal_new ("dispatch",
1022 G_TYPE_FROM_CLASS (klass),
1026 g_cclosure_marshal_VOID__OBJECT,
1028 1, EMPATHY_TYPE_DISPATCH_OPERATION);
1030 g_type_class_add_private (object_class, sizeof (EmpathyDispatcherPriv));
1035 empathy_dispatcher_init (EmpathyDispatcher *dispatcher)
1037 GList *connections, *l;
1038 EmpathyDispatcherPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (dispatcher,
1039 EMPATHY_TYPE_DISPATCHER, EmpathyDispatcherPriv);
1041 dispatcher->priv = priv;
1042 priv->mc = empathy_mission_control_dup_singleton ();
1043 priv->account_manager = empathy_account_manager_dup_singleton ();
1045 g_signal_connect (priv->account_manager, "new-connection",
1046 G_CALLBACK (dispatcher_new_connection_cb),
1049 priv->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal,
1050 g_object_unref, (GDestroyNotify) free_connection_data);
1052 priv->outstanding_classes_requests = g_hash_table_new_full (g_direct_hash,
1053 g_direct_equal, g_object_unref, NULL);
1055 priv->channels = NULL;
1057 connections = empathy_account_manager_dup_connections (priv->account_manager);
1058 for (l = connections; l; l = l->next)
1060 dispatcher_new_connection_cb (priv->account_manager, l->data, dispatcher);
1061 g_object_unref (l->data);
1063 g_list_free (connections);
1065 priv->request_channel_class_async_ids = g_hash_table_new (g_direct_hash,
1070 empathy_dispatcher_dup_singleton (void)
1072 return EMPATHY_DISPATCHER (g_object_new (EMPATHY_TYPE_DISPATCHER, NULL));
1076 dispatcher_request_failed (EmpathyDispatcher *dispatcher,
1077 DispatcherRequestData *request_data,
1078 const GError *error)
1080 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
1081 ConnectionData *conn_data;
1083 conn_data = g_hash_table_lookup (priv->connections, request_data->connection);
1084 if (request_data->cb != NULL)
1085 request_data->cb (NULL, error, request_data->user_data);
1087 conn_data->outstanding_requests =
1088 g_list_remove (conn_data->outstanding_requests, request_data);
1089 free_dispatcher_request_data (request_data);
1093 dispatcher_connection_new_requested_channel (EmpathyDispatcher *dispatcher,
1094 DispatcherRequestData *request_data,
1095 const gchar *object_path,
1096 GHashTable *properties,
1097 const GError *error)
1099 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
1100 EmpathyDispatchOperation *operation = NULL;
1101 ConnectionData *conn_data;
1103 conn_data = g_hash_table_lookup (priv->connections,
1104 request_data->connection);
1108 DEBUG ("Channel request failed: %s", error->message);
1110 dispatcher_request_failed (dispatcher, request_data, error);
1115 operation = g_hash_table_lookup (conn_data->outstanding_channels,
1118 if (operation != NULL)
1119 g_hash_table_remove (conn_data->outstanding_channels, object_path);
1121 operation = g_hash_table_lookup (conn_data->dispatching_channels,
1124 if (operation == NULL)
1126 DispatchData *data = g_hash_table_lookup (conn_data->dispatched_channels,
1131 operation = empathy_dispatch_operation_new_with_wrapper (
1132 request_data->connection,
1133 data->channel, request_data->contact, FALSE,
1134 data->channel_wrapper);
1140 if (properties != NULL)
1141 channel = tp_channel_new_from_properties (request_data->connection,
1142 object_path, properties, NULL);
1144 channel = tp_channel_new (request_data->connection, object_path,
1145 request_data->channel_type, request_data->handle_type,
1146 request_data->handle, NULL);
1148 g_signal_connect (channel, "invalidated",
1149 G_CALLBACK (dispatcher_channel_invalidated_cb),
1150 request_data->dispatcher);
1152 priv->channels = g_list_prepend (priv->channels, channel);
1154 operation = empathy_dispatch_operation_new (request_data->connection,
1155 channel, request_data->contact, FALSE);
1156 g_object_unref (channel);
1161 /* Already existed set potential extra information */
1162 g_object_set (G_OBJECT (operation),
1163 "contact", request_data->contact,
1167 request_data->operation = operation;
1169 /* (pre)-approve this right away as we requested it
1170 * This might cause the channel to be claimed, in which case the operation
1171 * will disappear. So ref it, and check the status before starting the
1174 g_object_ref (operation);
1175 empathy_dispatch_operation_approve (operation);
1177 if (empathy_dispatch_operation_get_status (operation) <
1178 EMPATHY_DISPATCHER_OPERATION_STATE_APPROVING)
1179 dispatcher_start_dispatching (request_data->dispatcher, operation,
1182 g_object_unref (operation);
1185 dispatcher_flush_outstanding_operations (request_data->dispatcher,
1190 dispatcher_request_channel_cb (TpConnection *connection,
1191 const gchar *object_path,
1192 const GError *error,
1194 GObject *weak_object)
1196 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (weak_object);
1197 DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
1199 dispatcher_connection_new_requested_channel (dispatcher,
1200 request_data, object_path, NULL, error);
1204 dispatcher_request_channel (DispatcherRequestData *request_data)
1206 tp_cli_connection_call_request_channel (request_data->connection, -1,
1207 request_data->channel_type,
1208 request_data->handle_type,
1209 request_data->handle,
1210 TRUE, dispatcher_request_channel_cb,
1211 request_data, NULL, G_OBJECT (request_data->dispatcher));
1215 empathy_dispatcher_chat_with_contact (EmpathyContact *contact,
1216 EmpathyDispatcherRequestCb *callback,
1219 EmpathyDispatcher *dispatcher;
1220 EmpathyDispatcherPriv *priv;
1221 TpConnection *connection;
1222 ConnectionData *connection_data;
1223 DispatcherRequestData *request_data;
1225 g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1227 dispatcher = empathy_dispatcher_dup_singleton ();
1228 priv = GET_PRIV (dispatcher);
1230 connection = empathy_contact_get_connection (contact);
1231 connection_data = g_hash_table_lookup (priv->connections, connection);
1233 /* The contact handle might not be known yet */
1234 request_data = new_dispatcher_request_data (dispatcher, connection,
1235 TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_CONTACT,
1236 empathy_contact_get_handle (contact), NULL, contact, callback, user_data);
1238 connection_data->outstanding_requests = g_list_prepend
1239 (connection_data->outstanding_requests, request_data);
1241 dispatcher_request_channel (request_data);
1243 g_object_unref (dispatcher);
1248 EmpathyDispatcher *dispatcher;
1249 EmpathyDispatcherRequestCb *callback;
1251 } ChatWithContactIdData;
1254 dispatcher_chat_with_contact_id_cb (EmpathyTpContactFactory *factory,
1255 EmpathyContact *contact,
1256 const GError *error,
1258 GObject *weak_object)
1260 ChatWithContactIdData *data = user_data;
1264 /* FIXME: Should call data->callback with the error */
1265 DEBUG ("Error: %s", error->message);
1269 empathy_dispatcher_chat_with_contact (contact, data->callback, data->user_data);
1272 g_object_unref (data->dispatcher);
1273 g_slice_free (ChatWithContactIdData, data);
1277 empathy_dispatcher_chat_with_contact_id (TpConnection *connection,
1278 const gchar *contact_id,
1279 EmpathyDispatcherRequestCb *callback,
1282 EmpathyDispatcher *dispatcher;
1283 EmpathyTpContactFactory *factory;
1284 ChatWithContactIdData *data;
1286 g_return_if_fail (TP_IS_CONNECTION (connection));
1287 g_return_if_fail (!EMP_STR_EMPTY (contact_id));
1289 dispatcher = empathy_dispatcher_dup_singleton ();
1290 factory = empathy_tp_contact_factory_dup_singleton (connection);
1291 data = g_slice_new0 (ChatWithContactIdData);
1292 data->dispatcher = dispatcher;
1293 data->callback = callback;
1294 data->user_data = user_data;
1295 empathy_tp_contact_factory_get_from_id (factory, contact_id,
1296 dispatcher_chat_with_contact_id_cb, data, NULL, NULL);
1298 g_object_unref (factory);
1302 dispatcher_request_handles_cb (TpConnection *connection,
1303 const GArray *handles,
1304 const GError *error,
1308 DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
1312 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (object);
1313 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
1316 cd = g_hash_table_lookup (priv->connections, request_data->connection);
1318 if (request_data->cb)
1319 request_data->cb (NULL, error, request_data->user_data);
1321 cd->outstanding_requests = g_list_remove (cd->outstanding_requests,
1324 free_dispatcher_request_data (request_data);
1326 dispatcher_flush_outstanding_operations (dispatcher, cd);
1330 request_data->handle = g_array_index (handles, guint, 0);
1331 dispatcher_request_channel (request_data);
1335 empathy_dispatcher_join_muc (TpConnection *connection,
1336 const gchar *roomname,
1337 EmpathyDispatcherRequestCb *callback,
1340 EmpathyDispatcher *dispatcher;
1341 EmpathyDispatcherPriv *priv;
1342 DispatcherRequestData *request_data;
1343 ConnectionData *connection_data;
1344 const gchar *names[] = { roomname, NULL };
1346 g_return_if_fail (TP_IS_CONNECTION (connection));
1347 g_return_if_fail (!EMP_STR_EMPTY (roomname));
1349 dispatcher = empathy_dispatcher_dup_singleton ();
1350 priv = GET_PRIV (dispatcher);
1352 connection_data = g_hash_table_lookup (priv->connections, connection);
1354 /* Don't know the room handle yet */
1355 request_data = new_dispatcher_request_data (dispatcher, connection,
1356 TP_IFACE_CHANNEL_TYPE_TEXT, TP_HANDLE_TYPE_ROOM, 0, NULL,
1357 NULL, callback, user_data);
1359 connection_data->outstanding_requests = g_list_prepend
1360 (connection_data->outstanding_requests, request_data);
1362 tp_cli_connection_call_request_handles (connection, -1,
1363 TP_HANDLE_TYPE_ROOM, names,
1364 dispatcher_request_handles_cb, request_data, NULL,
1365 G_OBJECT (dispatcher));
1367 g_object_unref (dispatcher);
1371 dispatcher_create_channel_cb (TpConnection *connect,
1372 const gchar *object_path,
1373 GHashTable *properties,
1374 const GError *error,
1376 GObject *weak_object)
1378 EmpathyDispatcher *dispatcher = EMPATHY_DISPATCHER (weak_object);
1379 DispatcherRequestData *request_data = (DispatcherRequestData *) user_data;
1381 dispatcher_connection_new_requested_channel (dispatcher,
1382 request_data, object_path, properties, error);
1386 empathy_dispatcher_create_channel (EmpathyDispatcher *dispatcher,
1387 TpConnection *connection,
1388 GHashTable *request,
1389 EmpathyDispatcherRequestCb *callback,
1392 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
1393 ConnectionData *connection_data;
1394 DispatcherRequestData *request_data;
1395 const gchar *channel_type;
1400 g_return_if_fail (EMPATHY_IS_DISPATCHER (dispatcher));
1401 g_return_if_fail (TP_IS_CONNECTION (connection));
1402 g_return_if_fail (request != NULL);
1404 connection_data = g_hash_table_lookup (priv->connections, connection);
1405 g_assert (connection_data != NULL);
1407 channel_type = tp_asv_get_string (request, TP_IFACE_CHANNEL ".ChannelType");
1409 handle_type = tp_asv_get_uint32 (request,
1410 TP_IFACE_CHANNEL ".TargetHandleType", &valid);
1412 handle_type = TP_UNKNOWN_HANDLE_TYPE;
1414 handle = tp_asv_get_uint32 (request, TP_IFACE_CHANNEL ".TargetHandle", NULL);
1416 request_data = new_dispatcher_request_data (dispatcher, connection,
1417 channel_type, handle_type, handle, request,
1418 NULL, callback, user_data);
1420 connection_data->outstanding_requests = g_list_prepend
1421 (connection_data->outstanding_requests, request_data);
1423 tp_cli_connection_interface_requests_call_create_channel (
1424 request_data->connection, -1,
1425 request_data->request, dispatcher_create_channel_cb, request_data, NULL,
1426 G_OBJECT (request_data->dispatcher));
1430 channel_class_matches (GValueArray *class,
1431 const char *channel_type,
1433 GArray *fixed_properties)
1441 v = g_value_array_get_nth (class, 0);
1443 /* if the class doesn't match channel type discard it. */
1444 fprops = g_value_get_boxed (v);
1445 c_type = tp_asv_get_string (fprops, TP_IFACE_CHANNEL ".ChannelType");
1447 if (tp_strdiff (channel_type, c_type))
1450 /* we have the right channel type, see if the handle type matches */
1451 h_type = tp_asv_get_uint32 (fprops,
1452 TP_IFACE_CHANNEL ".TargetHandleType", &valid);
1454 if (!valid || handle_type != h_type)
1457 if (fixed_properties != NULL)
1459 gpointer h_key, h_val;
1461 GHashTableIter iter;
1464 g_hash_table_iter_init (&iter, fprops);
1466 while (g_hash_table_iter_next (&iter, &h_key, &h_val))
1468 /* discard ChannelType and TargetHandleType, as we already
1471 if (!tp_strdiff ((char *) h_key, TP_IFACE_CHANNEL ".ChannelType") ||
1473 ((char *) h_key, TP_IFACE_CHANNEL ".TargetHandleType"))
1478 for (idx = 0; idx < fixed_properties->len; idx++)
1480 /* if |key| doesn't exist in |fixed_properties|, discard
1485 g_array_index (fixed_properties, char *, idx)))
1488 /* exit the for() loop */
1499 /* if no fixed_properties are specified, discard the classes
1500 * with some fixed properties other than the two we already
1503 if (g_hash_table_size (fprops) > 2)
1511 empathy_dispatcher_find_channel_classes (EmpathyDispatcher *dispatcher,
1512 TpConnection *connection,
1513 const gchar *channel_type,
1515 GArray *fixed_properties)
1517 EmpathyDispatcherPriv *priv = GET_PRIV (dispatcher);
1520 GList *matching_classes;
1524 g_return_val_if_fail (channel_type != NULL, NULL);
1525 g_return_val_if_fail (handle_type != 0, NULL);
1527 cd = g_hash_table_lookup (priv->connections, connection);
1532 classes = cd->requestable_channels;
1533 if (classes == NULL)
1536 matching_classes = NULL;
1538 for (i = 0; i < classes->len; i++)
1540 class = g_ptr_array_index (classes, i);
1542 if (!channel_class_matches
1543 (class, channel_type, handle_type, fixed_properties))
1546 matching_classes = g_list_prepend (matching_classes, class);
1549 return matching_classes;
1553 find_channel_class_idle_cb (gpointer user_data)
1557 FindChannelRequest *request = user_data;
1559 gboolean is_ready = TRUE;
1560 EmpathyDispatcherPriv *priv = GET_PRIV (request->dispatcher);
1562 g_hash_table_remove (priv->request_channel_class_async_ids, request);
1564 cd = g_hash_table_lookup (priv->connections, request->connection);
1568 else if (cd->requestable_channels == NULL)
1573 retval = empathy_dispatcher_find_channel_classes (request->dispatcher,
1574 request->connection, request->channel_type, request->handle_type,
1575 request->properties);
1577 request->callback (retval, request->user_data);
1578 free_find_channel_request (request);
1579 g_list_free (retval);
1584 requests = g_hash_table_lookup (priv->outstanding_classes_requests,
1585 request->connection);
1586 requests = g_list_prepend (requests, request);
1588 g_hash_table_insert (priv->outstanding_classes_requests,
1589 request->connection, requests);
1595 setup_varargs (va_list var_args,
1596 const char *channel_namespace,
1597 const char *first_property_name)
1603 if (first_property_name == NULL)
1606 name = first_property_name;
1607 properties = g_array_new (TRUE, TRUE, sizeof (char *));
1609 while (name != NULL)
1611 name_full = g_strdup (name);
1612 properties = g_array_append_val (properties, name_full);
1613 name = va_arg (var_args, char *);
1620 * empathy_dispatcher_find_requestable_channel_classes:
1621 * @dispatcher: an #EmpathyDispatcher
1622 * @connection: a #TpConnection
1623 * @channel_type: a string identifying the type of the channel to lookup
1624 * @handle_type: the handle type for the channel
1625 * @first_property_name: %NULL, or the name of the first fixed property,
1626 * followed optionally by more names, followed by %NULL.
1628 * Returns all the channel classes that a client can request for the connection
1629 * @connection, of the type identified by @channel_type, @handle_type and the
1630 * fixed properties list.
1631 * The classes which are compatible with a fixed properties list (i.e. those
1632 * that will be returned by this function) are intended as those that do not
1633 * contain any fixed property other than those in the list; note that this
1634 * doesn't guarantee that all the classes compatible with the list will contain
1635 * all the requested fixed properties, so the clients will have to filter
1636 * the returned list themselves.
1637 * If @first_property_name is %NULL, only the classes with no other fixed
1638 * properties than ChannelType and TargetHandleType will be returned.
1639 * Note that this function may return %NULL without performing any lookup if
1640 * @connection is not ready. To ensure that @connection is always ready,
1641 * use the empathy_dispatcher_find_requestable_channel_classes_async() variant.
1643 * Return value: a #GList of #GValueArray objects, where the first element in
1644 * the array is a #GHashTable of the fixed properties, and the second is
1645 * a #GStrv of the allowed properties for the class. The list should be free'd
1646 * with g_list_free() when done, but the objects inside the list are owned
1647 * by the #EmpathyDispatcher and must not be modified.
1650 empathy_dispatcher_find_requestable_channel_classes
1651 (EmpathyDispatcher *dispatcher,
1652 TpConnection *connection,
1653 const gchar *channel_type,
1655 const char *first_property_name,
1660 EmpathyDispatcherPriv *priv;
1665 g_return_val_if_fail (EMPATHY_IS_DISPATCHER (dispatcher), NULL);
1666 g_return_val_if_fail (TP_IS_CONNECTION (connection), NULL);
1667 g_return_val_if_fail (channel_type != NULL, NULL);
1668 g_return_val_if_fail (handle_type != 0, NULL);
1670 priv = GET_PRIV (dispatcher);
1672 va_start (var_args, first_property_name);
1674 properties = setup_varargs (var_args, channel_type, first_property_name);
1678 retval = empathy_dispatcher_find_channel_classes (dispatcher, connection,
1679 channel_type, handle_type, properties);
1681 if (properties != NULL)
1683 /* free the properties array */
1684 for (idx = 0; idx < properties->len ; idx++)
1686 str = g_array_index (properties, char *, idx);
1690 g_array_free (properties, TRUE);
1697 * empathy_dispatcher_find_requestable_channel_classes_async:
1698 * @dispatcher: an #EmpathyDispatcher
1699 * @connection: a #TpConnection
1700 * @channel_type: a string identifying the type of the channel to lookup
1701 * @handle_type: the handle type for the channel
1702 * @callback: the callback to call when @connection is ready
1703 * @user_data: the user data to pass to @callback
1704 * @first_property_name: %NULL, or the name of the first fixed property,
1705 * followed optionally by more names, followed by %NULL.
1707 * Please see the documentation of
1708 * empathy_dispatcher_find_requestable_channel_classes() for a detailed
1709 * description of this function.
1712 empathy_dispatcher_find_requestable_channel_classes_async
1713 (EmpathyDispatcher *dispatcher,
1714 TpConnection *connection,
1715 const gchar *channel_type,
1717 EmpathyDispatcherFindChannelClassCb callback,
1719 const char *first_property_name,
1724 FindChannelRequest *request;
1725 EmpathyDispatcherPriv *priv;
1728 g_return_if_fail (EMPATHY_IS_DISPATCHER (dispatcher));
1729 g_return_if_fail (TP_IS_CONNECTION (connection));
1730 g_return_if_fail (channel_type != NULL);
1731 g_return_if_fail (handle_type != 0);
1733 priv = GET_PRIV (dispatcher);
1735 va_start (var_args, first_property_name);
1737 properties = setup_varargs (var_args, channel_type, first_property_name);
1741 /* append another request for this connection */
1742 request = g_slice_new0 (FindChannelRequest);
1743 request->dispatcher = dispatcher;
1744 request->channel_type = g_strdup (channel_type);
1745 request->handle_type = handle_type;
1746 request->connection = connection;
1747 request->callback = callback;
1748 request->user_data = user_data;
1749 request->properties = properties;
1751 source_id = g_idle_add (find_channel_class_idle_cb, request);
1753 g_hash_table_insert (priv->request_channel_class_async_ids,
1754 request, GUINT_TO_POINTER (source_id));