2 * empathy-call-handler.c - Source for EmpathyCallHandler
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/util.h>
27 #include <telepathy-farsight/channel.h>
28 #include <telepathy-farsight/stream.h>
30 #include "empathy-call-handler.h"
31 #include "empathy-dispatcher.h"
32 #include "empathy-marshal.h"
33 #include "empathy-utils.h"
35 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
46 static guint signals[LAST_SIGNAL] = {0};
54 /* private structure */
57 gboolean dispose_has_run;
59 EmpathyContact *contact;
61 } EmpathyCallHandlerPriv;
63 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
66 empathy_call_handler_dispose (GObject *object)
68 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
70 if (priv->dispose_has_run)
73 priv->dispose_has_run = TRUE;
75 if (priv->contact != NULL)
76 g_object_unref (priv->contact);
80 if (priv->tfchannel != NULL)
81 g_object_unref (priv->tfchannel);
83 priv->tfchannel = NULL;
85 if (priv->call != NULL)
87 empathy_tp_call_close (priv->call);
88 g_object_unref (priv->call);
93 /* release any references held by the object here */
94 if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose)
95 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
99 empathy_call_handler_finalize (GObject *object)
101 /* free any data held directly by the object here */
102 if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize)
103 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
107 empathy_call_handler_init (EmpathyCallHandler *obj)
109 EmpathyCallHandlerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
110 EMPATHY_TYPE_CALL_HANDLER, EmpathyCallHandlerPriv);
116 empathy_call_handler_set_property (GObject *object,
117 guint property_id, const GValue *value, GParamSpec *pspec)
119 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
124 priv->contact = g_value_dup_object (value);
127 priv->call = g_value_dup_object (value);
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
135 empathy_call_handler_get_property (GObject *object,
136 guint property_id, GValue *value, GParamSpec *pspec)
138 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
143 g_value_set_object (value, priv->contact);
146 g_value_set_object (value, priv->call);
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
155 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
157 GObjectClass *object_class = G_OBJECT_CLASS (klass);
158 GParamSpec *param_spec;
160 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
162 object_class->set_property = empathy_call_handler_set_property;
163 object_class->get_property = empathy_call_handler_get_property;
164 object_class->dispose = empathy_call_handler_dispose;
165 object_class->finalize = empathy_call_handler_finalize;
167 param_spec = g_param_spec_object ("contact",
168 "contact", "The remote contact",
169 EMPATHY_TYPE_CONTACT,
170 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
171 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
173 param_spec = g_param_spec_object ("tp-call",
174 "tp-call", "The calls channel wrapper",
175 EMPATHY_TYPE_TP_CALL,
176 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
177 g_object_class_install_property (object_class, PROP_TP_CALL, param_spec);
179 signals[CONFERENCE_ADDED] =
180 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
181 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
182 g_cclosure_marshal_VOID__OBJECT,
184 1, FS_TYPE_CONFERENCE);
186 signals[SRC_PAD_ADDED] =
187 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
188 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
189 _empathy_marshal_VOID__OBJECT_UINT,
191 2, GST_TYPE_PAD, G_TYPE_UINT);
193 signals[SINK_PAD_ADDED] =
194 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
195 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
196 _empathy_marshal_VOID__OBJECT_UINT,
198 2, GST_TYPE_PAD, G_TYPE_UINT);
201 g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
202 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
203 g_cclosure_marshal_VOID__VOID,
209 empathy_call_handler_new_for_contact (EmpathyContact *contact)
211 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
212 "contact", contact, NULL));
216 empathy_call_handler_new_for_channel (EmpathyTpCall *call)
218 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
219 "tp-call", call, NULL));
223 empathy_call_handler_bus_message (EmpathyCallHandler *handler,
224 GstBus *bus, GstMessage *message)
226 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
228 if (priv->tfchannel == NULL)
231 tf_channel_bus_message (priv->tfchannel, message);
235 empathy_call_handler_tf_channel_session_created_cb (TfChannel *tfchannel,
236 FsConference *conference, FsParticipant *participant,
237 EmpathyCallHandler *self)
239 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
240 GST_ELEMENT (conference));
244 empathy_call_handler_tf_stream_src_pad_added_cb (TfStream *stream,
245 GstPad *pad, FsCodec *codec, EmpathyCallHandler *handler)
249 g_object_get (stream, "media-type", &media_type, NULL);
251 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
257 empathy_call_handler_tf_stream_request_resource_cb (TfStream *stream,
258 guint direction, EmpathyTpCall *call)
264 empathy_call_handler_tf_channel_stream_created_cb (TfChannel *tfchannel,
265 TfStream *stream, EmpathyCallHandler *handler)
270 g_signal_connect (stream, "src-pad-added",
271 G_CALLBACK (empathy_call_handler_tf_stream_src_pad_added_cb), handler);
272 g_signal_connect (stream, "request-resource",
273 G_CALLBACK (empathy_call_handler_tf_stream_request_resource_cb),
276 g_object_get (stream, "media-type", &media_type,
277 "sink-pad", &spad, NULL);
279 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
282 gst_object_unref (spad);
286 empathy_call_handler_tf_channel_closed_cb (TfChannel *tfchannel,
287 EmpathyCallHandler *handler)
289 g_signal_emit (G_OBJECT (handler), signals[CLOSED], 0);
293 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
295 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
298 g_object_get (priv->call, "channel", &channel, NULL);
300 g_assert (channel != NULL);
302 priv->tfchannel = tf_channel_new (channel);
304 /* Set up the telepathy farsight channel */
305 g_signal_connect (priv->tfchannel, "session-created",
306 G_CALLBACK (empathy_call_handler_tf_channel_session_created_cb), self);
307 g_signal_connect (priv->tfchannel, "stream-created",
308 G_CALLBACK (empathy_call_handler_tf_channel_stream_created_cb), self);
309 g_signal_connect (priv->tfchannel, "closed",
310 G_CALLBACK (empathy_call_handler_tf_channel_closed_cb), self);
312 g_object_unref (channel);
316 empathy_call_handler_request_cb (EmpathyDispatchOperation *operation,
317 const GError *error, gpointer user_data)
319 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
320 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
325 priv->call = EMPATHY_TP_CALL (
326 empathy_dispatch_operation_get_channel_wrapper (operation));
328 g_object_ref (priv->call);
330 empathy_call_handler_start_tpfs (self);
332 empathy_tp_call_to (priv->call, priv->contact);
334 empathy_dispatch_operation_claim (operation);
338 empathy_call_handler_contact_ready_cb (EmpathyContact *contact,
339 const GError *error, gpointer user_data, GObject *object)
341 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
342 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
343 EmpathyDispatcher *dispatcher;
347 GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
348 (GDestroyNotify) tp_g_value_slice_free);
350 g_assert (priv->contact != NULL);
352 dispatcher = empathy_dispatcher_dup_singleton ();
353 account = empathy_contact_get_account (priv->contact);
354 allowed = empathy_dispatcher_find_channel_class (dispatcher, account,
355 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT);
357 if (!tp_strv_contains ((const gchar * const *)allowed,
358 TP_IFACE_CHANNEL ".TargetHandle"))
359 g_assert_not_reached ();
361 /* org.freedesktop.Telepathy.Channel.ChannelType */
362 value = tp_g_value_slice_new (G_TYPE_STRING);
363 g_value_set_string (value, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA);
364 g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value);
366 /* org.freedesktop.Telepathy.Channel.TargetHandleType */
367 value = tp_g_value_slice_new (G_TYPE_UINT);
368 g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
369 g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value);
371 /* org.freedesktop.Telepathy.Channel.TargetHandle*/
372 value = tp_g_value_slice_new (G_TYPE_UINT);
373 g_value_set_uint (value, empathy_contact_get_handle (priv->contact));
374 g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
376 empathy_dispatcher_create_channel (dispatcher, account,
377 request, empathy_call_handler_request_cb, self);
379 g_object_unref (dispatcher);
383 empathy_call_handler_start_call (EmpathyCallHandler *handler)
386 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
388 if (priv->call == NULL)
390 empathy_contact_call_when_ready (priv->contact,
391 EMPATHY_CONTACT_READY_HANDLE,
392 empathy_call_handler_contact_ready_cb, NULL, NULL, G_OBJECT (handler));
396 empathy_call_handler_start_tpfs (handler);
397 empathy_tp_call_accept_incoming_call (priv->call);