summaryrefslogtreecommitdiff
path: root/src/linux
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2013-10-17 09:04:03 +0200
committerBastien Nocera <hadess@hadess.net>2013-10-17 09:04:03 +0200
commitdb31456921f9977d8fef8ed1dcee6517107358ff (patch)
treedcd098e7365d3d1b2fb8bc2170a4cf29c1a92a3c /src/linux
parenta7870229ee32616ac9e55edbab1045d1dac171be (diff)
downloadupower-db31456921f9977d8fef8ed1dcee6517107358ff.tar.gz
all: Add GetCriticalAction daemon method
This allows desktop front-ends to get which action will actually be taken when we hit critical battery. This is not a property as availability of actions might change over the course of the run of the system, and we didn't want to make unnecessary D-Bus calls on startup.
Diffstat (limited to 'src/linux')
-rw-r--r--src/linux/up-backend.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c
index 9b639d4..65ea8f7 100644
--- a/src/linux/up-backend.c
+++ b/src/linux/up-backend.c
@@ -367,13 +367,14 @@ check_action_result (GVariant *result)
}
/**
- * up_backend_take_action:
+ * up_backend_get_critical_action:
* @backend: The %UpBackend class instance
*
- * Act upon the %UP_DEVICE_LEVEL_ACTION warning-level.
+ * Which action will be taken when %UP_DEVICE_LEVEL_ACTION
+ * warning-level occurs.
**/
-void
-up_backend_take_action (UpBackend *backend)
+const char *
+up_backend_get_critical_action (UpBackend *backend)
{
struct {
const gchar *method;
@@ -388,10 +389,11 @@ up_backend_take_action (UpBackend *backend)
g_return_if_fail (backend->priv->logind_proxy != NULL);
for (i = 0; i < G_N_ELEMENTS (actions); i++) {
- gboolean action_available = FALSE;
GVariant *result;
if (actions[i].can_method) {
+ gboolean action_available;
+
/* Check whether we can use the method */
result = g_dbus_proxy_call_sync (backend->priv->logind_proxy,
actions[i].can_method,
@@ -399,32 +401,45 @@ up_backend_take_action (UpBackend *backend)
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, NULL);
action_available = check_action_result (result);
+ g_message ("got result %s", g_variant_print (result, TRUE));
g_variant_unref (result);
if (!action_available)
continue;
- } else {
- action_available = TRUE;
}
- /* Take action */
- g_debug ("About to call logind method %s", actions[i].method);
- g_dbus_proxy_call (backend->priv->logind_proxy,
- actions[i].method,
- g_variant_new ("(b)", FALSE),
- G_DBUS_CALL_FLAGS_NONE,
- G_MAXINT,
- NULL,
- NULL,
- NULL);
-
- return;
+ return actions[i].method;
}
-
g_assert_not_reached ();
}
/**
+ * up_backend_take_action:
+ * @backend: The %UpBackend class instance
+ *
+ * Act upon the %UP_DEVICE_LEVEL_ACTION warning-level.
+ **/
+void
+up_backend_take_action (UpBackend *backend)
+{
+ const char *method;
+
+ method = up_backend_get_critical_action (backend);
+ g_assert (method != NULL);
+
+ /* Take action */
+ g_debug ("About to call logind method %s", method);
+ g_dbus_proxy_call (backend->priv->logind_proxy,
+ method,
+ g_variant_new ("(b)", FALSE),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT,
+ NULL,
+ NULL,
+ NULL);
+}
+
+/**
* up_backend_class_init:
* @klass: The UpBackendClass
**/