summaryrefslogtreecommitdiff
path: root/src/linux
diff options
context:
space:
mode:
Diffstat (limited to 'src/linux')
-rw-r--r--src/linux/Makefile.am3
-rw-r--r--src/linux/up-backend.c67
2 files changed, 69 insertions, 1 deletions
diff --git a/src/linux/Makefile.am b/src/linux/Makefile.am
index 520b4cf..2081a66 100644
--- a/src/linux/Makefile.am
+++ b/src/linux/Makefile.am
@@ -12,7 +12,8 @@ INCLUDES = \
$(GUDEV_CFLAGS) \
$(POLKIT_CFLAGS) \
$(GLIB_CFLAGS) \
- $(IDEVICE_CFLAGS)
+ $(IDEVICE_CFLAGS) \
+ $(SYSTEMD_CFLAGS)
if BACKEND_TYPE_LINUX
noinst_LTLIBRARIES = libupshared.la
diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c
index be01763..ddd4472 100644
--- a/src/linux/up-backend.c
+++ b/src/linux/up-backend.c
@@ -45,6 +45,17 @@
#include "up-device-idevice.h"
#endif /* HAVE_IDEVICE */
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+
+#define SD_HIBERNATE_COMMAND "gdbus call --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 --method org.freedesktop.login1.Manager.Hibernate 'true'"
+#define SD_SUSPEND_COMMAND "gdbus call --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1 --method org.freedesktop.login1.Manager.Suspend 'true'"
+
+#endif
+
static void up_backend_class_init (UpBackendClass *klass);
static void up_backend_init (UpBackend *backend);
static void up_backend_finalize (GObject *object);
@@ -59,11 +70,13 @@ struct UpBackendPrivate
UpDeviceList *managed_devices;
UpDock *dock;
UpConfig *config;
+ DBusConnection *connection;
};
enum {
SIGNAL_DEVICE_ADDED,
SIGNAL_DEVICE_REMOVED,
+ SIGNAL_RESUMING,
SIGNAL_LAST
};
@@ -564,6 +577,11 @@ out:
const gchar *
up_backend_get_suspend_command (UpBackend *backend)
{
+#ifdef HAVE_SYSTEMD
+ if (sd_booted ())
+ return SD_SUSPEND_COMMAND;
+ else
+#endif
return UP_BACKEND_SUSPEND_COMMAND;
}
@@ -573,9 +591,24 @@ up_backend_get_suspend_command (UpBackend *backend)
const gchar *
up_backend_get_hibernate_command (UpBackend *backend)
{
+#ifdef HAVE_SYSTEMD
+ if (sd_booted ())
+ return SD_HIBERNATE_COMMAND;
+ else
+#endif
return UP_BACKEND_HIBERNATE_COMMAND;
}
+gboolean
+up_backend_emits_resuming (UpBackend *backend)
+{
+#ifdef HAVE_SYSTEMD
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
/**
* up_backend_get_powersave_command:
**/
@@ -609,10 +642,32 @@ up_backend_class_init (UpBackendClass *klass)
G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, up_marshal_VOID__POINTER_POINTER,
G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
+ signals [SIGNAL_RESUMING] =
+ g_signal_new ("resuming",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (UpBackendClass, resuming),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
g_type_class_add_private (klass, sizeof (UpBackendPrivate));
}
+static DBusHandlerResult
+message_filter (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
+{
+ UpBackend *backend = user_data;
+
+ if (dbus_message_is_signal (message, "org.freedesktop.UPower", "Resuming")) {
+ g_debug ("received Resuming signal");
+ g_signal_emit (backend, signals[SIGNAL_RESUMING], 0);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
/**
* up_backend_init:
**/
@@ -624,6 +679,15 @@ up_backend_init (UpBackend *backend)
backend->priv->daemon = NULL;
backend->priv->device_list = NULL;
backend->priv->managed_devices = up_device_list_new ();
+
+#ifdef HAVE_SYSTEMD
+ if (sd_booted ()) {
+ DBusGConnection *bus;
+ bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+ backend->priv->connection = dbus_g_connection_get_connection (bus);
+ dbus_connection_add_filter (backend->priv->connection, message_filter, backend, NULL);
+ }
+#endif
}
/**
@@ -648,6 +712,9 @@ up_backend_finalize (GObject *object)
g_object_unref (backend->priv->managed_devices);
+ if (backend->priv->connection)
+ dbus_connection_remove_filter (backend->priv->connection, message_filter, backend);
+
G_OBJECT_CLASS (up_backend_parent_class)->finalize (object);
}