diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-10-04 16:19:21 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-10-04 16:19:23 +0100 |
commit | 99fab96fa358f69e688865a81c3afb79508394cc (patch) | |
tree | b2fafeafa637eae1848bdd6fc96ed3849013e64c | |
parent | b78d26c3319809e391a6bcda2d2cb7f454084b90 (diff) | |
parent | c23ca1a9ca5275e708326e5db5f762c52479845e (diff) |
Merge branch 'upower'
Fixes: <https://bugs.freedesktop.org/show_bug.cgi?id=28370>
-rw-r--r-- | configure.ac | 28 | ||||
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/connectivity-monitor.c | 96 | ||||
-rw-r--r-- | src/kludge-transport.c | 2 | ||||
-rw-r--r-- | src/mcd-master.c | 3 |
5 files changed, 118 insertions, 16 deletions
diff --git a/configure.ac b/configure.ac index aa8aa98e..9ce47e9f 100644 --- a/configure.ac +++ b/configure.ac @@ -362,6 +362,33 @@ fi AM_CONDITIONAL(HAVE_NM, test "x$have_nm" = "xyes") AM_CONDITIONAL(HAVE_CONNMAN, test "x$have_connman" = "xyes") +# ----------------------------------------------------------- +# Suspend/resume tracking goop +# ----------------------------------------------------------- + +AC_ARG_ENABLE([upower], + [AS_HELP_STRING([--enable-upower], + [monitor device suspending and resuming using upower-glib @<:@default=auto@:>@])], + [], + [enable_upower=auto]) + +if test "x$enable_upower" != xno; then + PKG_CHECK_MODULES([UPOWER_GLIB], [upower-glib], + [AC_DEFINE([HAVE_UPOWER], [1], [Define to use upower-glib]) + have_upower=yes + ], + [if test "x$enable_upower" == xyes; then + AC_MSG_ERROR([$UPOWER_GLIB_PKG_ERRORS]) + else + have_upower=no + fi + ]) +else + have_upower=no +fi + +AC_SUBST([UPOWER_GLIB_CFLAGS]) +AC_SUBST([UPOWER_GLIB_LIBS]) dnl *************************************************************************** dnl Check for marshal and enum generators @@ -416,6 +443,7 @@ Configure summary: Gnome Keyring................: ${keyring_enabled} Network Manager integration..: ${have_nm} ConnMan integration..........: ${have_connman} + Suspend tracking with UPower.: ${have_upower} Aegis........................: ${aegis_enabled} libaccounts-glib backend.....: ${libaccounts_sso_enabled} Hidden accounts-glib accounts: ${with_accounts_glib_hidden_service_type} 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..4ecccde2 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 { @@ -72,20 +83,32 @@ static McdConnectivityMonitor *connectivity_monitor_singleton = NULL; G_DEFINE_TYPE (McdConnectivityMonitor, mcd_connectivity_monitor, G_TYPE_OBJECT); static void -connectivity_monitor_change_state (McdConnectivityMonitor *connectivity_monitor, - gboolean new_state) +connectivity_monitor_change_states ( + McdConnectivityMonitor *self, + gboolean connected, + gboolean awake) { - McdConnectivityMonitorPrivate *priv; - - priv = connectivity_monitor->priv; + McdConnectivityMonitorPrivate *priv = self->priv; + gboolean old_total = priv->connected && priv->awake; + gboolean new_total = connected && awake; - if (priv->connected == new_state) + if (priv->connected == connected && + priv->awake == awake) return; - priv->connected = new_state; + priv->connected = connected; + priv->awake = awake; - g_signal_emit (connectivity_monitor, signals[STATE_CHANGE], 0, - priv->connected); + if (old_total != new_total) + g_signal_emit (self, signals[STATE_CHANGE], 0, new_total); +} + +static void +connectivity_monitor_set_connected ( + McdConnectivityMonitor *self, + gboolean connected) +{ + connectivity_monitor_change_states (self, connected, self->priv->awake); } #ifdef HAVE_NM @@ -119,7 +142,7 @@ connectivity_monitor_nm_state_change_cb (NMClient *client, DEBUG ("New NetworkManager network state %d (connected: %s)", state, new_nm_connected ? "true" : "false"); - connectivity_monitor_change_state (connectivity_monitor, new_nm_connected); + connectivity_monitor_set_connected (connectivity_monitor, new_nm_connected); } #endif @@ -141,7 +164,7 @@ connectivity_monitor_connman_state_changed_cb (DBusGProxy *proxy, DEBUG ("New ConnMan network state %s", new_state); - connectivity_monitor_change_state (connectivity_monitor, new_connected); + connectivity_monitor_set_connected (connectivity_monitor, new_connected); } static void @@ -181,6 +204,40 @@ connectivity_monitor_connman_check_state (McdConnectivityMonitor *connectivity_m } #endif +#ifdef HAVE_UPOWER +static void +connectivity_monitor_set_awake ( + McdConnectivityMonitor *self, + gboolean awake) +{ + connectivity_monitor_change_states (self, self->priv->connected, awake); +} + +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 +253,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 +302,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 +345,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); } @@ -431,7 +503,7 @@ mcd_connectivity_monitor_set_use_conn (McdConnectivityMonitor *connectivity_moni else #endif { - connectivity_monitor_change_state (connectivity_monitor, TRUE); + connectivity_monitor_set_connected (connectivity_monitor, TRUE); } g_object_notify (G_OBJECT (connectivity_monitor), "use-conn"); 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); diff --git a/src/mcd-master.c b/src/mcd-master.c index 5ea3384e..06bb60ce 100644 --- a/src/mcd-master.c +++ b/src/mcd-master.c @@ -156,8 +156,7 @@ mcd_master_transport_connected (McdMaster *master, McdTransportPlugin *plugin, { DEBUG ("conditions matched"); _mcd_account_connect_with_auto_presence (account, FALSE); - if (g_hash_table_size (conditions) > 0) - mcd_account_connection_bind_transport (account, transport); + mcd_account_connection_bind_transport (account, transport); } g_hash_table_unref (conditions); } |