summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libupower-glib/up-client.c25
-rw-r--r--libupower-glib/up-client.h1
-rw-r--r--src/dummy/up-backend.c13
-rw-r--r--src/freebsd/up-backend.c13
-rw-r--r--src/linux/up-backend.c55
-rw-r--r--src/openbsd/up-backend.c13
-rw-r--r--src/org.freedesktop.UPower.xml27
-rw-r--r--src/up-backend.h1
-rw-r--r--src/up-daemon.c11
-rw-r--r--src/up-daemon.h2
-rw-r--r--tools/up-tool.c4
11 files changed, 145 insertions, 20 deletions
diff --git a/libupower-glib/up-client.c b/libupower-glib/up-client.c
index 2169a59..4bdfa91 100644
--- a/libupower-glib/up-client.c
+++ b/libupower-glib/up-client.c
@@ -145,6 +145,31 @@ up_client_get_display_device (UpClient *client)
}
/**
+ * up_client_get_critical_action:
+ * @client: a #UpClient instance.
+ *
+ * Gets a string representing the configured critical action,
+ * depending on availability.
+ *
+ * Return value: the action name, or %NULL on error.
+ *
+ * Since: 1.0
+ **/
+char *
+up_client_get_critical_action (UpClient *client)
+{
+ char *action;
+
+ g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
+ if (!up_client_glue_call_get_critical_action_sync (client->priv->proxy,
+ &action,
+ NULL, NULL)) {
+ return NULL;
+ }
+ return action;
+}
+
+/**
* up_client_get_daemon_version:
* @client: a #UpClient instance.
*
diff --git a/libupower-glib/up-client.h b/libupower-glib/up-client.h
index 0f502d9..151f29b 100644
--- a/libupower-glib/up-client.h
+++ b/libupower-glib/up-client.h
@@ -81,6 +81,7 @@ gboolean up_client_enumerate_devices_sync (UpClient *client,
GCancellable *cancellable,
GError **error);
UpDevice * up_client_get_display_device (UpClient *client);
+char * up_client_get_critical_action (UpClient *client);
/* accessors */
GPtrArray *up_client_get_devices (UpClient *client);
diff --git a/src/dummy/up-backend.c b/src/dummy/up-backend.c
index adc3bbb..c752041 100644
--- a/src/dummy/up-backend.c
+++ b/src/dummy/up-backend.c
@@ -131,6 +131,19 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
}
/**
+ * up_backend_get_critical_action:
+ * @backend: The %UpBackend class instance
+ *
+ * Which action will be taken when %UP_DEVICE_LEVEL_ACTION
+ * warning-level occurs.
+ **/
+const char *
+up_backend_get_critical_action (UpBackend *backend)
+{
+ return "PowerOff";
+}
+
+/**
* up_backend_take_action:
* @backend: The %UpBackend class instance
*
diff --git a/src/freebsd/up-backend.c b/src/freebsd/up-backend.c
index 949f3cd..433c331 100644
--- a/src/freebsd/up-backend.c
+++ b/src/freebsd/up-backend.c
@@ -294,6 +294,19 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
}
/**
+ * up_backend_get_critical_action:
+ * @backend: The %UpBackend class instance
+ *
+ * Which action will be taken when %UP_DEVICE_LEVEL_ACTION
+ * warning-level occurs.
+ **/
+const char *
+up_backend_get_critical_action (UpBackend *backend)
+{
+ return "PowerOff";
+}
+
+/**
* up_backend_take_action:
* @backend: The %UpBackend class instance
*
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
**/
diff --git a/src/openbsd/up-backend.c b/src/openbsd/up-backend.c
index d10a6c2..40e381e 100644
--- a/src/openbsd/up-backend.c
+++ b/src/openbsd/up-backend.c
@@ -149,6 +149,19 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
}
/**
+ * up_backend_get_critical_action:
+ * @backend: The %UpBackend class instance
+ *
+ * Which action will be taken when %UP_DEVICE_LEVEL_ACTION
+ * warning-level occurs.
+ **/
+const char *
+up_backend_get_critical_action (UpBackend *backend)
+{
+ return "PowerOff";
+}
+
+/**
* up_backend_take_action:
* @backend: The %UpBackend class instance
*
diff --git a/src/org.freedesktop.UPower.xml b/src/org.freedesktop.UPower.xml
index d02ee3a..294d3fd 100644
--- a/src/org.freedesktop.UPower.xml
+++ b/src/org.freedesktop.UPower.xml
@@ -105,6 +105,33 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
</doc:doc>
</method>
+ <method name="GetCriticalAction">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+ <arg name="action" direction="out" type="s">
+ <doc:doc><doc:summary>A string representing the critical action configured and available.</doc:summary></doc:doc>
+ </arg>
+
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ When the system's power supply is critical (critically low batteries or UPS),
+ the system will take this action. Possible values are:
+ <doc:list>
+ <doc:item>
+ <doc:term>HybridSleep</doc:term>
+ </doc:item>
+ <doc:item>
+ <doc:term>Hibernate</doc:term>
+ </doc:item>
+ <doc:item>
+ <doc:term>PowerOff</doc:term>
+ </doc:item>
+ </doc:list>
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
<!-- ************************************************************ -->
<signal name="DeviceAdded">
diff --git a/src/up-backend.h b/src/up-backend.h
index 71b074c..7b3145c 100644
--- a/src/up-backend.h
+++ b/src/up-backend.h
@@ -70,6 +70,7 @@ void up_backend_test (gpointer user_data);
gboolean up_backend_coldplug (UpBackend *backend,
UpDaemon *daemon);
void up_backend_take_action (UpBackend *backend);
+const char *up_backend_get_critical_action (UpBackend *backend);
G_END_DECLS
diff --git a/src/up-daemon.c b/src/up-daemon.c
index 22e9116..5068f47 100644
--- a/src/up-daemon.c
+++ b/src/up-daemon.c
@@ -449,6 +449,17 @@ up_daemon_get_display_device (UpDaemon *daemon,
}
/**
+ * up_daemon_get_critical_action:
+ **/
+gboolean
+up_daemon_get_critical_action (UpDaemon *daemon,
+ DBusGMethodInvocation *context)
+{
+ dbus_g_method_return (context, up_backend_get_critical_action (daemon->priv->backend));
+ return TRUE;
+}
+
+/**
* up_daemon_register_power_daemon:
**/
static gboolean
diff --git a/src/up-daemon.h b/src/up-daemon.h
index 43b534b..68c575c 100644
--- a/src/up-daemon.h
+++ b/src/up-daemon.h
@@ -99,6 +99,8 @@ gboolean up_daemon_enumerate_devices (UpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean up_daemon_get_display_device (UpDaemon *daemon,
DBusGMethodInvocation *context);
+gboolean up_daemon_get_critical_action (UpDaemon *daemon,
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/tools/up-tool.c b/tools/up-tool.c
index 99dba78..8e58d00 100644
--- a/tools/up-tool.c
+++ b/tools/up-tool.c
@@ -124,6 +124,7 @@ up_client_print (UpClient *client)
gboolean lid_is_closed;
gboolean lid_is_present;
gboolean is_docked;
+ char *action;
g_object_get (client,
"daemon-version", &daemon_version,
@@ -138,6 +139,9 @@ up_client_print (UpClient *client)
g_print (" lid-is-closed: %s\n", lid_is_closed ? "yes" : "no");
g_print (" lid-is-present: %s\n", lid_is_present ? "yes" : "no");
g_print (" is-docked: %s\n", is_docked ? "yes" : "no");
+ action = up_client_get_critical_action (client);
+ g_print (" critical-action: %s\n", action);
+ g_free (action);
g_free (daemon_version);
}