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
25 #include <telepathy-glib/account-channel-request.h>
26 #include <telepathy-glib/simple-handler.h>
27 #include <telepathy-glib/interfaces.h>
28 #include <telepathy-glib/util.h>
30 #include <telepathy-yell/telepathy-yell.h>
32 #include <libempathy/empathy-channel-factory.h>
33 #include <libempathy/empathy-request-util.h>
34 #include <libempathy/empathy-utils.h>
36 #include <libempathy-gtk/empathy-call-utils.h>
38 #include "empathy-call-factory.h"
39 #include "empathy-call-handler.h"
40 #include "src-marshal.h"
42 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
43 #include <libempathy/empathy-debug.h>
45 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
47 static void handle_channels_cb (TpSimpleHandler *handler,
49 TpConnection *connection,
51 GList *requests_satisfied,
52 gint64 user_action_time,
53 TpHandleChannelsContext *context,
63 static guint signals[LAST_SIGNAL] = {0};
65 /* private structure */
67 TpBaseClient *handler;
68 gboolean dispose_has_run;
69 } EmpathyCallFactoryPriv;
71 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
73 static GObject *call_factory = NULL;
76 empathy_call_factory_init (EmpathyCallFactory *obj)
78 EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
79 EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
81 EmpathyChannelFactory *factory;
86 dbus = tp_dbus_daemon_dup (&error);
89 g_warning ("Failed to get TpDBusDaemon: %s", error->message);
94 priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
95 EMPATHY_CALL_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, obj, NULL);
97 factory = empathy_channel_factory_new ();
98 tp_base_client_set_channel_factory (priv->handler,
99 TP_CLIENT_CHANNEL_FACTORY (factory));
100 g_object_unref (factory);
102 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
103 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
104 TPY_IFACE_CHANNEL_TYPE_CALL,
105 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
108 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
109 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
110 TPY_IFACE_CHANNEL_TYPE_CALL,
111 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
112 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
115 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
116 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
117 TPY_IFACE_CHANNEL_TYPE_CALL,
118 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
119 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
122 tp_base_client_add_handler_capabilities_varargs (priv->handler,
123 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
124 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
125 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
128 g_object_unref (dbus);
132 empathy_call_factory_constructor (GType type, guint n_construct_params,
133 GObjectConstructParam *construct_params)
135 g_return_val_if_fail (call_factory == NULL, NULL);
137 call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
138 (type, n_construct_params, construct_params);
139 g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
145 empathy_call_factory_finalize (GObject *object)
147 /* free any data held directly by the object here */
149 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
150 G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
154 empathy_call_factory_dispose (GObject *object)
156 EmpathyCallFactoryPriv *priv = GET_PRIV (object);
158 if (priv->dispose_has_run)
161 priv->dispose_has_run = TRUE;
163 tp_clear_object (&priv->handler);
165 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
166 G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
170 empathy_call_factory_class_init (
171 EmpathyCallFactoryClass *empathy_call_factory_class)
173 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
175 g_type_class_add_private (empathy_call_factory_class,
176 sizeof (EmpathyCallFactoryPriv));
178 object_class->constructor = empathy_call_factory_constructor;
179 object_class->dispose = empathy_call_factory_dispose;
180 object_class->finalize = empathy_call_factory_finalize;
182 signals[NEW_CALL_HANDLER] =
183 g_signal_new ("new-call-handler",
184 G_TYPE_FROM_CLASS (empathy_call_factory_class),
185 G_SIGNAL_RUN_LAST, 0,
187 _src_marshal_VOID__OBJECT_BOOLEAN,
189 2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
193 empathy_call_factory_initialise (void)
195 g_return_val_if_fail (call_factory == NULL, NULL);
197 return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
201 empathy_call_factory_get (void)
203 g_return_val_if_fail (call_factory != NULL, NULL);
205 return EMPATHY_CALL_FACTORY (call_factory);
209 create_call_channel_cb (GObject *source,
210 GAsyncResult *result,
213 GError *error = NULL;
215 if (!tp_account_channel_request_create_channel_finish (
216 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
218 DEBUG ("Failed to create call channel: %s", error->message);
219 g_error_free (error);
224 * empathy_call_factory_new_call_with_streams:
225 * @factory: an #EmpathyCallFactory
226 * @contact: an #EmpathyContact
227 * @initial_audio: if %TRUE the call will be started with audio
228 * @initial_video: if %TRUE the call will be started with video
230 * Initiate a new Call with @contact.
233 empathy_call_factory_new_call_with_streams (EmpathyContact *contact,
234 gboolean initial_audio,
235 gboolean initial_video,
239 GHashTable *call_request;
241 TpAccountChannelRequest *call_req;
243 call_request = empathy_call_create_call_request (contact,
244 initial_audio, initial_video);
246 account = empathy_contact_get_account (contact);
248 call_req = tp_account_channel_request_new (account, call_request, timestamp);
250 tp_account_channel_request_create_channel_async (call_req, NULL, NULL,
251 create_call_channel_cb, NULL);
253 g_hash_table_unref (call_request);
254 g_object_unref (call_req);
258 create_call_handler (EmpathyCallFactory *factory,
259 TpyCallChannel *call)
261 EmpathyCallHandler *handler;
263 g_return_if_fail (factory != NULL);
265 handler = empathy_call_handler_new_for_channel (call);
267 g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
270 g_object_unref (handler);
274 handle_channels_cb (TpSimpleHandler *handler,
276 TpConnection *connection,
278 GList *requests_satisfied,
279 gint64 user_action_time,
280 TpHandleChannelsContext *context,
283 EmpathyCallFactory *self = user_data;
286 for (l = channels; l != NULL; l = g_list_next (l))
288 TpChannel *channel = l->data;
289 TpyCallChannel *call;
291 if (tp_proxy_get_invalidated (channel) != NULL)
294 if (tp_channel_get_channel_type_id (channel) !=
295 TPY_IFACE_QUARK_CHANNEL_TYPE_CALL)
298 if (!TPY_IS_CALL_CHANNEL (channel))
301 call = TPY_CALL_CHANNEL (channel);
302 create_call_handler (self, call);
303 g_object_unref (call);
306 tp_handle_channels_context_accept (context);
310 empathy_call_factory_register (EmpathyCallFactory *self,
313 EmpathyCallFactoryPriv *priv = GET_PRIV (self);
315 return tp_base_client_register (priv->handler, error);