[gnome-power-manager] Add manager policy to change the disk spindown based on timeouts set in GConf
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-power-manager] Add manager policy to change the disk spindown based on timeouts set in GConf
- Date: Sun, 28 Jun 2009 17:28:50 +0000 (UTC)
commit 31e9d11c36d4c2b845d60757b58565800a2589d2
Author: Richard Hughes <richard hughsie com>
Date: Mon Jun 22 11:45:49 2009 +0100
Add manager policy to change the disk spindown based on timeouts set in GConf
src/Makefile.am | 2 +
src/gpm-disks.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gpm-disks.h | 57 +++++++++++++++
src/gpm-manager.c | 36 +++++++++
4 files changed, 303 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index ca943fe..1632946 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,6 +163,8 @@ gnome_power_manager_SOURCES = \
gpm-idle.c \
gpm-load.h \
gpm-load.c \
+ gpm-disks.h \
+ gpm-disks.c \
gpm-control.h \
gpm-control.c \
gpm-button.h \
diff --git a/src/gpm-disks.c b/src/gpm-disks.c
new file mode 100644
index 0000000..d8b5d24
--- /dev/null
+++ b/src/gpm-disks.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include "egg-debug.h"
+#include "gpm-disks.h"
+
+static void gpm_disks_finalize (GObject *object);
+
+#define GPM_DISKS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_DISKS, GpmDisksPrivate))
+
+struct GpmDisksPrivate
+{
+ DBusGProxy *proxy;
+ gchar *cookie;
+};
+
+static gpointer gpm_disks_object = NULL;
+
+G_DEFINE_TYPE (GpmDisks, gpm_disks, G_TYPE_OBJECT)
+
+/**
+ * gpm_disks_unregister:
+ **/
+static gboolean
+gpm_disks_unregister (GpmDisks *disks)
+{
+ gboolean ret = FALSE;
+ GError *error = NULL;
+
+ /* no DeviceKit-power */
+ if (disks->priv->proxy == NULL) {
+ egg_warning ("no DeviceKit-power");
+ goto out;
+ }
+
+ /* clear spindown timeouts */
+ ret = dbus_g_proxy_call (disks->priv->proxy, "DriveUnsetAllSpindownTimeouts", &error,
+ G_TYPE_STRING, disks->priv->cookie,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("failed to clear spindown timeout: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+out:
+ /* reset */
+ g_free (disks->priv->cookie);
+ disks->priv->cookie = NULL;
+
+ return ret;
+}
+
+/**
+ * gpm_disks_register:
+ **/
+static gboolean
+gpm_disks_register (GpmDisks *disks, guint timeout)
+{
+ gboolean ret = FALSE;
+ GError *error = NULL;
+ const gchar **options = {NULL};
+
+ /* no DeviceKit-power */
+ if (disks->priv->proxy == NULL) {
+ egg_warning ("no DeviceKit-power");
+ goto out;
+ }
+
+ /* set spindown timeouts */
+ ret = dbus_g_proxy_call (disks->priv->proxy, "DriveSetAllSpindownTimeouts", &error,
+ G_TYPE_INT, timeout,
+ G_TYPE_STRV, options,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, disks->priv->cookie,
+ G_TYPE_INVALID);
+ if (!ret) {
+ egg_warning ("failed to set spindown timeout: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+out:
+ return ret;
+}
+
+/**
+ * gpm_disks_set_spindown_timeout:
+ **/
+gboolean
+gpm_disks_set_spindown_timeout (GpmDisks *disks, guint timeout)
+{
+ gboolean ret = TRUE;
+
+ /* get rid of last request */
+ if (disks->priv->cookie != NULL) {
+ egg_debug ("unregistering %s", disks->priv->cookie);
+ gpm_disks_unregister (disks);
+ }
+
+ /* is not enabled? */
+ if (timeout == 0) {
+ egg_debug ("disk spindown disabled");
+ goto out;
+ }
+
+ /* register */
+ ret = gpm_disks_register (disks, timeout);
+ if (ret)
+ egg_debug ("registered %s (%i)", disks->priv->cookie, timeout);
+out:
+ return ret;
+}
+
+/**
+ * gpm_disks_init:
+ */
+static void
+gpm_disks_init (GpmDisks *disks)
+{
+ GError *error = NULL;
+ DBusGConnection *connection;
+
+ disks->priv = GPM_DISKS_GET_PRIVATE (disks);
+
+ disks->priv->cookie = NULL;
+
+ /* get org.gnome.Session.ClientPrivate interface */
+ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
+ disks->priv->proxy = dbus_g_proxy_new_for_name_owner (connection,
+ "org.freedesktop.DeviceKit.Disks", "/",
+ "org.freedesktop.DeviceKit.Disks", &error);
+ if (disks->priv->proxy == NULL) {
+ egg_warning ("DBUS error: %s", error->message);
+ g_error_free (error);
+ }
+}
+
+/**
+ * gpm_disks_coldplug:
+ *
+ * @object: This disks instance
+ */
+static void
+gpm_disks_finalize (GObject *object)
+{
+ GpmDisks *disks;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GPM_IS_DISKS (object));
+ disks = GPM_DISKS (object);
+ g_return_if_fail (disks->priv != NULL);
+
+ g_free (disks->priv->cookie);
+ g_object_unref (disks->priv->proxy);
+
+ G_OBJECT_CLASS (gpm_disks_parent_class)->finalize (object);
+}
+
+/**
+ * gpm_disks_class_init:
+ * @klass: This class instance
+ **/
+static void
+gpm_disks_class_init (GpmDisksClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gpm_disks_finalize;
+ g_type_class_add_private (klass, sizeof (GpmDisksPrivate));
+}
+
+/**
+ * gpm_disks_new:
+ * Return value: new #GpmDisks instance.
+ **/
+GpmDisks *
+gpm_disks_new (void)
+{
+ if (gpm_disks_object != NULL) {
+ g_object_ref (gpm_disks_object);
+ } else {
+ gpm_disks_object = g_object_new (GPM_TYPE_DISKS, NULL);
+ g_object_add_weak_pointer (gpm_disks_object, &gpm_disks_object);
+ }
+ return GPM_DISKS (gpm_disks_object);
+}
+
diff --git a/src/gpm-disks.h b/src/gpm-disks.h
new file mode 100644
index 0000000..f3d4589
--- /dev/null
+++ b/src/gpm-disks.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GPM_DISKS_H
+#define __GPM_DISKS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GPM_TYPE_DISKS (gpm_disks_get_type ())
+#define GPM_DISKS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_DISKS, GpmDisks))
+#define GPM_DISKS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_DISKS, GpmDisksClass))
+#define GPM_IS_DISKS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_DISKS))
+#define GPM_IS_DISKS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_DISKS))
+#define GPM_DISKS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_DISKS, GpmDisksClass))
+
+typedef struct GpmDisksPrivate GpmDisksPrivate;
+
+typedef struct
+{
+ GObject parent;
+ GpmDisksPrivate *priv;
+} GpmDisks;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} GpmDisksClass;
+
+GType gpm_disks_get_type (void);
+GpmDisks *gpm_disks_new (void);
+
+gboolean gpm_disks_set_spindown_timeout (GpmDisks *disks,
+ guint timeout);
+
+G_END_DECLS
+
+#endif /* __GPM_DISKS_H */
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 0806598..7b5375a 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -63,6 +63,7 @@
#include "gpm-tray-icon.h"
#include "gpm-engine.h"
#include "gpm-devicekit.h"
+#include "gpm-disks.h"
#include "gpm-feedback-widget.h"
#include "org.freedesktop.PowerManagement.Backlight.h"
@@ -76,6 +77,7 @@ struct GpmManagerPrivate
{
GpmButton *button;
GConfClient *conf;
+ GpmDisks *disks;
GpmDpms *dpms;
GpmIdle *idle;
GpmPrefsServer *prefs_server;
@@ -783,6 +785,28 @@ button_pressed_cb (GpmButton *button, const gchar *type, GpmManager *manager)
}
/**
+ * gpm_manager_get_spindown_timeout:
+ **/
+static guint
+gpm_manager_get_spindown_timeout (GpmManager *manager)
+{
+ gboolean enabled;
+ guint timeout;
+
+ /* get policy */
+ if (!manager->priv->on_battery) {
+ enabled = gconf_client_get_bool (manager->priv->conf, GPM_CONF_DISKS_SPINDOWN_ENABLE_AC, NULL);
+ timeout = gconf_client_get_int (manager->priv->conf, GPM_CONF_DISKS_SPINDOWN_TIMEOUT_AC, NULL);
+ } else {
+ enabled = gconf_client_get_bool (manager->priv->conf, GPM_CONF_DISKS_SPINDOWN_ENABLE_BATT, NULL);
+ timeout = gconf_client_get_int (manager->priv->conf, GPM_CONF_DISKS_SPINDOWN_TIMEOUT_BATT, NULL);
+ }
+ if (!enabled)
+ timeout = 0;
+ return timeout;
+}
+
+/**
* gpm_manager_client_changed_cb:
**/
static void
@@ -790,6 +814,7 @@ gpm_manager_client_changed_cb (DkpClient *client, GpmManager *manager)
{
gboolean event_when_closed;
guint brightness;
+ guint timeout;
gboolean on_battery;
/* get the on-battery state */
@@ -810,6 +835,10 @@ gpm_manager_client_changed_cb (DkpClient *client, GpmManager *manager)
egg_debug ("on_battery: %d", on_battery);
+ /* set disk spindown threshold */
+ timeout = gpm_manager_get_spindown_timeout (manager);
+ gpm_disks_set_spindown_timeout (manager->priv->disks, timeout);
+
if (!on_battery)
brightness = gconf_client_get_int (manager->priv->conf, GPM_CONF_KEYBOARD_BRIGHTNESS_AC, NULL);
else
@@ -1465,6 +1494,7 @@ static void
gpm_manager_init (GpmManager *manager)
{
gboolean check_type_cpu;
+ guint timeout;
DBusGConnection *connection;
GError *error = NULL;
guint version;
@@ -1486,6 +1516,7 @@ gpm_manager_init (GpmManager *manager)
manager->priv->prefs_server = gpm_prefs_server_new ();
manager->priv->notify = gpm_notify_new ();
+ manager->priv->disks = gpm_disks_new ();
manager->priv->conf = gconf_client_get_default ();
manager->priv->client = dkp_client_new ();
g_signal_connect (manager->priv->client, "changed",
@@ -1590,6 +1621,10 @@ gpm_manager_init (GpmManager *manager)
g_signal_connect (manager->priv->engine, "charge-action",
G_CALLBACK (gpm_engine_charge_action_cb), manager);
+ /* set disk spindown threshold */
+ timeout = gpm_manager_get_spindown_timeout (manager);
+ gpm_disks_set_spindown_timeout (manager->priv->disks, timeout);
+
/* update ac throttle */
update_ac_throttle (manager);
}
@@ -1613,6 +1648,7 @@ gpm_manager_finalize (GObject *object)
g_return_if_fail (manager->priv != NULL);
g_object_unref (manager->priv->conf);
+ g_object_unref (manager->priv->disks);
g_object_unref (manager->priv->dpms);
g_object_unref (manager->priv->idle);
g_object_unref (manager->priv->engine);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]