#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-tp-contact-factory.h>
+#include <libempathy-gtk/empathy-call-utils.h>
+
#include "empathy-call-handler.h"
-#include "empathy-call-factory.h"
-#include "src-marshal.h"
#define DEBUG_FLAG EMPATHY_DEBUG_VOIP
#include <libempathy/empathy-debug.h>
SINK_PAD_REMOVED,
CLOSED,
CANDIDATES_CHANGED,
+ STATE_CHANGED,
LAST_SIGNAL
};
enum {
PROP_CALL_CHANNEL = 1,
PROP_GST_BUS,
+ PROP_CONTACT,
PROP_MEMBERS,
PROP_INITIAL_AUDIO,
PROP_INITIAL_VIDEO,
/* private structure */
-typedef struct {
+struct _EmpathyCallHandlerPriv {
TpyCallChannel *call;
+ EmpathyContact *contact;
/* GArray of TpContacts */
GArray *members;
TfChannel *tfchannel;
FsCandidate *video_remote_candidate;
FsCandidate *audio_local_candidate;
FsCandidate *video_local_candidate;
-} EmpathyCallHandlerPriv;
+};
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
tp_clear_object (&priv->tfchannel);
tp_clear_object (&priv->call);
+ tp_clear_object (&priv->contact);
tp_clear_pointer (&priv->members, g_array_unref);
EmpathyCallHandlerPriv *priv = GET_PRIV (self);
guint i;
- g_print ("\nGot %d EmpathyContacts\n\n", n_contacts);
-
if (n_failed > 0)
g_warning ("Failed to get %d EmpathyContacts: %s",
n_failed, error->message);
g_object_notify (G_OBJECT (self), "members");
}
+static void
+on_call_invalidated_cb (TpyCallChannel *call,
+ guint domain,
+ gint code,
+ gchar *message,
+ EmpathyCallHandler *self)
+{
+ EmpathyCallHandlerPriv *priv = self->priv;
+
+ if (priv->call == call)
+ {
+ /* Invalidated unexpectedly? Fake call ending */
+ g_signal_emit (self, signals[STATE_CHANGED], 0,
+ TPY_CALL_STATE_ENDED, NULL);
+ tp_clear_object (&priv->call);
+ tp_clear_object (&priv->tfchannel);
+ }
+}
+
+static void
+on_call_state_changed_cb (TpyCallChannel *call,
+ TpyCallState state,
+ TpyCallFlags flags,
+ const GValueArray *call_state_reason,
+ GHashTable *call_state_details,
+ EmpathyCallHandler *handler)
+{
+ EmpathyCallHandlerPriv *priv = handler->priv;
+ gchar *dbus_reason;
+ guint actor, reason;
+
+ tp_value_array_unpack ((GValueArray *) call_state_reason, 3,
+ &actor, &reason, &dbus_reason);
+
+ g_signal_emit (handler, signals[STATE_CHANGED], 0, state, dbus_reason);
+
+ if (state == TPY_CALL_STATE_ENDED)
+ {
+ tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
+
+ tp_clear_object (&priv->call);
+ tp_clear_object (&priv->tfchannel);
+ }
+}
+
static void
on_members_changed_cb (TpyCallChannel *call,
GHashTable *members,
guint n_handles;
guint i = 0;
- g_print ("\non_members_changed!\n\n");
-
if (members == NULL)
- {
- g_print ("\nmembers is null!\n\n");
- return;
- }
+ return;
n_handles = g_hash_table_size (members);
- g_print ("\nn_handles: %d\n\n", n_handles);
if (n_handles == 0)
return;
switch (property_id)
{
+ case PROP_CONTACT:
+ priv->contact = g_value_dup_object (value);
+ break;
case PROP_MEMBERS:
priv->members = g_value_get_boxed (value);
break;
case PROP_CALL_CHANNEL:
+ g_return_if_fail (priv->call == NULL);
+
priv->call = g_value_dup_object (value);
+
+ tp_g_signal_connect_object (priv->call, "state-changed",
+ G_CALLBACK (on_call_state_changed_cb), object, 0);
+ tp_g_signal_connect_object (priv->call, "invalidated",
+ G_CALLBACK (on_call_invalidated_cb), object, 0);
break;
case PROP_INITIAL_AUDIO:
priv->initial_audio = g_value_get_boolean (value);
switch (property_id)
{
+ case PROP_CONTACT:
+ g_value_set_object (value, priv->contact);
+ break;
case PROP_MEMBERS:
g_value_set_boxed (value, priv->members);
break;
object_class->dispose = empathy_call_handler_dispose;
object_class->finalize = empathy_call_handler_finalize;
+ param_spec = g_param_spec_object ("target-contact",
+ "TargetContact", "The contact",
+ EMPATHY_TYPE_CONTACT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_CONTACT, param_spec);
+
param_spec = g_param_spec_boxed ("members",
"call members", "The call participants",
G_TYPE_ARRAY,
param_spec = g_param_spec_boolean ("initial-video",
"initial-video", "Whether the call should start with video",
FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
g_object_class_install_property (object_class, PROP_INITIAL_VIDEO,
param_spec);
signals[CONFERENCE_ADDED] =
g_signal_new ("conference-added", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
1, FS_TYPE_CONFERENCE);
signals[CONFERENCE_REMOVED] =
g_signal_new ("conference-removed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
1, FS_TYPE_CONFERENCE);
signals[SRC_PAD_ADDED] =
g_signal_new ("src-pad-added", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- _src_marshal_BOOLEAN__OBJECT_UINT,
+ g_cclosure_marshal_generic,
G_TYPE_BOOLEAN,
2, GST_TYPE_PAD, G_TYPE_UINT);
signals[SINK_PAD_ADDED] =
g_signal_new ("sink-pad-added", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- _src_marshal_BOOLEAN__OBJECT_UINT,
+ g_cclosure_marshal_generic,
G_TYPE_BOOLEAN,
2, GST_TYPE_PAD, G_TYPE_UINT);
signals[SINK_PAD_REMOVED] =
g_signal_new ("sink-pad-removed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- _src_marshal_BOOLEAN__OBJECT_UINT,
+ g_cclosure_marshal_generic,
G_TYPE_BOOLEAN,
2, GST_TYPE_PAD, G_TYPE_UINT);
signals[CLOSED] =
g_signal_new ("closed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
+ g_cclosure_marshal_generic,
G_TYPE_NONE,
0);
signals[CANDIDATES_CHANGED] =
g_signal_new ("candidates-changed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, 0, NULL, NULL,
- g_cclosure_marshal_VOID__UINT,
+ g_cclosure_marshal_generic,
G_TYPE_NONE, 1, G_TYPE_UINT);
+
+ signals[STATE_CHANGED] =
+ g_signal_new ("state-changed", G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING);
}
EmpathyCallHandler *
-empathy_call_handler_new_for_channel (TpyCallChannel *call)
+empathy_call_handler_new_for_channel (TpyCallChannel *call,
+ EmpathyContact *contact)
{
return EMPATHY_CALL_HANDLER (g_object_new (EMPATHY_TYPE_CALL_HANDLER,
"call-channel", call,
"initial-video", tpy_call_channel_has_initial_video (call),
+ "target-contact", contact,
NULL));
}
FsCodec *codec;
FsSession *session;
- g_print ("empathy_call_handler_bus_message: farsight-send-codec-changed\n");
+ DEBUG ("farsight-send-codec-changed");
val = gst_structure_get_value (s, "codec");
codec = g_value_get_boxed (val);
GList *codecs;
FsStream *stream;
- g_print ("empathy_call_handler_bus_message: farsight-recv-codecs-changed\n");
+ DEBUG ("farsight-recv-codecs-changed");
val = gst_structure_get_value (s, "codecs");
codecs = g_value_get_boxed (val);
FsCandidate *remote_candidate, *local_candidate;
FsStream *stream;
- g_print ("empathy_call_handler_bus_message: farsight-new-active-candidate-pair\n");
+ DEBUG ("farsight-new-active-candidate-pair");
val = gst_structure_get_value (s, "remote-candidate");
remote_candidate = g_value_get_boxed (val);
GstPad *spad;
gboolean retval;
- g_print ("removing content\n");
+ DEBUG ("removing content");
g_object_get (content, "media-type", &mtype,
"sink-pad", &spad, NULL);
on_tf_channel_ready, self);
}
-#if 0
+static void
+on_call_accepted_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
+ GError *error = NULL;
+
+ if (!tpy_call_channel_accept_finish (call, res, &error))
+ {
+ g_warning ("could not accept Call: %s", error->message);
+ g_error_free (error);
+ }
+}
+
static void
empathy_call_handler_request_cb (GObject *source,
GAsyncResult *result,
}
priv->call = TPY_CALL_CHANNEL (channel);
+ tp_g_signal_connect_object (priv->call, "state-changed",
+ G_CALLBACK (on_call_state_changed_cb), self, 0);
+ tp_g_signal_connect_object (priv->call, "invalidated",
+ G_CALLBACK (on_call_invalidated_cb), self, 0);
g_object_notify (G_OBJECT (self), "call-channel");
empathy_call_handler_start_tpfs (self);
-}
-#endif
-
-static void
-on_call_accepted_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TpyCallChannel *call = TPY_CALL_CHANNEL (source_object);
- GError *error = NULL;
-
- if (!tpy_call_channel_accept_finish (call, res, &error))
- {
- g_warning ("could not accept Call: %s", error->message);
- g_error_free (error);
- }
+ tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
}
void
gint64 timestamp)
{
EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
-/*TpAccountChannelRequest *req;
+ TpAccountChannelRequest *req;
TpAccount *account;
- GHashTable *request;*/
+ GHashTable *request;
if (priv->call != NULL)
{
tpy_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
return;
}
- else
- {
- g_warning ("No Call channel!");
- }
-#if 0
/* No TpyCallChannel (we are redialing). Request a new call channel */
g_assert (priv->contact != NULL);
account = empathy_contact_get_account (priv->contact);
- request = empathy_call_create_call_request (priv->contact,
+ request = empathy_call_create_call_request (
+ empathy_contact_get_id (priv->contact),
priv->initial_audio, priv->initial_video);
req = tp_account_channel_request_new (account, request, timestamp);
g_object_unref (req);
g_hash_table_unref (request);
-#endif
}
/**
tpy_call_channel_hangup_async (priv->call,
TPY_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
"", "", NULL, NULL);
+ tp_channel_close_async (TP_CHANNEL (priv->call),
+ NULL, NULL);
tp_clear_object (&priv->call);
+ tp_clear_object (&priv->tfchannel);
}
}