summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Taylor <rob.taylor@codethink.co.uk>2007-08-18 16:24:38 +0100
committerRob Taylor <rob.taylor@codethink.co.uk>2007-08-22 15:17:50 +0100
commit1b3a9e232dfde6d115d20275376c4e817ad3109d (patch)
treecd87364272083a5d1aebf1c071e18ab9c470065c
parentc6b1dc765bd1f769bf8e365795f9a798e920e82d (diff)
add 'timeouts' policy module.
This implements a simple 3 state timeout policy on top of the idle mechanism plugin.
-rw-r--r--configure.in1
-rw-r--r--plugins/policy/Makefile.am3
-rw-r--r--plugins/policy/timeouts/Makefile.am10
-rw-r--r--plugins/policy/timeouts/timeouts.c99
-rw-r--r--plugins/policy/timeouts/timeouts.ini4
5 files changed, 116 insertions, 1 deletions
diff --git a/configure.in b/configure.in
index 24ad0df..b09441d 100644
--- a/configure.in
+++ b/configure.in
@@ -321,6 +321,7 @@ plugins/glue/xorg/Makefile
plugins/policy/Makefile
plugins/policy/display/Makefile
plugins/policy/suspend/Makefile
+plugins/policy/timeouts/Makefile
ohmd/Makefile
po/Makefile.in
docs/Makefile
diff --git a/plugins/policy/Makefile.am b/plugins/policy/Makefile.am
index b3aee80..7d271f9 100644
--- a/plugins/policy/Makefile.am
+++ b/plugins/policy/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS = \
display \
- suspend
+ suspend \
+ timeouts
clean-local:
rm -f *~
diff --git a/plugins/policy/timeouts/Makefile.am b/plugins/policy/timeouts/Makefile.am
new file mode 100644
index 0000000..e7abfa0
--- /dev/null
+++ b/plugins/policy/timeouts/Makefile.am
@@ -0,0 +1,10 @@
+EXTRA_DIST = $(Data_DATA)
+Datadir = @OHM_PLUGIN_CONF_DIR@
+Data_DATA = timeouts.ini
+
+plugindir = @OHM_PLUGIN_DIR@
+plugin_LTLIBRARIES = libohm_timeouts.la
+libohm_timeouts_la_SOURCES = timeouts.c
+libohm_timeouts_la_LIBADD = @OHM_PLUGIN_LIBS@
+libohm_timeouts_la_LDFLAGS = -module -avoid-version
+libohm_timeouts_la_CFLAGS = @OHM_PLUGIN_CFLAGS@
diff --git a/plugins/policy/timeouts/timeouts.c b/plugins/policy/timeouts/timeouts.c
new file mode 100644
index 0000000..133dd36
--- /dev/null
+++ b/plugins/policy/timeouts/timeouts.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <gmodule.h>
+#include <glib.h>
+#include <ohm-plugin.h>
+
+enum {
+ CONF_IDLE_STATE_CHANGED,
+ CONF_LAST
+};
+
+
+static void
+init (OhmPlugin *plugin)
+{
+ gint first_timeout;
+
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", &first_timeout);
+ ohm_plugin_conf_set_key (plugin, "idle.timeout", first_timeout);
+ ohm_plugin_conf_set_key (plugin, "idle.state", 0);
+}
+
+static void
+notify (OhmPlugin *plugin, gint id, gint value)
+{
+ gint new_timeout, old_timeout;
+
+ if (id != CONF_IDLE_STATE_CHANGED)
+ return;
+
+ switch (value) {
+ case 0:
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", &new_timeout);
+ ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout);
+ ohm_plugin_conf_set_key (plugin, "timeouts.momentary", 0);
+ ohm_plugin_conf_set_key (plugin, "timeouts.powersave", 0);
+ ohm_plugin_conf_set_key (plugin, "timeouts.powerdown", 0);
+ break;
+ case 1:
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_powersave", &new_timeout);
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_momentary", &old_timeout);
+ ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout-old_timeout);
+ ohm_plugin_conf_set_key (plugin, "timeouts.momentary", 1);
+ break;
+ case 2:
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_powerdown", &new_timeout);
+ ohm_plugin_conf_get_key (plugin, "timeouts.timer_powersave", &old_timeout);
+ ohm_plugin_conf_set_key (plugin, "idle.timeout", new_timeout-old_timeout);
+ ohm_plugin_conf_set_key (plugin, "timeouts.powersave", 1);
+ break;
+ case 3:
+ ohm_plugin_conf_set_key (plugin, "timeouts.powerdown", 1);
+ break;
+ default:
+ break;
+ }
+}
+
+OHM_PLUGIN_DESCRIPTION (
+ "timeouts", /* description */
+ "0.0.1", /* version */
+ "rob.taylor@codethink.co.uk", /* author */
+ OHM_LICENSE_LGPL, /* license */
+ init, /* initialize */
+ NULL, /* destroy */
+ notify /* notify */
+);
+
+OHM_PLUGIN_PROVIDES (
+ "timeouts.momentary",
+ "timeouts.powersave",
+ "timeouts.powerdown"
+);
+
+OHM_PLUGIN_REQUIRES (
+ "idle"
+);
+
+OHM_PLUGIN_INTERESTED (
+ {"idle.state", CONF_IDLE_STATE_CHANGED}
+);
diff --git a/plugins/policy/timeouts/timeouts.ini b/plugins/policy/timeouts/timeouts.ini
new file mode 100644
index 0000000..703385b
--- /dev/null
+++ b/plugins/policy/timeouts/timeouts.ini
@@ -0,0 +1,4 @@
+timeouts.timer_momentary 5000 public
+timeouts.timer_powersave 10000 public
+timeouts.timer_powerdown 100000 public
+