diff options
author | Richard Hughes <richard@hughsie.com> | 2007-01-23 12:57:34 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2007-01-23 12:57:34 +0000 |
commit | 80cea4e3eec8bcaf5da0a1079c9aa9214e93b3b0 (patch) | |
tree | 8e2e1d65f9e25eaf796e501fe4e6a292e240fbe8 | |
parent | 8029eeba0414bba409c96160d7d7fc8259fd7717 (diff) |
add the idle and acadapter plugins
Add the idle and AC adapter plugins, and re-work the core and other
plugins to actually do stuff when events happen.
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | etc/prevent | 2 | ||||
-rw-r--r-- | etc/suggest | 9 | ||||
-rw-r--r-- | ohmd/ohm-manager.c | 11 | ||||
-rw-r--r-- | ohmd/ohm-module.c | 2 | ||||
-rw-r--r-- | ohmd/ohm-plugin.c | 14 | ||||
-rw-r--r-- | plugins/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/acadapter/.gitignore | 8 | ||||
-rw-r--r-- | plugins/acadapter/Makefile.am | 21 | ||||
-rw-r--r-- | plugins/acadapter/README | 1 | ||||
-rw-r--r-- | plugins/acadapter/acadapter | 4 | ||||
-rw-r--r-- | plugins/acadapter/ohm-plugin-acadapter.c | 131 | ||||
-rw-r--r-- | plugins/backlight/Makefile.am | 10 | ||||
-rw-r--r-- | plugins/backlight/ohm-plugin-backlight.c | 26 | ||||
-rw-r--r-- | plugins/idle/.gitignore | 8 | ||||
-rw-r--r-- | plugins/idle/Makefile.am | 20 | ||||
-rw-r--r-- | plugins/idle/README | 1 | ||||
-rw-r--r-- | plugins/idle/idle | 2 | ||||
-rw-r--r-- | plugins/idle/ohm-plugin-idle.c | 64 | ||||
-rw-r--r-- | plugins/powerstatus/Makefile.am | 10 | ||||
-rw-r--r-- | plugins/powerstatus/ohm-plugin-powerstatus.c | 2 |
21 files changed, 318 insertions, 32 deletions
diff --git a/configure.in b/configure.in index 1cda845..b911e7c 100644 --- a/configure.in +++ b/configure.in @@ -151,6 +151,8 @@ ohm.conf Makefile etc/Makefile plugins/Makefile +plugins/acadapter/Makefile +plugins/idle/Makefile plugins/powerstatus/Makefile plugins/backlight/Makefile ohmd/Makefile diff --git a/etc/prevent b/etc/prevent index 92d50a0..3a37958 100644 --- a/etc/prevent +++ b/etc/prevent @@ -1,2 +1,2 @@ # This file should list all the modules that are banned, typically this should be empty -libembedded.so +embedded diff --git a/etc/suggest b/etc/suggest index 5231d75..f0c83d9 100644 --- a/etc/suggest +++ b/etc/suggest @@ -1,5 +1,6 @@ # This file should list all the modules that are suggested for coldplug -libacadapter.so -libpluginbattery.so -libpolicyexample.so -libpolicypowerstatus.so +acadapter +backlight +battery +idle +powerstatus diff --git a/ohmd/ohm-manager.c b/ohmd/ohm-manager.c index e4e26d6..79d7fda 100644 --- a/ohmd/ohm-manager.c +++ b/ohmd/ohm-manager.c @@ -158,7 +158,6 @@ ohm_manager_init (OhmManager *manager) { GError *error = NULL; DBusGConnection *connection; - gboolean ret; manager->priv = OHM_MANAGER_GET_PRIVATE (manager); /* get system bus connection */ @@ -178,16 +177,6 @@ ohm_manager_init (OhmManager *manager) 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); - /* 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-module.c b/ohmd/ohm-module.c index 67bdcfc..fd9a794 100644 --- a/ohmd/ohm-module.c +++ b/ohmd/ohm-module.c @@ -247,7 +247,7 @@ ohm_module_add_plugin (OhmModule *module, const gchar *name) OhmPlugin *plugin; gboolean ret; - /* play for now, we really need to read in from disk a list of modules to load */ + /* setup new plugin */ plugin = ohm_plugin_new (); g_signal_connect (plugin, "add-interested", G_CALLBACK (add_interested_cb), module); diff --git a/ohmd/ohm-plugin.c b/ohmd/ohm-plugin.c index 454e4aa..edd7347 100644 --- a/ohmd/ohm-plugin.c +++ b/ohmd/ohm-plugin.c @@ -108,12 +108,17 @@ ohm_plugin_load (OhmPlugin *plugin, const gchar *name) { gchar *path; GModule *handle; + gchar *filename; + GError *error = NULL; + gboolean ret; OhmPluginInfo * (*ohm_init_plugin) (OhmPlugin *); g_return_val_if_fail (name != NULL, FALSE); - path = g_build_filename (LIBDIR, name, NULL); + filename = g_strdup_printf ("libohm_%s.so", name); + path = g_build_filename (LIBDIR, filename, NULL); + g_free (filename); handle = g_module_open (path, 0); if (!handle) { ohm_debug ("opening module %s failed : %s", name, g_module_error ()); @@ -131,6 +136,13 @@ ohm_plugin_load (OhmPlugin *plugin, const gchar *name) plugin->priv->name = g_strdup (name); plugin->priv->info = ohm_init_plugin (plugin); + /* load defaults from disk */ + ret = ohm_conf_load_defaults (plugin->priv->conf, name, &error); + if (ret == FALSE) { + g_error ("could not load defaults : %s", error->message); + } + + /* do the load */ if (plugin->priv->info->load != NULL) { plugin->priv->info->load (plugin); } diff --git a/plugins/Makefile.am b/plugins/Makefile.am index fa7ceed..52b800b 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,4 +1,6 @@ SUBDIRS = \ + idle \ + acadapter \ powerstatus \ backlight diff --git a/plugins/acadapter/.gitignore b/plugins/acadapter/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/acadapter/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/acadapter/Makefile.am b/plugins/acadapter/Makefile.am new file mode 100644 index 0000000..4e8a90c --- /dev/null +++ b/plugins/acadapter/Makefile.am @@ -0,0 +1,21 @@ +INCLUDES = \ + -I$(top_srcdir)/ohmd \ + $(HAL_CFLAGS) \ + $(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 = acadapter + +lib_LTLIBRARIES = libohm_acadapter.la +libohm_acadapterincludedir = $(includedir)/ohm +libohm_acadapter_la_SOURCES = ohm-plugin-acadapter.c +libohm_acadapter_la_LIBADD = @HAL_LIBS@ @DBUS_LIBS@ $(INTLLIBS) +libohm_acadapter_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *~ diff --git a/plugins/acadapter/README b/plugins/acadapter/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/acadapter/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/acadapter/acadapter b/plugins/acadapter/acadapter new file mode 100644 index 0000000..333d199 --- /dev/null +++ b/plugins/acadapter/acadapter @@ -0,0 +1,4 @@ +# acadapter values + +#should not be public!!!! +acadapter.state 1 public diff --git a/plugins/acadapter/ohm-plugin-acadapter.c b/plugins/acadapter/ohm-plugin-acadapter.c new file mode 100644 index 0000000..c54bc54 --- /dev/null +++ b/plugins/acadapter/ohm-plugin-acadapter.c @@ -0,0 +1,131 @@ +/* + * 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 + */ + +#include <gmodule.h> +#include <glib.h> +#include <libhal.h> + +#include <ohm-plugin.h> + +enum { + CONF_LAST +}; + +typedef struct { + LibHalContext *ctx; + gchar *udi; +} OhmPluginCacheData; + +OhmPluginCacheData data; +OhmPlugin *plugin_global; /* ick, needed as there is no userdata with libhal */ + +/** + * 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) +{ + ohm_plugin_conf_provide (plugin, "acadapter.state"); + plugin_global = plugin; +} + +/** + * plugin_unload: + * @plugin: This class instance + * + * Called just before the plugin module is unloaded, and gives the plugin + * a chance to free private memory. + */ +static void +plugin_unload (OhmPlugin *plugin) +{ + if (data.udi != NULL) { + libhal_device_remove_property_watch (data.ctx, data.udi, NULL); + g_free (data.udi); + } + libhal_ctx_shutdown (data.ctx, NULL); +} + +static void +hal_property_changed_cb (LibHalContext *ctx, + const char *udi, + const char *key, + dbus_bool_t is_removed, + dbus_bool_t is_added) +{ + /* safe to assume this is always acadapter.state as only one device watched */ + gboolean state; + state = libhal_device_get_property_bool (ctx, udi, key, NULL); + ohm_plugin_conf_set_key (plugin_global, "acadapter.state", state); +} + +/** + * 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) +{ + char **devices; + int num_devices; + gboolean state; + DBusConnection *conn; + + conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL); + + data.ctx = libhal_ctx_new (); + libhal_ctx_set_dbus_connection (data.ctx, conn); + libhal_ctx_init (data.ctx, NULL); + libhal_ctx_set_device_property_modified (data.ctx, hal_property_changed_cb); + + devices = libhal_find_device_by_capability (data.ctx, "ac_adapter", &num_devices, NULL); + if (num_devices == 1) { + data.udi = g_strdup (devices[0]); + libhal_device_add_property_watch (data.ctx, data.udi, NULL); + state = libhal_device_get_property_bool (data.ctx, data.udi, "ac_adapter.present", NULL); + ohm_plugin_conf_set_key (plugin, "acadapter.state", state); + } else { + data.udi = NULL; + ohm_plugin_conf_set_key (plugin, "acadapter.state", 1); + g_warning ("not tested with not one acadapter"); + } + libhal_free_string_array (devices); +} + +static OhmPluginInfo plugin_info = { + "OHM HAL AC Adapter", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_load, /* load */ + plugin_unload, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/backlight/Makefile.am b/plugins/backlight/Makefile.am index 3527a04..3e3026a 100644 --- a/plugins/backlight/Makefile.am +++ b/plugins/backlight/Makefile.am @@ -10,11 +10,11 @@ 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 +lib_LTLIBRARIES = libohm_backlight.la +libohm_backlightincludedir = $(includedir)/ohm +libohm_backlight_la_SOURCES = ohm-plugin-backlight.c +libohm_backlight_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_backlight_la_LDFLAGS = -module -avoid-version clean-local: rm -f *~ diff --git a/plugins/backlight/ohm-plugin-backlight.c b/plugins/backlight/ohm-plugin-backlight.c index dac2499..3304ed5 100644 --- a/plugins/backlight/ohm-plugin-backlight.c +++ b/plugins/backlight/ohm-plugin-backlight.c @@ -30,8 +30,10 @@ #include <ohm-plugin.h> enum { + CONF_AC_STATE_CHANGED, CONF_SYSTEM_IDLE_CHANGED, CONF_BRIGHTNESS_AC_CHANGED, + CONF_BRIGHTNESS_BATTERY_CHANGED, CONF_BRIGHTNESS_IDLE_CHANGED, CONF_TIME_IDLE_CHANGED, CONF_TIME_OFF_CHANGED, @@ -39,10 +41,12 @@ enum { }; typedef struct { + gint ac_state; gint system_idle; gint state; gint brightness; gint brightness_ac; + gint brightness_battery; gint brightness_idle; gint time_idle; gint time_off; @@ -63,7 +67,8 @@ 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"); + ohm_plugin_suggest (plugin, "idle"); + ohm_plugin_suggest (plugin, "acadapter"); } /** @@ -84,12 +89,17 @@ check_system_backlight_state (OhmPlugin *plugin) data.state = 1; data.brightness = data.brightness_idle; } else { - /* set brightness to default */ + /* set brightness to default value */ data.state = 1; - data.brightness = data.brightness_ac; + if (data.ac_state == 1) { + data.brightness = data.brightness_ac; + } else { + data.brightness = data.brightness_battery; + } } ohm_plugin_conf_set_key (plugin, "backlight.state", data.state); ohm_plugin_conf_set_key (plugin, "backlight.brightness", data.brightness); + g_debug ("setting state %i and brightness %i", data.state, data.brightness); } /** @@ -104,15 +114,19 @@ static void plugin_coldplug (OhmPlugin *plugin) { /* interested keys */ + ohm_plugin_conf_interested (plugin, "acadapter.state", CONF_AC_STATE_CHANGED); 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_battery", CONF_BRIGHTNESS_BATTERY_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, "acadapter.state", &(data.ac_state)); 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_battery", &(data.brightness_battery)); 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)); @@ -134,9 +148,15 @@ 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_AC_STATE_CHANGED) { + data.ac_state = 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_BATTERY_CHANGED) { + data.brightness_battery = value; + check_system_backlight_state (plugin); } else if (id == CONF_BRIGHTNESS_IDLE_CHANGED) { data.brightness_idle = value; check_system_backlight_state (plugin); diff --git a/plugins/idle/.gitignore b/plugins/idle/.gitignore new file mode 100644 index 0000000..0ec65bf --- /dev/null +++ b/plugins/idle/.gitignore @@ -0,0 +1,8 @@ +.deps +.libs +Makefile +Makefile.in +*.la +*.lo +*.o +*~ diff --git a/plugins/idle/Makefile.am b/plugins/idle/Makefile.am new file mode 100644 index 0000000..6fa96e5 --- /dev/null +++ b/plugins/idle/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 = idle + +lib_LTLIBRARIES = libohm_idle.la +libohm_idleincludedir = $(includedir)/ohm +libohm_idle_la_SOURCES = ohm-plugin-idle.c +libohm_idle_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_idle_la_LDFLAGS = -module -avoid-version + +clean-local: + rm -f *~ diff --git a/plugins/idle/README b/plugins/idle/README new file mode 100644 index 0000000..0db68d7 --- /dev/null +++ b/plugins/idle/README @@ -0,0 +1 @@ +Todo diff --git a/plugins/idle/idle b/plugins/idle/idle new file mode 100644 index 0000000..a34f2c4 --- /dev/null +++ b/plugins/idle/idle @@ -0,0 +1,2 @@ +#should not be public!!!! +idle.system_idle 0 public diff --git a/plugins/idle/ohm-plugin-idle.c b/plugins/idle/ohm-plugin-idle.c new file mode 100644 index 0000000..66b2cce --- /dev/null +++ b/plugins/idle/ohm-plugin-idle.c @@ -0,0 +1,64 @@ +/* + * 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 + */ + +#include <gmodule.h> +#include <glib.h> + +#include <ohm-plugin.h> + +/** + * 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) +{ + /* tell ohmd what keys we are going to provide */ + ohm_plugin_conf_provide (plugin, "idle.system_idle"); +} + +/** + * 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) +{ +} + +static OhmPluginInfo plugin_info = { + "OHM PowerStatus", /* description */ + "0.0.1", /* version */ + "richard@hughsie.com", /* author */ + plugin_load, /* load */ + NULL, /* unload */ + plugin_coldplug, /* coldplug */ + NULL, /* conf_notify */ +}; + +OHM_INIT_PLUGIN (plugin_info); diff --git a/plugins/powerstatus/Makefile.am b/plugins/powerstatus/Makefile.am index 787e0c0..724685f 100644 --- a/plugins/powerstatus/Makefile.am +++ b/plugins/powerstatus/Makefile.am @@ -10,11 +10,11 @@ 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 +lib_LTLIBRARIES = libohm_powerstatus.la +libohm_powerstatusincludedir = $(includedir)/ohm +libohm_powerstatus_la_SOURCES = ohm-plugin-powerstatus.c +libohm_powerstatus_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) +libohm_powerstatus_la_LDFLAGS = -module -avoid-version clean-local: rm -f *~ diff --git a/plugins/powerstatus/ohm-plugin-powerstatus.c b/plugins/powerstatus/ohm-plugin-powerstatus.c index 99cfe74..d4ed19a 100644 --- a/plugins/powerstatus/ohm-plugin-powerstatus.c +++ b/plugins/powerstatus/ohm-plugin-powerstatus.c @@ -50,7 +50,7 @@ static void plugin_load (OhmPlugin *plugin) { /* add in the required, suggested and prevented plugins */ - ohm_plugin_suggest (plugin, "libpluginbattery.so"); + ohm_plugin_suggest (plugin, "battery"); /* tell ohmd what keys we are going to provide */ ohm_plugin_conf_provide (plugin, "powerstatus.low"); |