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/simple-handler.h>
26 #include <telepathy-glib/interfaces.h>
27 #include <telepathy-glib/util.h>
29 #include "empathy-dispatcher.h"
30 #include "empathy-marshal.h"
31 #include "empathy-call-factory.h"
32 #include "empathy-utils.h"
34 G_DEFINE_TYPE(EmpathyCallFactory, empathy_call_factory, G_TYPE_OBJECT)
36 static void handle_channels_cb (TpSimpleHandler *handler,
38 TpConnection *connection,
40 GList *requests_satisfied,
41 gint64 user_action_time,
42 TpHandleChannelsContext *context,
52 static guint signals[LAST_SIGNAL] = {0};
54 /* private structure */
56 TpBaseClient *handler;
57 gboolean dispose_has_run;
58 } EmpathyCallFactoryPriv;
60 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallFactory)
62 static GObject *call_factory = NULL;
65 empathy_call_factory_init (EmpathyCallFactory *obj)
67 EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
68 EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
74 dbus = tp_dbus_daemon_dup (&error);
77 g_warning ("Failed to get TpDBusDaemon: %s", error->message);
82 priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
83 "Empathy.AudioVideo", FALSE, handle_channels_cb, obj, NULL);
85 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
86 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
87 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
88 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
91 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
92 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
93 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
94 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
95 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN, TRUE,
98 tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
99 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
100 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
101 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
102 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN, TRUE,
105 tp_base_client_add_handler_capabilities_varargs (priv->handler,
106 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/ice-udp",
107 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/gtalk-p2p",
108 "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
111 g_object_unref (dbus);
115 empathy_call_factory_constructor (GType type, guint n_construct_params,
116 GObjectConstructParam *construct_params)
118 g_return_val_if_fail (call_factory == NULL, NULL);
120 call_factory = G_OBJECT_CLASS (empathy_call_factory_parent_class)->constructor
121 (type, n_construct_params, construct_params);
122 g_object_add_weak_pointer (call_factory, (gpointer)&call_factory);
128 empathy_call_factory_finalize (GObject *object)
130 /* free any data held directly by the object here */
132 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize)
133 G_OBJECT_CLASS (empathy_call_factory_parent_class)->finalize (object);
137 empathy_call_factory_dispose (GObject *object)
139 EmpathyCallFactoryPriv *priv = GET_PRIV (object);
141 if (priv->dispose_has_run)
144 priv->dispose_has_run = TRUE;
146 /* release any references held by the object here */
148 if (G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose)
149 G_OBJECT_CLASS (empathy_call_factory_parent_class)->dispose (object);
153 empathy_call_factory_class_init (
154 EmpathyCallFactoryClass *empathy_call_factory_class)
156 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_factory_class);
158 g_type_class_add_private (empathy_call_factory_class,
159 sizeof (EmpathyCallFactoryPriv));
161 object_class->constructor = empathy_call_factory_constructor;
162 object_class->dispose = empathy_call_factory_dispose;
163 object_class->finalize = empathy_call_factory_finalize;
165 signals[NEW_CALL_HANDLER] =
166 g_signal_new ("new-call-handler",
167 G_TYPE_FROM_CLASS (empathy_call_factory_class),
168 G_SIGNAL_RUN_LAST, 0,
170 _empathy_marshal_VOID__OBJECT_BOOLEAN,
172 2, EMPATHY_TYPE_CALL_HANDLER, G_TYPE_BOOLEAN);
176 empathy_call_factory_initialise (void)
178 g_return_val_if_fail (call_factory == NULL, NULL);
180 return EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY, NULL));
184 empathy_call_factory_get (void)
186 g_return_val_if_fail (call_factory != NULL, NULL);
188 return EMPATHY_CALL_FACTORY (call_factory);
192 * empathy_call_factory_new_call_with_streams:
193 * @factory: an #EmpathyCallFactory
194 * @contact: an #EmpathyContact
195 * @initial_audio: if %TRUE the call will be started with audio
196 * @initial_video: if %TRUE the call will be started with video
198 * Initiate a new call with @contact.
201 empathy_call_factory_new_call_with_streams (EmpathyContact *contact,
202 gboolean initial_audio,
203 gboolean initial_video,
205 EmpathyDispatcherRequestCb callback,
208 EmpathyDispatcher *dispatcher;
211 request = tp_asv_new (
212 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
213 TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
214 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
215 TP_PROP_CHANNEL_TARGET_HANDLE, G_TYPE_UINT,
216 empathy_contact_get_handle (contact),
217 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_AUDIO, G_TYPE_BOOLEAN,
219 TP_PROP_CHANNEL_TYPE_STREAMED_MEDIA_INITIAL_VIDEO, G_TYPE_BOOLEAN,
223 dispatcher = empathy_dispatcher_dup_singleton ();
225 empathy_dispatcher_create_channel (dispatcher,
226 empathy_contact_get_connection (contact), request, timestamp, callback,
229 g_object_unref (dispatcher);
233 create_call_handler (EmpathyCallFactory *factory,
236 EmpathyCallHandler *handler;
238 g_return_if_fail (factory != NULL);
240 handler = empathy_call_handler_new_for_channel (call);
242 g_signal_emit (factory, signals[NEW_CALL_HANDLER], 0,
245 g_object_unref (handler);
249 call_status_changed_cb (EmpathyTpCall *call,
251 EmpathyCallFactory *self)
253 if (empathy_tp_call_get_status (call) <= EMPATHY_TP_CALL_STATUS_READYING)
256 create_call_handler (self, call);
258 g_signal_handlers_disconnect_by_func (call, call_status_changed_cb, self);
259 g_object_unref (call);
263 handle_channels_cb (TpSimpleHandler *handler,
265 TpConnection *connection,
267 GList *requests_satisfied,
268 gint64 user_action_time,
269 TpHandleChannelsContext *context,
272 EmpathyCallFactory *self = user_data;
275 for (l = channels; l != NULL; l = g_list_next (l))
277 TpChannel *channel = l->data;
280 if (tp_proxy_get_invalidated (channel) != NULL)
283 if (tp_channel_get_channel_type_id (channel) !=
284 TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
287 call = empathy_tp_call_new (channel);
289 if (empathy_tp_call_get_status (call) <= EMPATHY_TP_CALL_STATUS_READYING)
291 /* We have to wait that the TpCall is ready as the
292 * call-handler rely on it. */
293 tp_g_signal_connect_object (call, "notify::status",
294 G_CALLBACK (call_status_changed_cb), self, 0);
298 create_call_handler (self, call);
299 g_object_unref (call);
302 tp_handle_channels_context_accept (context);
306 empathy_call_factory_register (EmpathyCallFactory *self,
309 EmpathyCallFactoryPriv *priv = GET_PRIV (self);
311 return tp_base_client_register (priv->handler, error);