summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-09-23 12:24:36 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2011-09-28 16:29:18 +0100
commit9da0c6c713c9cba1ddef33d599888fce16b79482 (patch)
treeb2855f518c776a255e00c30abb84f651a7ba44b5
parent17246cccff176888eae16b8ce673e2c5f0da440f (diff)
Connectivity: go offline when laptop suspends.
Woop woop.
-rw-r--r--src/Makefile.am5
-rw-r--r--src/connectivity-monitor.c70
-rw-r--r--src/kludge-transport.c2
3 files changed, 74 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 61de2bde..781bdef3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ INCLUDES = \
$(GLIB_CFLAGS) \
$(NETWORK_MANAGER_CFLAGS) \
$(CONNMAN_CFLAGS) \
+ $(UPOWER_GLIB_CFLAGS) \
-DG_LOG_DOMAIN=\"mcd\" \
-DMCD_PLUGIN_LOADER_DIR=\"@libdir@/mission-control-plugins.@MCP_ABI_VERSION@\" \
-DMC_DISABLE_DEPRECATED -I$(top_srcdir)
@@ -101,7 +102,9 @@ libmcd_convenience_la_LIBADD = \
$(DBUS_LIBS) \
$(GLIB_LIBS) \
$(NETWORK_MANAGER_LIBS) \
- $(CONNMAN_LIBS)
+ $(CONNMAN_LIBS) \
+ $(UPOWER_GLIB_LIBS) \
+ $(NULL)
if ENABLE_GNOME_KEYRING
libmcd_convenience_la_LIBADD += $(GNOME_KEYRING_LIBS)
diff --git a/src/connectivity-monitor.c b/src/connectivity-monitor.c
index 3235f776..0756d5a9 100644
--- a/src/connectivity-monitor.c
+++ b/src/connectivity-monitor.c
@@ -38,6 +38,10 @@
#include <dbus/dbus-glib.h>
#endif
+#ifdef HAVE_UPOWER
+#include <upower.h>
+#endif
+
#include <telepathy-glib/util.h>
#include "mcd-debug.h"
@@ -52,8 +56,15 @@ struct _McdConnectivityMonitorPrivate {
DBusGProxy *proxy;
#endif
+#ifdef HAVE_UPOWER
+ UpClient *upower_client;
+#endif
+
gboolean connected;
gboolean use_conn;
+
+ /* TRUE if the device is not suspended; FALSE while it is. */
+ gboolean awake;
};
enum {
@@ -85,7 +96,23 @@ connectivity_monitor_change_state (McdConnectivityMonitor *connectivity_monitor,
priv->connected = new_state;
g_signal_emit (connectivity_monitor, signals[STATE_CHANGE], 0,
- priv->connected);
+ priv->connected && priv->awake);
+}
+
+static void
+connectivity_monitor_set_awake (
+ McdConnectivityMonitor *self,
+ gboolean awake)
+{
+ McdConnectivityMonitorPrivate *priv = self->priv;
+
+ if (priv->awake == awake)
+ return;
+
+ priv->awake = awake;
+
+ g_signal_emit (self, signals[STATE_CHANGE], 0,
+ priv->connected && priv->awake);
}
#ifdef HAVE_NM
@@ -181,6 +208,32 @@ connectivity_monitor_connman_check_state (McdConnectivityMonitor *connectivity_m
}
#endif
+#ifdef HAVE_UPOWER
+static void
+notify_sleep_cb (
+ UpClient *upower_client,
+ UpSleepKind sleep_kind,
+ gpointer user_data)
+{
+ McdConnectivityMonitor *self = MCD_CONNECTIVITY_MONITOR (user_data);
+
+ DEBUG ("about to sleep! sleep_kind=%s", up_sleep_kind_to_string (sleep_kind));
+ connectivity_monitor_set_awake (self, FALSE);
+}
+
+static void
+notify_resume_cb (
+ UpClient *upower_client,
+ UpSleepKind sleep_kind,
+ gpointer user_data)
+{
+ McdConnectivityMonitor *self = MCD_CONNECTIVITY_MONITOR (user_data);
+
+ DEBUG ("woke up! sleep_kind=%s", up_sleep_kind_to_string (sleep_kind));
+ connectivity_monitor_set_awake (self, TRUE);
+}
+#endif
+
static void
mcd_connectivity_monitor_init (McdConnectivityMonitor *connectivity_monitor)
{
@@ -196,6 +249,7 @@ mcd_connectivity_monitor_init (McdConnectivityMonitor *connectivity_monitor)
connectivity_monitor->priv = priv;
priv->use_conn = TRUE;
+ priv->awake = TRUE;
#ifdef HAVE_NM
priv->nm_client = nm_client_new ();
@@ -244,6 +298,16 @@ mcd_connectivity_monitor_init (McdConnectivityMonitor *connectivity_monitor)
#if !defined(HAVE_NM) && !defined(HAVE_CONNMAN)
priv->connected = TRUE;
#endif
+
+#ifdef HAVE_UPOWER
+ priv->upower_client = up_client_new ();
+ tp_g_signal_connect_object (priv->upower_client,
+ "notify-sleep", G_CALLBACK (notify_sleep_cb), connectivity_monitor,
+ G_CONNECT_AFTER);
+ tp_g_signal_connect_object (priv->upower_client,
+ "notify-resume", G_CALLBACK (notify_resume_cb), connectivity_monitor,
+ G_CONNECT_AFTER);
+#endif
}
static void
@@ -277,6 +341,10 @@ connectivity_monitor_finalize (GObject *object)
}
#endif
+#ifdef HAVE_UPOWER
+ tp_clear_object (&priv->upower_client);
+#endif
+
G_OBJECT_CLASS (mcd_connectivity_monitor_parent_class)->finalize (object);
}
diff --git a/src/kludge-transport.c b/src/kludge-transport.c
index 54717bb4..67d5b234 100644
--- a/src/kludge-transport.c
+++ b/src/kludge-transport.c
@@ -75,7 +75,7 @@ mcd_kludge_transport_constructed (GObject *object)
priv->minotaur = mcd_connectivity_monitor_new ();
tp_g_signal_connect_object (priv->minotaur, "state-change",
- (GCallback) monitor_state_changed_cb, self, G_CONNECT_AFTER);
+ (GCallback) monitor_state_changed_cb, self, 0);
/* We just use ourself as the McdTransport pointer... */
priv->transports = g_list_prepend (NULL, self);