mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-08 19:28:06 +02:00
Add a --enable-deprecated configure argument
This is turned off by default. If this is not set, then any calls to Suspend(), SuspendAllowed(), Hibernate() or HibernateAllowed() will fail with an error. The error mesage tells the user what new method to port to in logind. I'm expecting to set --enable-deprecated for Fedora 17 and 18, but turn it off for Fedora 19, so other distributions probably want to follow suit to find out what other stuff needs to be ported to the new APIs early. GNOME should already be fine, but KDE will need some solid porting as I understand it. See http://lists.freedesktop.org/archives/devkit-devel/2013-January/001339.html for more information on future plans and for rationale.
This commit is contained in:
parent
9843589d2d
commit
372c2f8d29
5 changed files with 120 additions and 11 deletions
10
configure.ac
10
configure.ac
|
|
@ -61,6 +61,15 @@ AC_SYS_LARGEFILE
|
|||
# Initialize libtool
|
||||
LT_INIT
|
||||
|
||||
# Build deprecated functionality
|
||||
AC_ARG_ENABLE(deprecated, [ --enable-deprecated build deprecated functionality],
|
||||
enable_deprecated=$enableval,
|
||||
enable_deprecated=no)
|
||||
if test "${enable_deprecated}" != no; then
|
||||
AC_DEFINE(ENABLE_DEPRECATED, 1, [Define if we should build deprecated functionalty])
|
||||
fi
|
||||
AM_CONDITIONAL(ENABLE_DEPRECATED, test x$enable_deprecated = xyes)
|
||||
|
||||
# Build man pages?
|
||||
AC_ARG_ENABLE(man-pages, [ --enable-man-pages build manual pages],enable_man_pages=$enableval,enable_man_pages=yes)
|
||||
if test "${enable_man_page}" != no; then
|
||||
|
|
@ -291,6 +300,7 @@ echo "
|
|||
cppflags: ${CPPFLAGS}
|
||||
xsltproc: ${XSLTPROC}
|
||||
|
||||
Enable deprecated stuff: ${enable_deprecated}
|
||||
Backend: ${with_backend}
|
||||
libimobiledevice support: ${have_idevice}
|
||||
Maintainer mode: ${USE_MAINTAINER_MODE}
|
||||
|
|
|
|||
|
|
@ -49,12 +49,14 @@
|
|||
#include <dbus/dbus-glib.h>
|
||||
#include <dbus/dbus-glib-lowlevel.h>
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
#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
|
||||
#endif
|
||||
|
||||
static void up_backend_class_init (UpBackendClass *klass);
|
||||
|
|
@ -77,7 +79,9 @@ struct UpBackendPrivate
|
|||
enum {
|
||||
SIGNAL_DEVICE_ADDED,
|
||||
SIGNAL_DEVICE_REMOVED,
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
SIGNAL_RESUMING,
|
||||
#endif
|
||||
SIGNAL_LAST
|
||||
};
|
||||
|
||||
|
|
@ -88,8 +92,10 @@ G_DEFINE_TYPE (UpBackend, up_backend, G_TYPE_OBJECT)
|
|||
static gboolean up_backend_device_add (UpBackend *backend, GUdevDevice *native);
|
||||
static void up_backend_device_remove (UpBackend *backend, GUdevDevice *native);
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
#define UP_BACKEND_SUSPEND_COMMAND "/usr/sbin/pm-suspend"
|
||||
#define UP_BACKEND_HIBERNATE_COMMAND "/usr/sbin/pm-hibernate"
|
||||
#endif
|
||||
#define UP_BACKEND_POWERSAVE_TRUE_COMMAND "/usr/sbin/pm-powersave true"
|
||||
#define UP_BACKEND_POWERSAVE_FALSE_COMMAND "/usr/sbin/pm-powersave false"
|
||||
|
||||
|
|
@ -362,6 +368,7 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
/**
|
||||
* up_backend_supports_sleep_state:
|
||||
*
|
||||
|
|
@ -619,6 +626,7 @@ up_backend_emits_resuming (UpBackend *backend)
|
|||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* up_backend_get_powersave_command:
|
||||
|
|
@ -653,16 +661,19 @@ 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);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
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);
|
||||
#endif
|
||||
|
||||
g_type_class_add_private (klass, sizeof (UpBackendPrivate));
|
||||
}
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
static DBusHandlerResult
|
||||
message_filter (DBusConnection *connection,
|
||||
DBusMessage *message,
|
||||
|
|
@ -675,9 +686,9 @@ message_filter (DBusConnection *connection,
|
|||
g_signal_emit (backend, signals[SIGNAL_RESUMING], 0);
|
||||
return DBUS_HANDLER_RESULT_HANDLED;
|
||||
}
|
||||
|
||||
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* up_backend_init:
|
||||
|
|
@ -691,6 +702,7 @@ up_backend_init (UpBackend *backend)
|
|||
backend->priv->device_list = NULL;
|
||||
backend->priv->managed_devices = up_device_list_new ();
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
#ifdef HAVE_SYSTEMD
|
||||
if (sd_booted ()) {
|
||||
DBusGConnection *bus;
|
||||
|
|
@ -699,6 +711,7 @@ up_backend_init (UpBackend *backend)
|
|||
dbus_connection_add_filter (backend->priv->connection, message_filter, backend, NULL);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -723,8 +736,10 @@ up_backend_finalize (GObject *object)
|
|||
|
||||
g_object_unref (backend->priv->managed_devices);
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
if (backend->priv->connection)
|
||||
dbus_connection_remove_filter (backend->priv->connection, message_filter, backend);
|
||||
#endif
|
||||
|
||||
G_OBJECT_CLASS (up_backend_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ typedef struct
|
|||
void (* device_removed) (UpBackend *backend,
|
||||
GObject *native,
|
||||
UpDevice *device);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
void (* resuming) (UpBackend *backend);
|
||||
#endif
|
||||
} UpBackendClass;
|
||||
|
||||
GType up_backend_get_type (void);
|
||||
|
|
@ -68,15 +70,19 @@ void up_backend_test (gpointer user_data);
|
|||
|
||||
gboolean up_backend_coldplug (UpBackend *backend,
|
||||
UpDaemon *daemon);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean up_backend_kernel_can_suspend (UpBackend *backend);
|
||||
gboolean up_backend_kernel_can_hibernate (UpBackend *backend);
|
||||
gboolean up_backend_has_encrypted_swap (UpBackend *backend);
|
||||
gfloat up_backend_get_used_swap (UpBackend *backend);
|
||||
const gchar *up_backend_get_suspend_command (UpBackend *backend);
|
||||
const gchar *up_backend_get_hibernate_command (UpBackend *backend);
|
||||
#endif
|
||||
const gchar *up_backend_get_powersave_command (UpBackend *backend,
|
||||
gboolean powersave);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean up_backend_emits_resuming (UpBackend *backend);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -86,17 +86,23 @@ struct UpDaemonPrivate
|
|||
gboolean lid_is_present;
|
||||
gboolean lid_force_sleep;
|
||||
gboolean is_docked;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean kernel_can_suspend;
|
||||
gboolean kernel_can_hibernate;
|
||||
gboolean hibernate_has_encrypted_swap;
|
||||
#endif
|
||||
gboolean during_coldplug;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean sent_sleeping_signal;
|
||||
#endif
|
||||
guint battery_poll_id;
|
||||
guint battery_poll_count;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
GTimer *about_to_sleep_timer;
|
||||
guint about_to_sleep_id;
|
||||
guint conf_sleep_timeout;
|
||||
gboolean conf_allow_hibernate_encrypted_swap;
|
||||
#endif
|
||||
gboolean conf_run_powersave_command;
|
||||
const gchar *sleep_kind;
|
||||
};
|
||||
|
|
@ -338,8 +344,9 @@ up_daemon_about_to_sleep (UpDaemon *daemon,
|
|||
const gchar *sleep_kind,
|
||||
DBusGMethodInvocation *context)
|
||||
{
|
||||
PolkitSubject *subject = NULL;
|
||||
GError *error;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
PolkitSubject *subject = NULL;
|
||||
UpDaemonPrivate *priv = daemon->priv;
|
||||
|
||||
/* already requested */
|
||||
|
|
@ -373,6 +380,15 @@ out:
|
|||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
return TRUE;
|
||||
#else
|
||||
/* just return an error */
|
||||
error = g_error_new_literal (UP_DAEMON_ERROR,
|
||||
UP_DAEMON_ERROR_GENERAL,
|
||||
"Method is deprecated, please port to org.freedesktop.login1.Manager.Inhibit");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* temp object for deferred callback */
|
||||
|
|
@ -383,6 +399,7 @@ typedef struct {
|
|||
gulong handler;
|
||||
} UpDaemonDeferredSleep;
|
||||
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
static void
|
||||
emit_resuming (UpDaemonDeferredSleep *sleep)
|
||||
{
|
||||
|
|
@ -504,6 +521,7 @@ up_daemon_deferred_sleep (UpDaemon *daemon, const gchar *command, DBusGMethodInv
|
|||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* up_daemon_suspend:
|
||||
|
|
@ -512,6 +530,7 @@ gboolean
|
|||
up_daemon_suspend (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
PolkitSubject *subject = NULL;
|
||||
const gchar *command;
|
||||
UpDaemonPrivate *priv = daemon->priv;
|
||||
|
|
@ -551,6 +570,15 @@ out:
|
|||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
return TRUE;
|
||||
#else
|
||||
/* just return an error */
|
||||
error = g_error_new_literal (UP_DAEMON_ERROR,
|
||||
UP_DAEMON_ERROR_GENERAL,
|
||||
"Method is deprecated, please port to org.freedesktop.login1.Manager.Suspend");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -559,10 +587,11 @@ out:
|
|||
gboolean
|
||||
up_daemon_suspend_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean ret;
|
||||
PolkitSubject *subject = NULL;
|
||||
UpDaemonPrivate *priv = daemon->priv;
|
||||
GError *error;
|
||||
|
||||
subject = up_polkit_get_subject (priv->polkit, context);
|
||||
if (subject == NULL)
|
||||
|
|
@ -582,9 +611,19 @@ out:
|
|||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
return TRUE;
|
||||
#else
|
||||
/* just return an error */
|
||||
error = g_error_new_literal (UP_DAEMON_ERROR,
|
||||
UP_DAEMON_ERROR_GENERAL,
|
||||
"Method is deprecated, please port to org.freedesktop.login1.Manager.CanSuspend");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
/**
|
||||
* up_daemon_check_hibernate_swap:
|
||||
*
|
||||
* Check current memory usage whether we have enough swap space for
|
||||
|
|
@ -608,6 +647,7 @@ up_daemon_check_hibernate_swap (UpDaemon *daemon)
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* up_daemon_hibernate:
|
||||
|
|
@ -616,6 +656,7 @@ gboolean
|
|||
up_daemon_hibernate (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
PolkitSubject *subject = NULL;
|
||||
const gchar *command;
|
||||
UpDaemonPrivate *priv = daemon->priv;
|
||||
|
|
@ -676,6 +717,15 @@ out:
|
|||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
return TRUE;
|
||||
#else
|
||||
/* just return an error */
|
||||
error = g_error_new_literal (UP_DAEMON_ERROR,
|
||||
UP_DAEMON_ERROR_GENERAL,
|
||||
"Method is deprecated, please port to org.freedesktop.login1.Manager.Hibernate");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -684,10 +734,11 @@ out:
|
|||
gboolean
|
||||
up_daemon_hibernate_allowed (UpDaemon *daemon, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean ret;
|
||||
PolkitSubject *subject = NULL;
|
||||
UpDaemonPrivate *priv = daemon->priv;
|
||||
GError *error;
|
||||
|
||||
subject = up_polkit_get_subject (priv->polkit, context);
|
||||
if (subject == NULL)
|
||||
|
|
@ -707,6 +758,15 @@ out:
|
|||
if (subject != NULL)
|
||||
g_object_unref (subject);
|
||||
return TRUE;
|
||||
#else
|
||||
/* just return an error */
|
||||
error = g_error_new_literal (UP_DAEMON_ERROR,
|
||||
UP_DAEMON_ERROR_GENERAL,
|
||||
"Method is deprecated, please port to org.freedesktop.login1.Manager.CanHibernate");
|
||||
dbus_g_method_return_error (context, error);
|
||||
g_error_free (error);
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1098,19 +1158,15 @@ up_daemon_init (UpDaemon *daemon)
|
|||
daemon->priv->lid_is_present = FALSE;
|
||||
daemon->priv->is_docked = FALSE;
|
||||
daemon->priv->lid_is_closed = FALSE;
|
||||
daemon->priv->kernel_can_suspend = FALSE;
|
||||
daemon->priv->kernel_can_hibernate = FALSE;
|
||||
daemon->priv->hibernate_has_encrypted_swap = FALSE;
|
||||
daemon->priv->power_devices = up_device_list_new ();
|
||||
daemon->priv->on_battery = FALSE;
|
||||
daemon->priv->on_low_battery = FALSE;
|
||||
daemon->priv->during_coldplug = FALSE;
|
||||
daemon->priv->sent_sleeping_signal = FALSE;
|
||||
daemon->priv->battery_poll_id = 0;
|
||||
daemon->priv->battery_poll_count = 0;
|
||||
daemon->priv->about_to_sleep_id = 0;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
daemon->priv->conf_sleep_timeout = 1000;
|
||||
daemon->priv->conf_allow_hibernate_encrypted_swap = FALSE;
|
||||
#endif
|
||||
daemon->priv->conf_run_powersave_command = TRUE;
|
||||
|
||||
/* load some values from the config file */
|
||||
|
|
@ -1124,10 +1180,12 @@ up_daemon_init (UpDaemon *daemon)
|
|||
}
|
||||
ret = g_key_file_load_from_file (file, filename, G_KEY_FILE_NONE, &error);
|
||||
if (ret) {
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
daemon->priv->conf_sleep_timeout =
|
||||
g_key_file_get_integer (file, "UPower", "SleepTimeout", NULL);
|
||||
daemon->priv->conf_allow_hibernate_encrypted_swap =
|
||||
g_key_file_get_boolean (file, "UPower", "AllowHibernateEncryptedSwap", NULL);
|
||||
#endif
|
||||
daemon->priv->conf_run_powersave_command =
|
||||
g_key_file_get_boolean (file, "UPower", "RunPowersaveCommand", NULL);
|
||||
} else {
|
||||
|
|
@ -1144,8 +1202,10 @@ up_daemon_init (UpDaemon *daemon)
|
|||
G_CALLBACK (up_daemon_device_removed_cb), daemon);
|
||||
|
||||
/* use a timer for the about-to-sleep logic */
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
daemon->priv->about_to_sleep_timer = g_timer_new ();
|
||||
g_timer_stop (daemon->priv->about_to_sleep_timer);
|
||||
#endif
|
||||
|
||||
/* watch when these properties change */
|
||||
g_signal_connect (daemon, "notify::lid-is-present",
|
||||
|
|
@ -1158,12 +1218,14 @@ up_daemon_init (UpDaemon *daemon)
|
|||
G_CALLBACK (up_daemon_properties_changed_cb), daemon);
|
||||
|
||||
/* check if we have support */
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
daemon->priv->kernel_can_suspend = up_backend_kernel_can_suspend (daemon->priv->backend);
|
||||
daemon->priv->kernel_can_hibernate = up_backend_kernel_can_hibernate (daemon->priv->backend);
|
||||
|
||||
/* is the swap usable? */
|
||||
if (daemon->priv->kernel_can_hibernate)
|
||||
daemon->priv->hibernate_has_encrypted_swap = up_backend_has_encrypted_swap (daemon->priv->backend);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1214,13 +1276,21 @@ up_daemon_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
|
|||
g_value_set_string (value, PACKAGE_VERSION);
|
||||
break;
|
||||
case PROP_CAN_SUSPEND:
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
g_value_set_boolean (value, priv->kernel_can_suspend);
|
||||
#else
|
||||
g_value_set_boolean (value, FALSE);
|
||||
#endif
|
||||
break;
|
||||
case PROP_CAN_HIBERNATE:
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
g_value_set_boolean (value, (priv->kernel_can_hibernate &&
|
||||
up_daemon_check_hibernate_swap (daemon) &&
|
||||
(!priv->hibernate_has_encrypted_swap ||
|
||||
priv->conf_allow_hibernate_encrypted_swap)));
|
||||
#else
|
||||
g_value_set_boolean (value, FALSE);
|
||||
#endif
|
||||
break;
|
||||
case PROP_ON_BATTERY:
|
||||
g_value_set_boolean (value, priv->on_battery);
|
||||
|
|
@ -1433,7 +1503,9 @@ up_daemon_finalize (GObject *object)
|
|||
g_object_unref (priv->polkit);
|
||||
g_object_unref (priv->config);
|
||||
g_object_unref (priv->backend);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
g_timer_destroy (priv->about_to_sleep_timer);
|
||||
#endif
|
||||
|
||||
G_OBJECT_CLASS (up_daemon_parent_class)->finalize (object);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,8 +118,10 @@ static void
|
|||
up_client_print (UpClient *client)
|
||||
{
|
||||
gchar *daemon_version;
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
gboolean can_suspend;
|
||||
gboolean can_hibernate;
|
||||
#endif
|
||||
gboolean on_battery;
|
||||
gboolean on_low_battery;
|
||||
gboolean lid_is_closed;
|
||||
|
|
@ -128,8 +130,10 @@ up_client_print (UpClient *client)
|
|||
|
||||
g_object_get (client,
|
||||
"daemon-version", &daemon_version,
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
"can-suspend", &can_suspend,
|
||||
"can-hibernate", &can_hibernate,
|
||||
#endif
|
||||
"on-battery", &on_battery,
|
||||
"on-low_battery", &on_low_battery,
|
||||
"lid-is-closed", &lid_is_closed,
|
||||
|
|
@ -138,8 +142,10 @@ up_client_print (UpClient *client)
|
|||
NULL);
|
||||
|
||||
g_print (" daemon-version: %s\n", daemon_version);
|
||||
#ifdef ENABLE_DEPRECATED
|
||||
g_print (" can-suspend: %s\n", can_suspend ? "yes" : "no");
|
||||
g_print (" can-hibernate: %s\n", can_hibernate ? "yes" : "no");
|
||||
#endif
|
||||
g_print (" on-battery: %s\n", on_battery ? "yes" : "no");
|
||||
g_print (" on-low-battery: %s\n", on_low_battery ? "yes" : "no");
|
||||
g_print (" lid-is-closed: %s\n", lid_is_closed ? "yes" : "no");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue