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
26 #include <telepathy-glib/telepathy-glib.h>
28 #include <libempathy/empathy-client-factory.h>
29 #include <libempathy/empathy-request-util.h>
30 #include <libempathy/empathy-utils.h>
32 #include "empathy-call-factory.h"
33 #include "empathy-call-handler.h"
35 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
36 #include <libempathy/empathy-debug.h>
38 G_DEFINE_TYPE(EmpathyCallFactory
, empathy_call_factory
, TP_TYPE_BASE_CLIENT
)
40 static void handle_channels (TpBaseClient
*client
,
42 TpConnection
*connection
,
44 GList
*requests_satisfied
,
45 gint64 user_action_time
,
46 TpHandleChannelsContext
*context
);
48 static void approve_channels (TpBaseClient
*client
,
50 TpConnection
*connection
,
52 TpChannelDispatchOperation
*dispatch_operation
,
53 TpAddDispatchOperationContext
*context
);
63 static guint signals
[LAST_SIGNAL
] = {0};
65 static GObject
*call_factory
= NULL
;
68 empathy_call_factory_init (EmpathyCallFactory
*obj
)
70 TpBaseClient
*client
= (TpBaseClient
*) obj
;
72 tp_base_client_take_approver_filter (client
, tp_asv_new (
73 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
74 TP_IFACE_CHANNEL_TYPE_CALL
,
75 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
,
76 G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
79 tp_base_client_take_handler_filter (client
, tp_asv_new (
80 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
81 TP_IFACE_CHANNEL_TYPE_CALL
,
82 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
,
83 G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
86 tp_base_client_take_handler_filter (client
, tp_asv_new (
87 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
88 TP_IFACE_CHANNEL_TYPE_CALL
,
89 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
,
90 G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
91 TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO
, G_TYPE_BOOLEAN
, TRUE
,
94 tp_base_client_take_handler_filter (client
, tp_asv_new (
95 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
96 TP_IFACE_CHANNEL_TYPE_CALL
,
97 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE
,
98 G_TYPE_UINT
, TP_HANDLE_TYPE_CONTACT
,
99 TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO
, G_TYPE_BOOLEAN
, TRUE
,
102 tp_base_client_add_handler_capabilities_varargs (client
,
103 "org.freedesktop.Telepathy.Channel.Type.Call1/audio",
104 "org.freedesktop.Telepathy.Channel.Type.Call1/video",
105 "org.freedesktop.Telepathy.Channel.Type.Call1/ice",
106 "org.freedesktop.Telepathy.Channel.Type.Call1/gtalk-p2p",
107 "org.freedesktop.Telepathy.Channel.Type.Call1/video/h264",
112 empathy_call_factory_constructor (GType type
, guint n_construct_params
,
113 GObjectConstructParam
*construct_params
)
115 g_return_val_if_fail (call_factory
== NULL
, NULL
);
117 call_factory
= G_OBJECT_CLASS (empathy_call_factory_parent_class
)->constructor
118 (type
, n_construct_params
, construct_params
);
119 g_object_add_weak_pointer (call_factory
, (gpointer
)&call_factory
);
125 empathy_call_factory_class_init (EmpathyCallFactoryClass
*klass
)
127 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
128 TpBaseClientClass
*base_clt_cls
= TP_BASE_CLIENT_CLASS (klass
);
130 object_class
->constructor
= empathy_call_factory_constructor
;
132 base_clt_cls
->handle_channels
= handle_channels
;
133 base_clt_cls
->add_dispatch_operation
= approve_channels
;
135 signals
[NEW_CALL_HANDLER
] =
136 g_signal_new ("new-call-handler",
137 G_TYPE_FROM_CLASS (klass
),
138 G_SIGNAL_RUN_LAST
, 0,
140 g_cclosure_marshal_generic
,
142 2, EMPATHY_TYPE_CALL_HANDLER
, G_TYPE_BOOLEAN
);
144 signals
[INCOMING_CALL
] =
145 g_signal_new ("incoming-call",
146 G_TYPE_FROM_CLASS (klass
),
147 G_SIGNAL_RUN_LAST
, 0,
149 g_cclosure_marshal_generic
,
151 4, G_TYPE_UINT
, TP_TYPE_CALL_CHANNEL
,
152 TP_TYPE_CHANNEL_DISPATCH_OPERATION
,
153 TP_TYPE_ADD_DISPATCH_OPERATION_CONTEXT
);
157 empathy_call_factory_initialise (void)
159 EmpathyCallFactory
*self
;
160 EmpathyClientFactory
*factory
;
161 TpAccountManager
*am
;
163 g_return_val_if_fail (call_factory
== NULL
, NULL
);
165 am
= tp_account_manager_dup ();
166 factory
= empathy_client_factory_dup ();
168 self
= EMPATHY_CALL_FACTORY (g_object_new (EMPATHY_TYPE_CALL_FACTORY
,
169 "account-manager", am
,
171 "name", EMPATHY_CALL_BUS_NAME_SUFFIX
,
175 g_object_unref (factory
);
181 empathy_call_factory_get (void)
183 g_return_val_if_fail (call_factory
!= NULL
, NULL
);
185 return EMPATHY_CALL_FACTORY (call_factory
);
189 handle_channels (TpBaseClient
*client
,
191 TpConnection
*connection
,
193 GList
*requests_satisfied
,
194 gint64 user_action_time
,
195 TpHandleChannelsContext
*context
)
197 EmpathyCallFactory
*self
= EMPATHY_CALL_FACTORY (client
);
200 for (l
= channels
; l
!= NULL
; l
= g_list_next (l
))
202 TpChannel
*channel
= l
->data
;
204 TpContact
*tp_contact
;
205 EmpathyContact
*contact
;
206 EmpathyCallHandler
*handler
;
208 if (tp_proxy_get_invalidated (channel
) != NULL
)
211 if (tp_channel_get_channel_type_id (channel
) !=
212 TP_IFACE_QUARK_CHANNEL_TYPE_CALL
)
215 if (!TP_IS_CALL_CHANNEL (channel
))
218 call
= TP_CALL_CHANNEL (channel
);
220 tp_contact
= tp_channel_get_target_contact (channel
);
221 contact
= empathy_contact_dup_from_tp_contact (tp_contact
);
222 handler
= empathy_call_handler_new_for_channel (call
, contact
);
224 g_signal_emit (self
, signals
[NEW_CALL_HANDLER
], 0,
227 g_object_unref (handler
);
228 g_object_unref (contact
);
231 tp_handle_channels_context_accept (context
);
234 static TpCallChannel
*
235 find_call_channel (GList
*channels
)
239 for (l
= channels
; l
!= NULL
; l
= g_list_next (l
))
241 TpChannel
*channel
= l
->data
;
244 if (tp_proxy_get_invalidated (channel
) != NULL
)
247 channel_type
= tp_channel_get_channel_type_id (channel
);
249 if (channel_type
== TP_IFACE_QUARK_CHANNEL_TYPE_CALL
)
250 return TP_CALL_CHANNEL (channel
);
257 approve_channels (TpBaseClient
*client
,
259 TpConnection
*connection
,
261 TpChannelDispatchOperation
*dispatch_operation
,
262 TpAddDispatchOperationContext
*context
)
264 EmpathyCallFactory
*self
= EMPATHY_CALL_FACTORY (client
);
265 TpCallChannel
*channel
;
267 GError error
= { TP_ERROR
, TP_ERROR_INVALID_ARGUMENT
, "" };
268 gboolean handled
= FALSE
;
270 channel
= find_call_channel (channels
);
274 DEBUG ("Failed to find the main channel; ignoring");
275 error
.message
= "Unknown channel";
279 handle
= tp_channel_get_handle (TP_CHANNEL (channel
), NULL
);
283 DEBUG ("Unknown handle, ignoring");
284 error
.code
= TP_ERROR_INVALID_HANDLE
;
285 error
.message
= "Unknown handle";
289 g_signal_emit (self
, signals
[INCOMING_CALL
], 0,
290 handle
, channel
, dispatch_operation
, context
,
296 /* There was no call window so the context wasn't handled. */
297 DEBUG ("Call with a contact for which there's no existing "
298 "call window, ignoring");
299 error
.message
= "No call window with this contact";
302 tp_add_dispatch_operation_context_fail (context
, &error
);
306 empathy_call_factory_register (EmpathyCallFactory
*self
,
309 return tp_base_client_register (TP_BASE_CLIENT (self
), error
);