2 * empathy-call-factory.c - Source for EmpathyCallFactory
3 * Copyright (C) 2008 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "empathy-client-factory.h"
24 #include "empathy-call-factory.h"
25 #include "empathy-call-handler.h"
26 #include "empathy-request-util.h"
28 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
29 #include "empathy-debug.h"
31 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, TP_TYPE_BASE_CLIENT)
33 static void handle_channels (TpBaseClient *client,
35 TpConnection *connection,
37 GList *requests_satisfied,
38 gint64 user_action_time,
39 TpHandleChannelsContext *context);
41 static void approve_channels (TpBaseClient *client,
43 TpConnection *connection,
45 TpChannelDispatchOperation *dispatch_operation,
46 TpAddDispatchOperationContext *context);
56 static guint signals[LAST_SIGNAL] = {0};
58 static GObject *call_factory = NULL;
61 empathy_call_factory_init (EmpathyCallFactory *obj)
63 TpBaseClient *client = (TpBaseClient *) obj;
65 tp_base_client_take_approver_filter (client, tp_asv_new (
66 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
67 TP_IFACE_CHANNEL_TYPE_CALL,
68 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
69 G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
72 tp_base_client_take_handler_filter (client, tp_asv_new (
73 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
74 TP_IFACE_CHANNEL_TYPE_CALL,
75 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
76 G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
79 tp_base_client_take_handler_filter (client, tp_asv_new (
80 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
81 TP_IFACE_CHANNEL_TYPE_CALL,
82 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
83 G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
84 TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
87 tp_base_client_take_handler_filter (client, tp_asv_new (
88 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
89 TP_IFACE_CHANNEL_TYPE_CALL,
90 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
91 G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
92 TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
95 tp_base_client_add_handler_capabilities_varargs (client,
96 "org.freedesktop.Telepathy.Channel.Type.Call1/audio",
97 "org.freedesktop.Telepathy.Channel.Type.Call1/video",
98 "org.freedesktop.Telepathy.Channel.Type.Call1/ice",
99 "org.freedesktop.Telepathy.Channel.Type.Call1/gtalk-p2p",
100 "org.freedesktop.Telepathy.Channel.Type.Call1/video/h264",
105 empathy_call_factory_constructor (GType type, guint n_construct_params,
106 GObjectConstructParam *construct_params)
108 g_return_val_if_fail (call_factory == NULL, NULL);
110 call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
111 (type, n_construct_params, construct_params);
112 g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
118 empathy_call_factory_class_init (EmpathyCallFactoryClass *klass)
120 GObjectClass *object_class = G_OBJECT_CLASS (klass);
121 TpBaseClientClass *base_clt_cls = TP_BASE_CLIENT_CLASS (klass);
123 object_class->constructor = empathy_call_factory_constructor;
125 base_clt_cls->handle_channels = handle_channels;
126 base_clt_cls->add_dispatch_operation = approve_channels;
128 signals[NEW_CALL_HANDLER] =
129 g_signal_new ("new-call-handler",
130 G_TYPE_FROM_CLASS (klass),
131 G_SIGNAL_RUN_LAST, 0,
133 g_cclosure_marshal_generic,
135 2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
137 signals[INCOMING_CALL] =
138 g_signal_new ("incoming-call",
139 G_TYPE_FROM_CLASS (klass),
140 G_SIGNAL_RUN_LAST, 0,
142 g_cclosure_marshal_generic,
144 4, G_TYPE_UINT, TP_TYPE_CALL_CHANNEL,
145 TP_TYPE_CHANNEL_DISPATCH_OPERATION,
146 TP_TYPE_ADD_DISPATCH_OPERATION_CONTEXT);
150 empathy_call_factory_initialise (void)
152 EmpathyCallFactory *self;
153 EmpathyClientFactory *factory;
154 TpAccountManager *am;
156 g_return_val_if_fail (call_factory == NULL, NULL);
158 am = tp_account_manager_dup ();
159 factory = empathy_client_factory_dup ();
161 self = EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY,
162 "account-manager", am,
164 "name", EMPATHY_CALL_BUS_NAME_SUFFIX,
168 g_object_unref (factory);
174 empathy_call_factory_get (void)
176 g_return_val_if_fail (call_factory != NULL, NULL);
178 return EMPATHY_CALL_FACTORY (call_factory);
182 handle_channels (TpBaseClient *client,
184 TpConnection *connection,
186 GList *requests_satisfied,
187 gint64 user_action_time,
188 TpHandleChannelsContext *context)
190 EmpathyCallFactory *self = EMPATHY_CALL_FACTORY (client);
193 for (l = channels; l != NULL; l = g_list_next (l))
195 TpChannel *channel = l->data;
197 TpContact *tp_contact;
198 EmpathyContact *contact;
199 EmpathyCallHandler *handler;
201 if (tp_proxy_get_invalidated (channel) != NULL)
204 if (tp_channel_get_channel_type_id (channel) !=
205 TP_IFACE_QUARK_CHANNEL_TYPE_CALL)
208 if (!TP_IS_CALL_CHANNEL (channel))
211 call = TP_CALL_CHANNEL (channel);
213 tp_contact = tp_channel_get_target_contact (channel);
214 contact = empathy_contact_dup_from_tp_contact (tp_contact);
215 handler = empathy_call_handler_new_for_channel (call, contact);
217 g_signal_emit (self, signals[NEW_CALL_HANDLER], 0,
220 g_object_unref (handler);
221 g_object_unref (contact);
224 tp_handle_channels_context_accept (context);
227 static TpCallChannel *
228 find_call_channel (GList *channels)
232 for (l = channels; l != NULL; l = g_list_next (l))
234 TpChannel *channel = l->data;
237 if (tp_proxy_get_invalidated (channel) != NULL)
240 channel_type = tp_channel_get_channel_type_id (channel);
242 if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CALL)
243 return TP_CALL_CHANNEL (channel);
250 approve_channels (TpBaseClient *client,
252 TpConnection *connection,
254 TpChannelDispatchOperation *dispatch_operation,
255 TpAddDispatchOperationContext *context)
257 EmpathyCallFactory *self = EMPATHY_CALL_FACTORY (client);
258 TpCallChannel *channel;
260 GError error = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "" };
261 gboolean handled = FALSE;
263 channel = find_call_channel (channels);
267 DEBUG ("Failed to find the main channel; ignoring");
268 error.message = "Unknown channel";
272 handle = tp_channel_get_handle (TP_CHANNEL (channel), NULL);
276 DEBUG ("Unknown handle, ignoring");
277 error.code = TP_ERROR_INVALID_HANDLE;
278 error.message = "Unknown handle";
282 g_signal_emit (self, signals[INCOMING_CALL], 0,
283 handle, channel, dispatch_operation, context,
289 /* There was no call window so the context wasn't handled. */
290 DEBUG ("Call with a contact for which there's no existing "
291 "call window, ignoring");
292 error.message = "No call window with this contact";
295 tp_add_dispatch_operation_context_fail (context, &error);
299 empathy_call_factory_register (EmpathyCallFactory *self,
302 return tp_base_client_register (TP_BASE_CLIENT (self), error);