summaryrefslogtreecommitdiff
path: root/libupower-glib/up-client.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2010-02-08 12:18:50 +0000
committerRichard Hughes <richard@hughsie.com>2010-02-08 12:18:50 +0000
commit02914e71ec36ab9d6642c020929fbf9a2b31235b (patch)
treec71f3ace0175c4823e9fe309efb1e6170010e5a2 /libupower-glib/up-client.c
parent4214c6a3450cb2e8f5ef936b1cbd76a772ffb5ed (diff)
downloadupower-02914e71ec36ab9d6642c020929fbf9a2b31235b.tar.gz
Add a new method and two new signals to inform userspace of the pending suspend and the resume event
Based on an idea from Matthew Garrett and Lennart Poettering
Diffstat (limited to 'libupower-glib/up-client.c')
-rw-r--r--libupower-glib/up-client.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c
index b60510a..e0727eb 100644
--- a/libupower-glib/up-client.c
+++ b/libupower-glib/up-client.c
@@ -240,6 +240,48 @@ out:
}
/**
+ * up_client_about_to_sleep_sync:
+ * @client: a #UpClient instance.
+ * @cancellable: a #GCancellable or %NULL
+ * @error: a #GError, or %NULL.
+ *
+ * Tells UPower that we are soon to reqest either Suspend() or Hibernate()
+ * and that session and system components should be notified of this.
+ *
+ * Return value: TRUE if system suspended okay, FALSE other wise.
+ *
+ * Since: 0.9.1
+ **/
+gboolean
+up_client_about_to_sleep_sync (UpClient *client, GCancellable *cancellable, GError **error)
+{
+ gboolean ret;
+ GError *error_local = NULL;
+
+ g_return_val_if_fail (UP_IS_CLIENT (client), FALSE);
+ g_return_val_if_fail (client->priv->proxy != NULL, FALSE);
+
+ ret = dbus_g_proxy_call (client->priv->proxy, "AboutToSleep", &error_local,
+ G_TYPE_INVALID, G_TYPE_INVALID);
+ if (!ret) {
+ /* DBus might time out, which is okay */
+ if (g_error_matches (error_local, DBUS_GERROR, DBUS_GERROR_NO_REPLY)) {
+ g_debug ("DBUS timed out, but recovering");
+ ret = TRUE;
+ goto out;
+ }
+
+ /* an actual error */
+ g_warning ("Couldn't sent that we were about to sleep: %s", error_local->message);
+ g_set_error (error, 1, 0, "%s", error_local->message);
+ }
+out:
+ if (error_local != NULL)
+ g_error_free (error_local);
+ return ret;
+}
+
+/**
* up_client_get_properties_sync:
* @client: a #UpClient instance.
* @cancellable: a #GCancellable or %NULL