summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSjoerd Simons <sjoerd.simons@collabora.co.uk>2008-12-26 21:20:04 (GMT)
committerSjoerd Simons <sjoerd.simons@collabora.co.uk>2008-12-26 21:20:04 (GMT)
commitffec42da207ca7908a86799837c5f4e9d2d10c4b (patch)
tree9c021358be3f2fb9d86128d679df9e39e6e4d5cc
parentdc147922869509b3008e23484f8574a7ffc206d6 (diff)
downloadtictactube-master.tar.gz
tictactube-master.tar.xz
Update for changes in the tubes APIHEADmaster
-rw-r--r--src/ttt-net-stream-tube.c63
1 files changed, 52 insertions, 11 deletions
diff --git a/src/ttt-net-stream-tube.c b/src/ttt-net-stream-tube.c
index b51b817..f302e32 100644
--- a/src/ttt-net-stream-tube.c
+++ b/src/ttt-net-stream-tube.c
@@ -52,6 +52,8 @@ struct _TttNetStreamTubePriv
GIOChannel *channel;
guint event_source;
EmpathyTpTube *tube;
+ gchar *hostname;
+ guint port;
};
enum
@@ -185,6 +187,7 @@ ttt_net_stream_tube_finalize (GObject *object)
TttNetStreamTubePriv *priv = GET_PRIV (object);
g_debug ("TttNetStreamTube - finalize: %p", object);
+ g_free (priv->hostname);
(G_OBJECT_CLASS (ttt_net_stream_tube_parent_class)->finalize) (object);
}
@@ -404,6 +407,20 @@ ttt_net_stream_tube_make_offer (TttNetStreamTube *net,
return TRUE;
}
+static void
+ttt_net_stream_tube_connect (TttNetStreamTube *net)
+{
+ TttNetStreamTubePriv *priv = GET_PRIV (net);
+
+ if (!(priv->socket = gnet_tcp_socket_connect (priv->hostname, priv->port)))
+ g_debug ("TttNetStreamTube - could not connect to %s on port %d",
+ priv->hostname, priv->port);
+
+ priv->channel = gnet_tcp_socket_get_io_channel (priv->socket);
+ priv->event_source = g_io_add_watch (priv->channel, G_IO_IN | G_IO_HUP,
+ ttt_net_stream_tube_channel_cb, (gpointer) net);
+}
+
static void
ttt_net_stream_tube_tube_state_changed_cb (EmpathyTpTube *tube,
@@ -413,27 +430,50 @@ ttt_net_stream_tube_tube_state_changed_cb (EmpathyTpTube *tube,
TttNetStreamTube *net = TTT_NET_STREAM_TUBE (data);
TttNetStreamTubePriv *priv = GET_PRIV (net);
guint state;
- gchar *hostname;
- guint port;
g_object_get (tube, "state", &state, NULL);
if (state != TP_TUBE_STATE_OPEN)
return;
- g_signal_handlers_disconnect_by_func (tube,
+ g_signal_handlers_disconnect_by_func (priv->tube,
ttt_net_stream_tube_tube_state_changed_cb, net);
- empathy_tp_tube_get_socket (priv->tube, &hostname, &port);
- if (!(priv->socket = gnet_tcp_socket_connect (hostname, port)))
- g_debug ("TttNetStreamTube - could not connect to %s on port %d",
- hostname, port);
+ if (priv->hostname == NULL)
+ return;
- priv->channel = gnet_tcp_socket_get_io_channel (priv->socket);
- priv->event_source = g_io_add_watch (priv->channel, G_IO_IN | G_IO_HUP,
- ttt_net_stream_tube_channel_cb, (gpointer) net);
+ ttt_net_stream_tube_connect (net);
}
+static void
+ttt_net_stream_tube_accept_stream_tube_cb (EmpathyTpTube *tube,
+ const EmpathyTpTubeAddress *address, const GError *error, gpointer user_data)
+{
+ TttNetStreamTube *net = TTT_NET_STREAM_TUBE (user_data);
+ TttNetStreamTubePriv *priv = GET_PRIV (net);
+ guint state;
+
+ if (error != NULL)
+ {
+ /* FIXME present a sad face to the user */
+ printf ("Something went wrong :( : %s",
+ error->message);
+ return;
+ }
+
+ g_assert (address->type == TP_SOCKET_ADDRESS_TYPE_IPV4);
+
+ priv->hostname = g_strdup (address->a.inet.hostname);
+ priv->port = address->a.inet.port;
+
+ g_object_get (tube, "state", &state, NULL);
+
+ /* FIXME handle cases where tube went into an error condition */
+ if (state != TP_TUBE_STATE_OPEN)
+ return;
+
+ ttt_net_stream_tube_connect (net);
+}
gboolean
ttt_net_stream_tube_accept_offer (TttNetStreamTube *net,
@@ -447,7 +487,8 @@ ttt_net_stream_tube_accept_offer (TttNetStreamTube *net,
g_signal_connect (G_OBJECT (priv->tube), "notify::state",
G_CALLBACK (ttt_net_stream_tube_tube_state_changed_cb), (gpointer) net);
- empathy_tp_tube_accept_stream_tube (priv->tube, TP_SOCKET_ADDRESS_TYPE_IPV4);
+ empathy_tp_tube_accept_stream_tube (priv->tube, TP_SOCKET_ADDRESS_TYPE_IPV4,
+ ttt_net_stream_tube_accept_stream_tube_cb, net);
return TRUE;
}