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"
34 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
45 static guint signals[LAST_SIGNAL] = {0};
53 /* private structure */
54 typedef struct _EmpathyCallHandlerPriv EmpathyCallHandlerPriv;
56 struct _EmpathyCallHandlerPriv
58 gboolean dispose_has_run;
60 EmpathyContact *contact;
66 (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_HANDLER,\
67 EmpathyCallHandlerPriv))
70 empathy_call_handler_init (EmpathyCallHandler *obj)
72 //EmpathyCallHandlerPriv *priv = GET_PRIV (obj);
74 /* allocate any data required by the object here */
77 static void empathy_call_handler_dispose (GObject *object);
78 static void empathy_call_handler_finalize (GObject *object);
81 empathy_call_handler_set_property (GObject *object,
82 guint property_id, const GValue *value, GParamSpec *pspec)
84 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
89 priv->contact = g_value_dup_object (value);
92 priv->call = g_value_dup_object (value);
95 priv->bus = g_value_dup_object (value);
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
103 empathy_call_handler_get_property (GObject *object,
104 guint property_id, GValue *value, GParamSpec *pspec)
106 EmpathyCallHandlerPriv *priv = GET_PRIV (object);
111 g_value_set_object (value, priv->contact);
114 g_value_set_object (value, priv->call);
117 g_value_set_object (value, priv->bus);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
126 empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 GParamSpec *param_spec;
131 g_type_class_add_private (klass, sizeof (EmpathyCallHandlerPriv));
133 object_class->set_property = empathy_call_handler_set_property;
134 object_class->get_property = empathy_call_handler_get_property;
135 object_class->dispose = empathy_call_handler_dispose;
136 object_class->finalize = empathy_call_handler_finalize;
138 param_spec = g_param_spec_object ("contact",
139 "contact", "The remote contact",
140 EMPATHY_TYPE_CONTACT,
141 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
142 g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
144 param_spec = g_param_spec_object ("gst-bus",
145 "gst-bus", "The gstreamer bus",
147 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
148 g_object_class_install_property (object_class, PROP_GST_BUS, param_spec);
150 param_spec = g_param_spec_object ("tp-call",
151 "tp-call", "The calls channel wrapper",
152 EMPATHY_TYPE_TP_CALL,
153 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
154 g_object_class_install_property (object_class, PROP_TP_CALL, param_spec);
156 signals[CONFERENCE_ADDED] =
157 g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
158 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
159 g_cclosure_marshal_VOID__OBJECT,
161 1, FS_TYPE_CONFERENCE);
163 signals[SRC_PAD_ADDED] =
164 g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
165 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
166 _empathy_marshal_VOID__OBJECT_UINT,
168 2, GST_TYPE_PAD, G_TYPE_UINT);
170 signals[SINK_PAD_ADDED] =
171 g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
172 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
173 _empathy_marshal_VOID__OBJECT_UINT,
175 2, GST_TYPE_PAD, G_TYPE_UINT);
179 empathy_call_handler_dispose (GObject *object)
181 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
182 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
184 if (priv->dispose_has_run)
187 priv->dispose_has_run = TRUE;
189 if (priv->contact != NULL)
190 g_object_unref (priv->contact);
192 /* FIXME close the call ? */
193 if (priv->call != NULL)
195 empathy_tp_call_close (priv->call);
196 g_object_unref (priv->call);
201 /* release any references held by the object here */
202 if (G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose)
203 G_OBJECT_CLASS (empathy_call_handler_parent_class)->dispose (object);
207 empathy_call_handler_finalize (GObject *object)
209 //EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
210 //EmpathyCallHandlerPriv *priv = GET_PRIV (self);
212 /* free any data held directly by the object here */
214 G_OBJECT_CLASS (empathy_call_handler_parent_class)->finalize (object);
218 empathy_call_handler_new_for_contact (EmpathyContact *contact)
220 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
221 "contact", contact, NULL));
225 empathy_call_handler_new_for_channel (EmpathyTpCall *call)
227 return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
228 "tp-call", call, NULL));
232 empathy_call_handler_pipeline_bus_watch (GstBus *bus, GstMessage *message,
235 EmpathyCallHandler *handler = EMPATHY_CALL_HANDLER (user_data);
236 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
238 g_assert (priv->tfchannel != NULL);
240 tf_channel_bus_message (priv->tfchannel, message);
246 empathy_call_handler_tf_channel_session_created_cb (TfChannel *tfchannel,
247 FsConference *conference, FsParticipant *participant,
248 EmpathyCallHandler *self)
250 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
252 //gst_bus_enable_essage_emission (priv->bus);
254 gst_bus_add_watch (priv->bus, empathy_call_handler_pipeline_bus_watch, self);
256 g_signal_emit (G_OBJECT (self), signals[CONFERENCE_ADDED], 0,
257 GST_ELEMENT (conference));
261 empathy_call_handler_tf_stream_src_pad_added_cb (TfStream *stream,
262 GstPad *pad, FsCodec *codec, EmpathyCallHandler *handler)
266 g_object_get (stream, "media-type", &media_type, NULL);
268 g_signal_emit (G_OBJECT (handler), signals[SRC_PAD_ADDED], 0,
274 empathy_call_handler_tf_stream_request_resource_cb (TfStream *stream,
275 guint direction, EmpathyTpCall *call)
281 empathy_call_handler_tf_channel_stream_created_cb (TfChannel *tfchannel,
282 TfStream *stream, EmpathyCallHandler *handler)
287 g_signal_connect (stream, "src-pad-added",
288 G_CALLBACK (empathy_call_handler_tf_stream_src_pad_added_cb), handler);
289 g_signal_connect (stream, "request-resource",
290 G_CALLBACK (empathy_call_handler_tf_stream_request_resource_cb),
293 g_object_get (stream, "media-type", &media_type,
294 "sink-pad", &spad, NULL);
296 g_signal_emit (G_OBJECT (handler), signals[SINK_PAD_ADDED], 0,
299 gst_object_unref (spad);
303 empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
305 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
308 g_object_get (priv->call, "channel", &channel, NULL);
310 g_assert (channel != NULL);
312 priv->tfchannel = tf_channel_new (channel);
314 /* Set up the telepathy farsight channel */
315 g_signal_connect (priv->tfchannel, "session-created",
316 G_CALLBACK (empathy_call_handler_tf_channel_session_created_cb), self);
317 g_signal_connect (priv->tfchannel, "stream-created",
318 G_CALLBACK (empathy_call_handler_tf_channel_stream_created_cb), self);
320 g_object_unref (channel);
324 empathy_call_handler_request_cb (EmpathyDispatchOperation *operation,
325 const GError *error, gpointer user_data)
327 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (user_data);
328 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
333 priv->call = EMPATHY_TP_CALL (
334 empathy_dispatch_operation_get_channel_wrapper (operation));
336 g_object_ref (priv->call);
338 empathy_call_handler_start_tpfs (self);
340 empathy_tp_call_to (priv->call, priv->contact);
342 empathy_dispatch_operation_claim (operation);
346 empathy_call_handler_contact_ready_cb (EmpathyContact *contact,
347 const GError *error, gpointer user_data, GObject *object)
349 EmpathyCallHandler *self = EMPATHY_CALL_HANDLER (object);
350 EmpathyCallHandlerPriv *priv = GET_PRIV (self);
351 EmpathyDispatcher *dispatcher;
355 GHashTable *request = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
356 (GDestroyNotify) tp_g_value_slice_free);
358 g_assert (priv->contact != NULL);
360 dispatcher = empathy_dispatcher_dup_singleton ();
361 account = empathy_contact_get_account (priv->contact);
362 allowed = empathy_dispatcher_find_channel_class (dispatcher, account,
363 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA, TP_HANDLE_TYPE_CONTACT);
365 if (!tp_strv_contains ((const gchar * const *)allowed,
366 TP_IFACE_CHANNEL ".TargetHandle"))
367 g_assert_not_reached ();
369 /* org.freedesktop.Telepathy.Channel.ChannelType */
370 value = tp_g_value_slice_new (G_TYPE_STRING);
371 g_value_set_string (value, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA);
372 g_hash_table_insert (request, TP_IFACE_CHANNEL ".ChannelType", value);
374 /* org.freedesktop.Telepathy.Channel.TargetHandleType */
375 value = tp_g_value_slice_new (G_TYPE_UINT);
376 g_value_set_uint (value, TP_HANDLE_TYPE_CONTACT);
377 g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandleType", value);
379 /* org.freedesktop.Telepathy.Channel.TargetHandle*/
380 value = tp_g_value_slice_new (G_TYPE_UINT);
381 g_value_set_uint (value, empathy_contact_get_handle (priv->contact));
382 g_hash_table_insert (request, TP_IFACE_CHANNEL ".TargetHandle", value);
384 empathy_dispatcher_create_channel (dispatcher, account,
385 request, empathy_call_handler_request_cb, self);
387 g_object_unref (dispatcher);
391 empathy_call_handler_start_call (EmpathyCallHandler *handler)
394 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
396 if (priv->call == NULL)
398 empathy_contact_call_when_ready (priv->contact,
399 EMPATHY_CONTACT_READY_ID,
400 empathy_call_handler_contact_ready_cb, NULL, NULL, G_OBJECT (handler));
404 empathy_call_handler_start_tpfs (handler);
405 empathy_tp_call_accept_incoming_call (priv->call);
410 empathy_call_handler_set_bus (EmpathyCallHandler *handler, GstBus *bus)
412 EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
414 g_assert (priv->bus == NULL);
416 priv->bus = g_object_ref (bus);