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 "empathy-call-factory.h"
37 #include "empathy-call-handler.h"
38 #include "src-marshal.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
41 #include <libempathy/empathy-debug.h>
43 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
45 static void handle_channels_cb (TpSimpleHandler *handler,
47 TpConnection *connection,
49 GList *requests_satisfied,
50 gint64 user_action_time,
51 TpHandleChannelsContext *context,
61 static guint signals[LAST_SIGNAL] = {0};
63 /* private structure */
65 TpBaseClient *handler;
66 gboolean dispose_has_run;
67 } EmpathyCallFactoryPriv;
69 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
71 static GObject *call_factory = NULL;
74 empathy_call_factory_init (EmpathyCallFactory *obj)
76 EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
77 EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
79 EmpathyChannelFactory *factory;
84 dbus = tp_dbus_daemon_dup (&error);
87 g_warning ("Failed to get TpDBusDaemon: %s", error->message);
92 priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
93 EMPATHY_CALL_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, obj, NULL);
95 factory = empathy_channel_factory_new ();
96 tp_base_client_set_channel_factory (priv->handler,
97 TP_CLIENT_CHANNEL_FACTORY (factory));
98 g_object_unref (factory);
100 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
101 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
102 TPY_IFACE_CHANNEL_TYPE_CALL,
103 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
106 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
107 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
108 TPY_IFACE_CHANNEL_TYPE_CALL,
109 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
110 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
113 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
114 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
115 TPY_IFACE_CHANNEL_TYPE_CALL,
116 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
117 TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
120 tp_base_client_add_handler_capabilities_varargs (priv->handler,
121 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
122 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
123 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
126 g_object_unref (dbus);
130 empathy_call_factory_constructor (GType type, guint n_construct_params,
131 GObjectConstructParam *construct_params)
133 g_return_val_if_fail (call_factory == NULL, NULL);
135 call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
136 (type, n_construct_params, construct_params);
137 g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
143 empathy_call_factory_finalize (GObject *object)
145 /* free any data held directly by the object here */
147 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
148 G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
152 empathy_call_factory_dispose (GObject *object)
154 EmpathyCallFactoryPriv *priv = GET_PRIV (object);
156 if (priv->dispose_has_run)
159 priv->dispose_has_run = TRUE;
161 tp_clear_object (&priv->handler);
163 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
164 G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
168 empathy_call_factory_class_init (
169 EmpathyCallFactoryClass *empathy_call_factory_class)
171 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
173 g_type_class_add_private (empathy_call_factory_class,
174 sizeof (EmpathyCallFactoryPriv));
176 object_class->constructor = empathy_call_factory_constructor;
177 object_class->dispose = empathy_call_factory_dispose;
178 object_class->finalize = empathy_call_factory_finalize;
180 signals[NEW_CALL_HANDLER] =
181 g_signal_new ("new-call-handler",
182 G_TYPE_FROM_CLASS (empathy_call_factory_class),
183 G_SIGNAL_RUN_LAST, 0,
185 _src_marshal_VOID__OBJECT_BOOLEAN,
187 2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
191 empathy_call_factory_initialise (void)
193 g_return_val_if_fail (call_factory == NULL, NULL);
195 return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
199 empathy_call_factory_get (void)
201 g_return_val_if_fail (call_factory != NULL, NULL);
203 return EMPATHY_CALL_FACTORY (call_factory);
207 create_call_channel_cb (GObject *source,
208 GAsyncResult *result,
211 GError *error = NULL;
213 if (!tp_account_channel_request_create_channel_finish (
214 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
216 DEBUG ("Failed to create call channel: %s", error->message);
217 g_error_free (error);
222 * empathy_call_factory_new_call_with_streams:
223 * @factory: an #EmpathyCallFactory
224 * @contact: an #EmpathyContact
225 * @initial_audio: if %TRUE the call will be started with audio
226 * @initial_video: if %TRUE the call will be started with video
228 * Initiate a new Call with @contact.
231 empathy_call_factory_new_call_with_streams (EmpathyContact *contact,
232 gboolean initial_audio,
233 gboolean initial_video,
237 GHashTable *call_request;
239 TpAccountChannelRequest *call_req;
241 call_request = empathy_call_create_call_request (contact,
242 initial_audio, initial_video);
244 account = empathy_contact_get_account (contact);
246 call_req = tp_account_channel_request_new (account, call_request, timestamp);
248 tp_account_channel_request_create_channel_async (call_req, NULL, NULL,
249 create_call_channel_cb, NULL);
251 g_hash_table_unref (call_request);
252 g_object_unref (call_req);
256 create_call_handler (EmpathyCallFactory *factory,
257 TpyCallChannel *call)
259 EmpathyCallHandler *handler;
261 g_return_if_fail (factory != NULL);
263 handler = empathy_call_handler_new_for_channel (call);
265 g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
268 g_object_unref (handler);
272 handle_channels_cb (TpSimpleHandler *handler,
274 TpConnection *connection,
276 GList *requests_satisfied,
277 gint64 user_action_time,
278 TpHandleChannelsContext *context,
281 EmpathyCallFactory *self = user_data;
284 for (l = channels; l != NULL; l = g_list_next (l))
286 TpChannel *channel = l->data;
287 TpyCallChannel *call;
289 if (tp_proxy_get_invalidated (channel) != NULL)
292 if (tp_channel_get_channel_type_id (channel) !=
293 TPY_IFACE_QUARK_CHANNEL_TYPE_CALL)
296 if (!TPY_IS_CALL_CHANNEL (channel))
299 call = TPY_CALL_CHANNEL (channel);
300 create_call_handler (self, call);
301 g_object_unref (call);
304 tp_handle_channels_context_accept (context);
308 empathy_call_factory_register (EmpathyCallFactory *self,
311 EmpathyCallFactoryPriv *priv = GET_PRIV (self);
313 return tp_base_client_register (priv->handler, error);