diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2010-04-21 14:48:28 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2010-04-22 11:04:58 +0100 |
commit | 50cc4015c061d7d36dd190877b5a5d89596003dc (patch) | |
tree | 137843f8573936a02b3fa820a9a92d6f1396cd98 | |
parent | d662ebdf0a4c5c68dbac0df875d6fdcedcdf15ab (diff) |
Cork presence updates on Google Talk connections
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/conn-slacker.c | 107 | ||||
-rw-r--r-- | src/conn-slacker.h | 36 | ||||
-rw-r--r-- | src/connection.c | 3 | ||||
-rw-r--r-- | src/connection.h | 4 | ||||
-rw-r--r-- | src/namespaces.h | 1 |
6 files changed, 153 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 60dd361ae..e0633fda9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -45,6 +45,8 @@ libgabble_convenience_la_SOURCES = \ conn-olpc.c \ conn-presence.h \ conn-presence.c \ + conn-slacker.h \ + conn-slacker.c \ connection.h \ connection.c \ connection-manager.h \ diff --git a/src/conn-slacker.c b/src/conn-slacker.c new file mode 100644 index 000000000..6d7aca8eb --- /dev/null +++ b/src/conn-slacker.c @@ -0,0 +1,107 @@ +/* + * conn-slacker.h - Header for Gabble connection code handling device idleness + * Copyright (C) 2010 Collabora Ltd. + * Copyright (C) 2010 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "conn-slacker.h" + +#define DEBUG_FLAG GABBLE_DEBUG_CONNECTION +#include "debug.h" +#include "namespaces.h" +#include "util.h" + +static void +conn_slacker_update_inactivity ( + GabbleConnection *conn, + gboolean is_inactive) +{ + LmMessage *command; + + if (DEBUGGING) + { + gchar *jid = gabble_connection_get_full_jid (conn); + + DEBUG ("device became %sactive; %sabling presence queueing for %s", + is_inactive ? "in" : "", + is_inactive ? "en" : "dis", + jid); + g_free (jid); + } + + command = lm_message_build_with_sub_type (NULL, + LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET, + '(', "query", "", + '@', "xmlns", NS_GOOGLE_QUEUE, + '(', (is_inactive ? "enable" : "disable"), "", ')', + ')', + NULL); + _gabble_connection_send_with_reply (conn, command, NULL, NULL, NULL, NULL); + lm_message_unref (command); +} + +static void +conn_slacker_inactivity_changed_cb ( + GabbleSlacker *slacker, + gboolean is_inactive, + gpointer user_data) +{ + GabbleConnection *conn = GABBLE_CONNECTION (user_data); + + conn_slacker_update_inactivity (conn, is_inactive); +} + +void +gabble_connection_slacker_start (GabbleConnection *conn) +{ + GabbleSlacker *s; + + /* We can only cork presence updates on Google Talk. Of course, the Google + * Talk server doesn't advertise support for google:queue. So let's use the + * roster again... */ + if (!(conn->features & GABBLE_CONNECTION_FEATURES_GOOGLE_ROSTER)) + return; + + s = conn->slacker = gabble_slacker_new (); + + /* In the unlikely event of having to use an escape slide... */ + if (G_UNLIKELY (s == NULL)) + return; + + conn->slacker_inactivity_changed_id = g_signal_connect (s, + "inactivity-changed", (GCallback) conn_slacker_inactivity_changed_cb, + conn); + + /* If we're already inactive, let's cork right away. (I guess the connection + * flaked out in the user's pocket?) */ + if (gabble_slacker_is_inactive (s)) + conn_slacker_update_inactivity (conn, TRUE); +} + +void +gabble_connection_slacker_stop (GabbleConnection *conn) +{ + if (conn->slacker != NULL) + { + g_signal_handler_disconnect (conn->slacker, + conn->slacker_inactivity_changed_id); + conn->slacker_inactivity_changed_id = 0; + + g_object_unref (conn->slacker); + conn->slacker = NULL; + } +} diff --git a/src/conn-slacker.h b/src/conn-slacker.h new file mode 100644 index 000000000..c38d6cfce --- /dev/null +++ b/src/conn-slacker.h @@ -0,0 +1,36 @@ +/* + * conn-slacker.h - Header for Gabble connection code handling device idleness + * Copyright (C) 2010 Collabora Ltd. + * Copyright (C) 2010 Nokia Corporation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef GABBLE_CONN_SLACKER_H +#define GABBLE_CONN_SLACKER_H + +#include <glib.h> + +#include "connection.h" + +G_BEGIN_DECLS + +void gabble_connection_slacker_start (GabbleConnection *conn); +void gabble_connection_slacker_stop (GabbleConnection *conn); + +G_END_DECLS + +#endif /* GABBLE_CONN_SLACKER_H */ + diff --git a/src/connection.c b/src/connection.c index 907884f25..84011ec1e 100644 --- a/src/connection.c +++ b/src/connection.c @@ -53,6 +53,7 @@ #include "conn-location.h" #include "conn-presence.h" #include "conn-olpc.h" +#include "conn-slacker.h" #include "debug.h" #include "disco.h" #include "media-channel.h" @@ -624,6 +625,7 @@ base_connected_cb (TpBaseConnection *base_conn) GabbleConnection *conn = GABBLE_CONNECTION (base_conn); gabble_connection_connected_olpc (conn); + gabble_connection_slacker_start (conn); } static void @@ -1546,6 +1548,7 @@ connection_shut_down (TpBaseConnection *base) g_assert (GABBLE_IS_CONNECTION (conn)); cancel_connect_timeout (conn); + gabble_connection_slacker_stop (conn); /* If we're shutting down by user request, we don't want to be * unreffed until the LM connection actually closes; the event handler diff --git a/src/connection.h b/src/connection.h index b2a47d0d0..ba4ecce69 100644 --- a/src/connection.h +++ b/src/connection.h @@ -34,6 +34,7 @@ #include "jingle-factory.h" #include "muc-factory.h" #include "olpc-gadget-manager.h" +#include "slacker.h" #include "types.h" G_BEGIN_DECLS @@ -173,6 +174,9 @@ struct _GabbleConnection { GPtrArray *channel_requests; gboolean has_tried_connection; + GabbleSlacker *slacker; + guint slacker_inactivity_changed_id; + GabbleConnectionPrivate *priv; }; diff --git a/src/namespaces.h b/src/namespaces.h index fdf9ad8ab..5219b1e20 100644 --- a/src/namespaces.h +++ b/src/namespaces.h @@ -36,6 +36,7 @@ #define NS_GOOGLE_FEAT_VIDEO "http://www.google.com/xmpp/protocol/video/v1" #define NS_GOOGLE_JINGLE_INFO "google:jingleinfo" #define NS_GOOGLE_ROSTER "google:roster" +#define NS_GOOGLE_QUEUE "google:queue" #define NS_IBB "http://jabber.org/protocol/ibb" /* Namespaces for XEP-0166 draft v0.15, the most capable Jingle dialect |