diff options
-rw-r--r-- | configure.in | 3 | ||||
-rw-r--r-- | etc/Makefile.am | 2 | ||||
-rw-r--r-- | etc/plugins/.gitignore | 2 | ||||
-rw-r--r-- | etc/plugins/Makefile.am | 7 | ||||
-rw-r--r-- | etc/require | 1 | ||||
-rw-r--r-- | etc/suggest | 3 | ||||
-rw-r--r-- | ohmd/ohm-conf.c | 10 | ||||
-rw-r--r-- | ohmd/ohm-manager.c | 34 | ||||
-rw-r--r-- | ohmd/ohm-plugin.c | 7 | ||||
-rw-r--r-- | plugins/Makefile.am | 10 | ||||
-rw-r--r-- | plugins/backlight/.gitignore | 8 | ||||
-rw-r--r-- | plugins/backlight/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/backlight/README | 1 | ||||
-rw-r--r-- | plugins/backlight/backlight (renamed from etc/plugins/backlight) | 1 | ||||
-rw-r--r-- | plugins/backlight/ohm-plugin-backlight.c | 162 | ||||
-rw-r--r-- | plugins/powerstatus/.gitignore | 8 | ||||
-rw-r--r-- | plugins/powerstatus/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/powerstatus/README | 1 | ||||
-rw-r--r-- | plugins/powerstatus/ohm-plugin-powerstatus.c (renamed from plugins/ohm-plugin-battery.c) | 78 | ||||
-rw-r--r-- | plugins/powerstatus/powerstatus | 2 |
20 files changed, 306 insertions, 74 deletions
diff --git a/configure.in b/configure.in index 714edd8..1cda845 100644 --- a/configure.in +++ b/configure.in @@ -150,8 +150,9 @@ ohm.pc ohm.conf Makefile etc/Makefile -etc/plugins/Makefile plugins/Makefile +plugins/powerstatus/Makefile +plugins/backlight/Makefile ohmd/Makefile po/Makefile.in docs/Makefile diff --git a/etc/Makefile.am b/etc/Makefile.am index 755cbb7..a551d9d 100644 --- a/etc/Makefile.am +++ b/etc/Makefile.am @@ -1,5 +1,3 @@ -SUBDIRS = plugins - EXTRA_DIST = \ $(Data_DATA) diff --git a/etc/plugins/.gitignore b/etc/plugins/.gitignore deleted file mode 100644 index 282522d..0000000 --- a/etc/plugins/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/etc/plugins/Makefile.am b/etc/plugins/Makefile.am deleted file mode 100644 index 2fde320..0000000 --- a/etc/plugins/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -EXTRA_DIST = \ - $(Data_DATA) - -Datadir = $(sysconfdir)/ohm/plugins - -Data_DATA = \ - backlight diff --git a/etc/require b/etc/require index f30443e..38fdea1 100644 --- a/etc/require +++ b/etc/require @@ -1,2 +1 @@ # This file should list all the modules that are required for coldplug -libpluginbattery.so diff --git a/etc/suggest b/etc/suggest index 68cee26..5231d75 100644 --- a/etc/suggest +++ b/etc/suggest @@ -1,2 +1,5 @@ # This file should list all the modules that are suggested for coldplug libacadapter.so +libpluginbattery.so +libpolicyexample.so +libpolicypowerstatus.so diff --git a/ohmd/ohm-conf.c b/ohmd/ohm-conf.c index 412b813..6168c17 100644 --- a/ohmd/ohm-conf.c +++ b/ohmd/ohm-conf.c @@ -142,7 +142,11 @@ ohm_conf_print_all (OhmConf *conf) entry = (OhmConfObjectMulti *) l->data; g_print ("%s", entry->key); spaces = g_strnfill (max - strlen(entry->key), ' '); - g_print ("%s : %i\n", spaces, entry->value); + if (entry->public == TRUE) { + g_print ("%s : %i\t(public)\n", spaces, entry->value); + } else { + g_print ("%s : %i\t(private)\n", spaces, entry->value); + } g_free (spaces); } @@ -165,6 +169,8 @@ ohm_conf_get_key (OhmConf *conf, g_return_val_if_fail (OHM_IS_CONF (conf), FALSE); g_return_val_if_fail (key != NULL, FALSE); g_return_val_if_fail (value != NULL, FALSE); + g_return_val_if_fail (error != NULL, FALSE); + g_return_val_if_fail (*error == NULL, FALSE); if (conf->priv->keys == NULL) { *error = g_error_new (ohm_conf_error_quark (), @@ -405,6 +411,8 @@ ohm_conf_load_defaults (OhmConf *conf, /* generate path for each module */ filename = g_build_path (G_DIR_SEPARATOR_S, SYSCONFDIR, "ohm", "plugins", plugin_name, NULL); + ohm_debug ("Loading %s defaults from %s", plugin_name, filename); + /* load from file */ ret = g_file_get_contents (filename, &contents, &length, error); g_free (filename); diff --git a/ohmd/ohm-manager.c b/ohmd/ohm-manager.c index 2f5e7dc..e4e26d6 100644 --- a/ohmd/ohm-manager.c +++ b/ohmd/ohm-manager.c @@ -82,26 +82,6 @@ ohm_manager_error_quark (void) return quark; } -static void -moo (OhmManager *manager) -{ - gboolean ret; - GError *error = NULL; - gint intval; - - ret = ohm_conf_load_defaults (manager->priv->conf, "backlight", &error); - if (ret == FALSE) { - g_error ("could not load defaults : %s", error->message); - } - - ret = ohm_conf_get_key (manager->priv->conf, "manager.version.major", &intval, &error); - - ohm_conf_print_all (manager->priv->conf); - - ohm_debug ("ret=%i, intval=%i, error=%p", ret, intval, error); - -} - /** * ohm_manager_get_on_ac: * @manager: This class instance @@ -178,6 +158,7 @@ ohm_manager_init (OhmManager *manager) { GError *error = NULL; DBusGConnection *connection; + gboolean ret; manager->priv = OHM_MANAGER_GET_PRIVATE (manager); /* get system bus connection */ @@ -196,9 +177,18 @@ ohm_manager_init (OhmManager *manager) ohm_conf_set_key_internal (manager->priv->conf, "manager.version.major", 0, TRUE, NULL); ohm_conf_set_key_internal (manager->priv->conf, "manager.version.minor", 0, TRUE, NULL); ohm_conf_set_key_internal (manager->priv->conf, "manager.version.patch", 1, TRUE, NULL); - ohm_conf_print_all (manager->priv->conf); - moo (manager); + /* fixme: move to OhmModule */ + ret = ohm_conf_load_defaults (manager->priv->conf, "backlight", &error); + if (ret == FALSE) { + g_error ("could not load defaults : %s", error->message); + } + ret = ohm_conf_load_defaults (manager->priv->conf, "powerstatus", &error); + if (ret == FALSE) { + g_error ("could not load defaults : %s", error->message); + } + + ohm_conf_print_all (manager->priv->conf); } /** diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c index dceb37f..454e4aa 100644 --- a/ohmd/ohm-plugin.c +++ b/ohmd/ohm-plugin.c @@ -176,7 +176,12 @@ ohm_plugin_conf_get_key (OhmPlugin *plugin, const gchar *key, int *value) { - return ohm_conf_get_key (plugin->priv->conf, key, value, NULL); + GError *error; + gboolean ret; + error = NULL; + ret = ohm_conf_get_key (plugin->priv->conf, key, value, &error); + /* fixme print and clear error */ + return ret; } G_MODULE_EXPORT gboolean diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 77dc76f..fa7ceed 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,3 +1,7 @@ +SUBDIRS = \ + powerstatus \ + backlight + INCLUDES = \ -I$(top_srcdir)/ohmd \ $(GLIB_CFLAGS) \ @@ -6,11 +10,5 @@ INCLUDES = \ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" -lib_LTLIBRARIES=libpluginbattery.la -libpluginbatteryincludedir=$(includedir)/ohm -libpluginbattery_la_SOURCES = ohm-plugin-battery.c -libpluginbattery_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) -libpluginbattery_la_LDFLAGS = -module -avoid-version - clean-local: rm -f *~ diff --git a/plugins/backlight/.gitignore b/plugins/backlight/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/backlight/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/backlight/Makefile.am b/plugins/backlight/Makefile.am new file mode 100644 index 0000000..3527a04 --- /dev/null +++ b/plugins/backlight/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = backlight + +lib_LTLIBRARIES = libpolicybacklight.la +libpolicybacklightincludedir = $(includedir)/ohm +libpolicybacklight_la_SOURCES = ohm-plugin-backlight.c +libpolicybacklight_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libpolicybacklight_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *~ diff --git a/plugins/backlight/README b/plugins/backlight/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/backlight/README @@ -0,0 +1 @@ +Todo diff --git a/etc/plugins/backlight b/plugins/backlight/backlight index cb2c472..2e56268 100644 --- a/etc/plugins/backlight +++ b/plugins/backlight/backlight @@ -4,3 +4,4 @@ backlight.value_battery 70 public backlight.value_idle 40 public backlight.time_idle 200 public backlight.time_off 400 +backlight.state 1 diff --git a/plugins/backlight/ohm-plugin-backlight.c b/plugins/backlight/ohm-plugin-backlight.c new file mode 100644 index 0000000..dac2499 --- /dev/null +++ b/plugins/backlight/ohm-plugin-backlight.c @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2007 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 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 + */ + +/* + * TODO + * + * - Add battery brightness, and detect change in battery state + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +enum { + CONF_SYSTEM_IDLE_CHANGED, + CONF_BRIGHTNESS_AC_CHANGED, + CONF_BRIGHTNESS_IDLE_CHANGED, + CONF_TIME_IDLE_CHANGED, + CONF_TIME_OFF_CHANGED, + CONF_LAST +}; + +typedef struct { + gint system_idle; + gint state; + gint brightness; + gint brightness_ac; + gint brightness_idle; + gint time_idle; + gint time_off; +} OhmPluginCacheData; + +OhmPluginCacheData data; + +/** + * plugin_load: + * @plugin: This class instance + * + * Called before the plugin is coldplg. + * Define any modules that the plugin depends on, but do not do coldplug here + * as some of the modules may not have loaded yet. + */ +static void +plugin_load (OhmPlugin *plugin) +{ + /* FIXME: detect if we have any backlights in the system and return false if not */ + /* add in the required, suggested and prevented plugins */ + ohm_plugin_suggest (plugin, "libpluginidle.so"); +} + +/** + * check_system_idle_state: + * @plugin: This class instance + * + * Check the idle times, and dim the backlight is required + */ +static void +check_system_backlight_state (OhmPlugin *plugin) +{ + if (data.system_idle > data.time_off) { + /* turn off screen after 20 seconds */ + data.state = 0; + data.brightness = 0; + } else if (data.system_idle > data.time_idle) { + /* dim screen after 5 seconds */ + data.state = 1; + data.brightness = data.brightness_idle; + } else { + /* set brightness to default */ + data.state = 1; + data.brightness = data.brightness_ac; + } + ohm_plugin_conf_set_key (plugin, "backlight.state", data.state); + ohm_plugin_conf_set_key (plugin, "backlight.brightness", data.brightness); +} + +/** + * plugin_coldplug: + * @plugin: This class instance + * + * Coldplug, i.e. read and set the initial state of the plugin. + * We can assume all the required modules have been loaded, although it's + * dangerous to assume the key values are anything other than the defaults. + */ +static void +plugin_coldplug (OhmPlugin *plugin) +{ + /* interested keys */ + ohm_plugin_conf_interested (plugin, "idle.system_idle", CONF_SYSTEM_IDLE_CHANGED); + ohm_plugin_conf_interested (plugin, "backlight.value_ac", CONF_BRIGHTNESS_AC_CHANGED); + ohm_plugin_conf_interested (plugin, "backlight.value_idle", CONF_BRIGHTNESS_IDLE_CHANGED); + ohm_plugin_conf_interested (plugin, "backlight.time_idle", CONF_TIME_IDLE_CHANGED); + ohm_plugin_conf_interested (plugin, "backlight.time_off", CONF_TIME_OFF_CHANGED); + + /* initial values */ + ohm_plugin_conf_get_key (plugin, "idle.system_idle", &(data.system_idle)); + ohm_plugin_conf_get_key (plugin, "backlight.value_ac", &(data.brightness_ac)); + ohm_plugin_conf_get_key (plugin, "backlight.value_idle", &(data.brightness_idle)); + ohm_plugin_conf_get_key (plugin, "backlight.time_idle", &(data.time_idle)); + ohm_plugin_conf_get_key (plugin, "backlight.time_off", &(data.time_off)); + + check_system_backlight_state (plugin); +} + +/** + * plugin_conf_notify: + * @plugin: This class instance + * + * Notify the plugin that a key marked with ohm_plugin_conf_interested () + * has it's value changed. + * An enumerated numeric id rather than the key is returned for processing speed. + */ +static void +plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) +{ + if (id == CONF_SYSTEM_IDLE_CHANGED) { + data.system_idle = value; + check_system_backlight_state (plugin); + } else if (id == CONF_BRIGHTNESS_AC_CHANGED) { + data.brightness_ac = value; + check_system_backlight_state (plugin); + } else if (id == CONF_BRIGHTNESS_IDLE_CHANGED) { + data.brightness_idle = value; + check_system_backlight_state (plugin); + } else if (id == CONF_TIME_IDLE_CHANGED) { + data.time_idle = value; + check_system_backlight_state (plugin); + } else if (id == CONF_TIME_OFF_CHANGED) { + data.time_off = value; + check_system_backlight_state (plugin); + } +} + +static OhmPluginInfo plugin_info = { + "OHM Backlight", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_load, /* load */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + plugin_conf_notify, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/powerstatus/.gitignore b/plugins/powerstatus/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/powerstatus/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/powerstatus/Makefile.am b/plugins/powerstatus/Makefile.am new file mode 100644 index 0000000..787e0c0 --- /dev/null +++ b/plugins/powerstatus/Makefile.am @@ -0,0 +1,20 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(GLIB_CFLAGS) \ + $(DBUS_CFLAGS) \ + $(GMODULE_CFLAGS) \ + -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ + -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" + +EXTRA_DIST = $(Data_DATA) +Datadir = $(sysconfdir)/ohm/plugins +Data_DATA = powerstatus + +lib_LTLIBRARIES = libpolicypowerstatus.la +libpolicypowerstatusincludedir = $(includedir)/ohm +libpolicypowerstatus_la_SOURCES = ohm-plugin-powerstatus.c +libpolicypowerstatus_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libpolicypowerstatus_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *~ diff --git a/plugins/powerstatus/README b/plugins/powerstatus/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/powerstatus/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/ohm-plugin-battery.c b/plugins/powerstatus/ohm-plugin-powerstatus.c index 59ee06a..99cfe74 100644 --- a/plugins/ohm-plugin-battery.c +++ b/plugins/powerstatus/ohm-plugin-powerstatus.c @@ -24,11 +24,20 @@ #include <ohm-plugin.h> enum { - CONF_BACKLIGHTCHANGED, - CONF_ACCHANGED, + CONF_PERCENT_LOW_CHANGED, + CONF_PERCENT_CRITICAL_CHANGED, + CONF_BATTERY_CHANGED, CONF_LAST }; +typedef struct { + gint percentage; + gint percentage_low; + gint percentage_critical; +} OhmPluginCacheData; + +OhmPluginCacheData data; + /** * plugin_load: * @plugin: This class instance @@ -40,29 +49,32 @@ enum { static void plugin_load (OhmPlugin *plugin) { - g_debug ("plug:load plugin %s", ohm_plugin_get_name (plugin)); - /* add in the required, suggested and prevented plugins */ -// ohm_plugin_require (plugin, "libmoo.so"); - ohm_plugin_suggest (plugin, "libtemperature.so"); - ohm_plugin_prevent (plugin, "libembedded.so"); + ohm_plugin_suggest (plugin, "libpluginbattery.so"); - /* tell ohmd what keys we are going to provide - don't set keys - * unless you provide them or you know a plugin you require provides them */ - ohm_plugin_conf_provide (plugin, "battery.percentage"); + /* tell ohmd what keys we are going to provide */ + ohm_plugin_conf_provide (plugin, "powerstatus.low"); + ohm_plugin_conf_provide (plugin, "powerstatus.critical"); } /** - * plugin_unload: + * check_system_power_state: * @plugin: This class instance * - * Called just beforet the plugin module is unloaded, and gives the plugin - * a chance to free private memory. + * Check the battery, and set the low and critical values if battery is low */ static void -plugin_unload (OhmPlugin *plugin) +check_system_power_state (OhmPlugin *plugin) { - g_debug ("plug:unload plugin"); + if (data.percentage < data.percentage_critical) { + ohm_plugin_conf_set_key (plugin, "powerstatus.low", 1); + ohm_plugin_conf_set_key (plugin, "powerstatus.critical", 1); + } else if (data.percentage < data.percentage_low) { + ohm_plugin_conf_set_key (plugin, "powerstatus.low", 1); + ohm_plugin_conf_set_key (plugin, "powerstatus.critical", 0); + } + ohm_plugin_conf_set_key (plugin, "powerstatus.low", 0); + ohm_plugin_conf_set_key (plugin, "powerstatus.critical", 0); } /** @@ -76,16 +88,17 @@ plugin_unload (OhmPlugin *plugin) static void plugin_coldplug (OhmPlugin *plugin) { - g_debug ("plug:coldplug"); - gint value; - ohm_plugin_conf_set_key (plugin, "battery.percentage", 99); - ohm_plugin_conf_get_key (plugin, "battery.percentage", &value); + /* interested keys */ + ohm_plugin_conf_interested (plugin, "battery.percentage", CONF_BATTERY_CHANGED); + ohm_plugin_conf_interested (plugin, "powerstatus.percentage_low", CONF_BATTERY_CHANGED); + ohm_plugin_conf_interested (plugin, "powerstatus.percentage_critical", CONF_BATTERY_CHANGED); - /* these don't have to be one enum per key, you can clump them as classes */ - ohm_plugin_conf_interested (plugin, "backlight.value_foo", CONF_BACKLIGHTCHANGED); - ohm_plugin_conf_interested (plugin, "system.ac_state", CONF_ACCHANGED); + /* initial values */ + ohm_plugin_conf_get_key (plugin, "battery.percentage", &(data.percentage)); + ohm_plugin_conf_get_key (plugin, "powerstatus.percentage_low", &(data.percentage_low)); + ohm_plugin_conf_get_key (plugin, "powerstatus.percentage_critical", &(data.percentage_critical)); - g_debug ("plug:got conf from plugin! %i", value); + check_system_power_state (plugin); } /** @@ -99,21 +112,24 @@ plugin_coldplug (OhmPlugin *plugin) static void plugin_conf_notify (OhmPlugin *plugin, gint id, gint value) { - g_debug ("plug:plugin_conf_notify %i: %i", id, value); - /* using an integer enumeration is much faster than a load of strcmp's */ - if (id == CONF_BACKLIGHTCHANGED) { - g_error ("plug:backlight changed, so maybe we need to update something or re-evaluate policy"); - } else if (id == CONF_ACCHANGED) { - g_error ("plug:ac status changed, so maybe we need to update something or re-evaluate policy"); + if (id == CONF_BATTERY_CHANGED) { + data.percentage = value; + check_system_power_state (plugin); + } else if (id == CONF_PERCENT_LOW_CHANGED) { + data.percentage_low = value; + check_system_power_state (plugin); + } else if (id == CONF_PERCENT_CRITICAL_CHANGED) { + data.percentage_critical = value; + check_system_power_state (plugin); } } static OhmPluginInfo plugin_info = { - "OHM HAL Battery", /* description */ + "OHM PowerStatus", /* description */ "0.0.1", /* version */ "richard@hughsie.com", /* author */ plugin_load, /* load */ - plugin_unload, /* unload */ + NULL, /* unload */ plugin_coldplug, /* coldplug */ plugin_conf_notify, /* conf_notify */ }; diff --git a/plugins/powerstatus/powerstatus b/plugins/powerstatus/powerstatus new file mode 100644 index 0000000..d3814e5 --- /dev/null +++ b/plugins/powerstatus/powerstatus @@ -0,0 +1,2 @@ +powerstatus.percentage_low 20 public +powerstatus.percentage_critical 10 public |