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-dispatcher.h>
33
#include <libempathy/empathy-channel-factory.h>
34
#include <libempathy/empathy-tp-contact-factory.h>
35
#include <libempathy/empathy-utils.h>
37
#include <libempathy-gtk/empathy-call-utils.h>
39
#include "empathy-call-factory.h"
40
#include "empathy-call-handler.h"
41
#include "src-marshal.h"
43
#define DEBUG_FLAG EMPATHY_DEBUG_VOIP
44
#include <libempathy/empathy-debug.h>
46
G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
48
static void handle_channels_cb (TpSimpleHandler *handler,
50
TpConnection *connection,
52
GList *requests_satisfied,
53
gint64 user_action_time,
54
TpHandleChannelsContext *context,
64
static guint signals[LAST_SIGNAL] = {0};
66
/* private structure */
68
TpBaseClient *handler;
69
gboolean dispose_has_run;
70
} EmpathyCallFactoryPriv;
72
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
74
static GObject *call_factory = NULL;
77
empathy_call_factory_init (EmpathyCallFactory *obj)
79
EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
80
EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
82
EmpathyChannelFactory *factory;
87
dbus = tp_dbus_daemon_dup (&error);
90
g_warning ("Failed to get TpDBusDaemon: %s", error->message);
95
priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
96
"Empathy.Call", FALSE, handle_channels_cb, obj, NULL);
98
factory = empathy_channel_factory_new ();
99
tp_base_client_set_channel_factory (priv->handler,
100
TP_CLIENT_CHANNEL_FACTORY (factory));
101
g_object_unref (factory);
103
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
104
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
105
TPY_IFACE_CHANNEL_TYPE_CALL,
106
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
107
G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
110
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
111
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
112
TPY_IFACE_CHANNEL_TYPE_CALL,
113
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
114
G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
115
TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
118
tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
119
TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
120
TPY_IFACE_CHANNEL_TYPE_CALL,
121
TP_PROP_CHANNEL_TARGET_HANDLE_TYPE,
122
G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
123
TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
126
tp_base_client_add_handler_capabilities_varargs (priv->handler,
127
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
128
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
129
"org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
132
g_object_unref (dbus);
136
empathy_call_factory_constructor (GType type, guint n_construct_params,
137
GObjectConstructParam *construct_params)
139
g_return_val_if_fail (call_factory == NULL, NULL);
141
call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
142
(type, n_construct_params, construct_params);
143
g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
149
empathy_call_factory_finalize (GObject *object)
151
/* free any data held directly by the object here */
153
if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
154
G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
158
empathy_call_factory_dispose (GObject *object)
160
EmpathyCallFactoryPriv *priv = GET_PRIV (object);
162
if (priv->dispose_has_run)
165
priv->dispose_has_run = TRUE;
167
tp_clear_object (&priv->handler);
169
if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
170
G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
174
empathy_call_factory_class_init (
175
EmpathyCallFactoryClass *empathy_call_factory_class)
177
GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
179
g_type_class_add_private (empathy_call_factory_class,
180
sizeof (EmpathyCallFactoryPriv));
182
object_class->constructor = empathy_call_factory_constructor;
183
object_class->dispose = empathy_call_factory_dispose;
184
object_class->finalize = empathy_call_factory_finalize;
186
signals[NEW_CALL_HANDLER] =
187
g_signal_new ("new-call-handler",
188
G_TYPE_FROM_CLASS (empathy_call_factory_class),
189
G_SIGNAL_RUN_LAST, 0,
191
_src_marshal_VOID__OBJECT_BOOLEAN,
193
2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
197
empathy_call_factory_initialise (void)
199
g_return_val_if_fail (call_factory == NULL, NULL);
201
return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
205
empathy_call_factory_get (void)
207
g_return_val_if_fail (call_factory != NULL, NULL);
209
return EMPATHY_CALL_FACTORY (call_factory);
213
create_call_channel_cb (GObject *source,
214
GAsyncResult *result,
217
GError *error = NULL;
219
if (!tp_account_channel_request_create_channel_finish (
220
TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error))
222
DEBUG ("Failed to create call channel: %s", error->message);
223
g_error_free (error);
228
* empathy_call_factory_new_call_with_streams:
229
* @factory: an #EmpathyCallFactory
230
* @contact: an #EmpathyContact
231
* @initial_audio: if %TRUE the call will be started with audio
232
* @initial_video: if %TRUE the call will be started with video
234
* Initiate a new Call with @contact.
237
empathy_call_factory_new_call_with_streams (EmpathyContact *contact,
238
gboolean initial_audio,
239
gboolean initial_video,
243
GHashTable *call_request;
245
TpAccountChannelRequest *call_req;
247
call_request = empathy_call_create_call_request (
248
empathy_contact_get_id (contact),
249
initial_audio, initial_video);
251
account = empathy_contact_get_account (contact);
253
call_req = tp_account_channel_request_new (account, call_request, timestamp);
255
tp_account_channel_request_create_channel_async (call_req, NULL, NULL,
256
create_call_channel_cb, NULL);
258
g_hash_table_unref (call_request);
259
g_object_unref (call_req);
263
call_channel_got_contact (TpConnection *connection,
264
EmpathyContact *contact,
267
GObject *weak_object)
269
EmpathyCallFactory *factory = EMPATHY_CALL_FACTORY (weak_object);
270
EmpathyCallHandler *handler;
271
TpyCallChannel *call = TPY_CALL_CHANNEL (user_data);
275
/* FIXME use hangup with an appropriate error */
276
tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
280
handler = empathy_call_handler_new_for_channel (call, contact);
282
g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
285
g_object_unref (handler);
288
g_object_unref (call);
293
handle_channels_cb (TpSimpleHandler *handler,
295
TpConnection *connection,
297
GList *requests_satisfied,
298
gint64 user_action_time,
299
TpHandleChannelsContext *context,
302
EmpathyCallFactory *self = user_data;
305
for (l = channels; l != NULL; l = g_list_next (l))
307
TpChannel *channel = l->data;
308
TpyCallChannel *call;
311
if (tp_proxy_get_invalidated (channel) != NULL)
314
if (tp_channel_get_channel_type_id (channel) !=
315
TPY_IFACE_QUARK_CHANNEL_TYPE_CALL)
318
if (!TPY_IS_CALL_CHANNEL (channel))
321
call = TPY_CALL_CHANNEL (channel);
323
id = tp_channel_get_identifier (channel);
324
empathy_tp_contact_factory_get_from_id (connection,
326
call_channel_got_contact,
327
g_object_ref (channel),
332
tp_handle_channels_context_accept (context);
336
empathy_call_factory_register (EmpathyCallFactory *self,
339
EmpathyCallFactoryPriv *priv = GET_PRIV (self);
341
return tp_base_client_register (priv->handler, error);