[PATCH 2/3] update plugins to new plugin interface

Rob Taylor rob.taylor at codethink.co.uk
Tue Jul 31 11:52:13 PDT 2007


Updates all the existing plugins to use the new plugin interface.
---
 plugins/glue/acadapter/ohm-plugin-acadapter.c      |   36 +++------
 plugins/glue/backlight/ohm-plugin-backlight.c      |   62 ++++++---------
 plugins/glue/battery/ohm-plugin-battery.c          |   37 +++-------
 plugins/glue/buttons/ohm-plugin-buttons.c          |   44 ++++-------
 plugins/glue/dpms/ohm-plugin-dpms.c                |   46 ++++--------
 plugins/glue/idle/ohm-plugin-idle.c                |   48 ++++--------
 plugins/glue/powerstatus/ohm-plugin-powerstatus.c  |   57 +++++---------
 .../glue/timeremaining/ohm-plugin-timeremaining.c  |   55 +++++---------
 plugins/glue/xorg/ohm-plugin-xorg.c                |   33 ++------
 plugins/glue/xrandr/ohm-plugin-xrandr.c            |   43 ++++-------
 plugins/policy/display/ohm-plugin-display.c        |   82 +++++++-------------
 plugins/policy/suspend/ohm-plugin-suspend.c        |   66 +++++-----------
 12 files changed, 203 insertions(+), 406 deletions(-)

diff --git a/plugins/glue/acadapter/ohm-plugin-acadapter.c b/plugins/glue/acadapter/ohm-plugin-acadapter.c
index ea4a24f..a2e1d79 100644
--- a/plugins/glue/acadapter/ohm-plugin-acadapter.c
+++ b/plugins/glue/acadapter/ohm-plugin-acadapter.c
@@ -23,21 +23,6 @@
 #include <string.h>
 #include <ohm-plugin.h>
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	ohm_plugin_conf_provide (plugin, "acadapter.state");
-	return TRUE;
-}
-
 static void
 hal_property_changed_cb (OhmPlugin   *plugin,
 			 guint        id,
@@ -51,7 +36,7 @@ hal_property_changed_cb (OhmPlugin   *plugin,
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -59,12 +44,12 @@ hal_property_changed_cb (OhmPlugin   *plugin,
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initalize (OhmPlugin *plugin)
 {
 	gboolean state;
 	guint num;
 
-	/* initialise HAL */
+	/* initalize HAL */
 	ohm_plugin_hal_init (plugin);
 
 	/* we want this function to get the property modified events for all devices */
@@ -82,14 +67,15 @@ plugin_coldplug (OhmPlugin *plugin)
 	ohm_plugin_conf_set_key (plugin, "acadapter.state", state);
 }
 
-static OhmPluginInfo plugin_info = {
+
+OHM_PLUGIN_DESCRIPTION (
 	"OHM HAL AC Adapter",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	NULL,				/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initalize,		/* initalize */
+	NULL,				/* destroy */
+	NULL				/* notify */
+);
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_PROVIDES("acadapter.state");
diff --git a/plugins/glue/backlight/ohm-plugin-backlight.c b/plugins/glue/backlight/ohm-plugin-backlight.c
index ea6be96..8950972 100644
--- a/plugins/glue/backlight/ohm-plugin-backlight.c
+++ b/plugins/glue/backlight/ohm-plugin-backlight.c
@@ -113,27 +113,6 @@ backlight_get_brightness (OhmPlugin *plugin, guint *brightness)
 }
 #endif
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* todo: split into dcon glue plugin */
-	ohm_plugin_conf_provide (plugin, "backlight.state");
-
-	/* tell ohmd what keys we are going to provide so it can create them */
-	ohm_plugin_conf_provide (plugin, "backlight.hardware_brightness");
-	ohm_plugin_conf_provide (plugin, "backlight.percent_brightness");
-	ohm_plugin_conf_provide (plugin, "backlight.num_levels");
-	return TRUE;
-}
-
 static guint
 percent_to_discrete (guint percentage,
 		     guint levels)
@@ -150,7 +129,7 @@ percent_to_discrete (guint percentage,
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -158,15 +137,13 @@ percent_to_discrete (guint percentage,
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initalize (OhmPlugin *plugin)
 {
 	guint num;
 
 	/* interested keys, either can be changed without changing the other  */
-	ohm_plugin_conf_interested (plugin, "backlight.hardware_brightness", CONF_BRIGHTNESS_HARDWARE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "backlight.percent_brightness", CONF_BRIGHTNESS_PERCENT_CHANGED);
 
-	/* initialise HAL */
+	/* initalize HAL */
 	ohm_plugin_hal_init (plugin);
 
 	/* get the only device with capability and watch it */
@@ -185,7 +162,7 @@ plugin_coldplug (OhmPlugin *plugin)
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -193,7 +170,7 @@ plugin_coldplug (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	guint hw;
 	if (id == CONF_BRIGHTNESS_PERCENT_CHANGED) {
@@ -205,14 +182,21 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
-	"OHM Backlight",		/* description */
-	"0.0.2",			/* version */
-	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
-
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_DESCRIPTION (
+	"OHM Backlight",
+	"0.0.2",
+	"richard at hughsie.com",
+	OHM_LICENSE_LGPL,
+	plugin_initalize,
+	NULL,
+	plugin_notify);
+
+OHM_PLUGIN_INTERESTED (
+	{"backlight.hardware_brightness", CONF_BRIGHTNESS_HARDWARE_CHANGED},
+	{"backlight.percent_brightness", CONF_BRIGHTNESS_PERCENT_CHANGED});
+
+OHM_PLUGIN_PROVIDES (
+	"backlight.state",
+	"backlight.hardware_brightness",
+	"backlight.percent_brightness",
+	"backlight.num_levels");
diff --git a/plugins/glue/battery/ohm-plugin-battery.c b/plugins/glue/battery/ohm-plugin-battery.c
index da48fe6..c51ceed 100644
--- a/plugins/glue/battery/ohm-plugin-battery.c
+++ b/plugins/glue/battery/ohm-plugin-battery.c
@@ -24,23 +24,6 @@
 
 #include <ohm-plugin.h>
 
-/**
- * plugin_preload:
- * @plugin: This class instance
- *
- * Called before the plugin is coldplug.
- * 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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* tell ohmd what keys we are going to provide - don't set keys
-	 * unless you provide them */
-	ohm_plugin_conf_provide (plugin, "battery.percentage");
-	return TRUE;
-}
-
 static void
 hal_property_changed_cb (OhmPlugin   *plugin,
 			 guint        id,
@@ -54,7 +37,7 @@ hal_property_changed_cb (OhmPlugin   *plugin,
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -62,12 +45,12 @@ hal_property_changed_cb (OhmPlugin   *plugin,
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initalize (OhmPlugin *plugin)
 {
 	gint state;
 	guint num;
 
-	/* initialise HAL */
+	/* initalize HAL */
 	ohm_plugin_hal_init (plugin);
 
 	/* we want this function to get the property modified events for all devices */
@@ -84,14 +67,14 @@ plugin_coldplug (OhmPlugin *plugin)
 	ohm_plugin_conf_set_key (plugin, "battery.percentage", state);
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM HAL Battery",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	NULL,				/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initalize,		/* initalize */
+	NULL,				/* destroy */
+	NULL				/* notify */
+);
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_PROVIDES ("battery.percentage");
diff --git a/plugins/glue/buttons/ohm-plugin-buttons.c b/plugins/glue/buttons/ohm-plugin-buttons.c
index 51ce216..3648899 100644
--- a/plugins/glue/buttons/ohm-plugin-buttons.c
+++ b/plugins/glue/buttons/ohm-plugin-buttons.c
@@ -23,23 +23,6 @@
 #include <string.h>
 #include <ohm-plugin.h>
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	ohm_plugin_conf_provide (plugin, "button.power");
-	ohm_plugin_conf_provide (plugin, "button.lid");
-	ohm_plugin_conf_provide (plugin, "button.tablet");
-	return TRUE;
-}
-
 static void
 hal_condition_cb (OhmPlugin   *plugin,
 		  guint        id,
@@ -64,17 +47,17 @@ hal_condition_cb (OhmPlugin   *plugin,
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  * @plugin: This class instance
  *
- * Coldplug, i.e. read and set the initial state of the plugin.
+ * 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)
+plugin_initalize (OhmPlugin *plugin)
 {
-	/* initialise HAL */
+	/* initalize HAL */
 	ohm_plugin_hal_init (plugin);
 
 	/* we want this function to get the property modified events for all devices */
@@ -89,14 +72,19 @@ plugin_coldplug (OhmPlugin *plugin)
 	ohm_plugin_conf_set_key (plugin, "button.tablet", 0);
 }
 
-static OhmPluginInfo plugin_info = {
+
+OHM_PLUGIN_DESCRIPTION (
 	"OHM HAL Buttons",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	NULL,				/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initalize,		/* initalize */
+	NULL,				/* destroy */
+	NULL				/* notify */
+);
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_PROVIDES (
+	"button.lid",
+	"button.power",
+	"button.tablet"
+);
diff --git a/plugins/glue/dpms/ohm-plugin-dpms.c b/plugins/glue/dpms/ohm-plugin-dpms.c
index 320e89b..603b5d7 100644
--- a/plugins/glue/dpms/ohm-plugin-dpms.c
+++ b/plugins/glue/dpms/ohm-plugin-dpms.c
@@ -47,21 +47,6 @@ typedef enum {
 	OHM_DPMS_MODE_OFF
 } OhmDpmsMode;
 
-/**
- * plugin_preload:
- *
- * 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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* add in the required, suggested and prevented plugins */
-	ohm_plugin_require (plugin, "backlight");
-	return TRUE;
-}
-
 
 /**
  * ohm_dpms_get_mode:
@@ -166,46 +151,43 @@ ohm_dpms_set_mode (OhmDpmsMode mode)
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  *
  * 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)
+plugin_initalize (OhmPlugin *plugin)
 {
 	/* we can assume DPMS is on */
 	ohm_plugin_conf_set_key (plugin, "backlight.state", 1);
 
-	/* interested keys */
-	ohm_plugin_conf_interested (plugin, "backlight.state", CONF_BACKLIGHT_STATE_CHANGED);
-
 	/* open display, need to free using XCloseDisplay */
 	dpy = XOpenDisplay (":0"); /* fixme: don't assume :0 */
 }
 
 /**
- * plugin_unload:
+ * plugin_destroy:
  *
  * Unload drivers, free memory.
  */
 static void
-plugin_unload (OhmPlugin *plugin)
+plugin_destroy (OhmPlugin *plugin)
 {
 	XCloseDisplay (dpy);
 	dpy = NULL;
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  *
  * 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)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_BACKLIGHT_STATE_CHANGED) {
 		if (value == 0) {
@@ -216,14 +198,16 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM DPMS",			/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	plugin_unload,			/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initalize,		/* initalize */
+	plugin_destroy,			/* destroy */
+	plugin_notify		/* notify */
+);
+
+OHM_PLUGIN_INTERESTED ({"backlight.state", CONF_BACKLIGHT_STATE_CHANGED});
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_REQUIRES ("backlight");
diff --git a/plugins/glue/idle/ohm-plugin-idle.c b/plugins/glue/idle/ohm-plugin-idle.c
index 499f006..31de93c 100644
--- a/plugins/glue/idle/ohm-plugin-idle.c
+++ b/plugins/glue/idle/ohm-plugin-idle.c
@@ -32,25 +32,6 @@ enum {
 	CONF_LAST
 };
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* tell ohmd what keys we are going to provide */
-	ohm_plugin_require (plugin, "xorg");
-	ohm_plugin_conf_provide (plugin, "idle.momentary");
-	ohm_plugin_conf_provide (plugin, "idle.powersave");
-	ohm_plugin_conf_provide (plugin, "idle.powerdown");
-	return TRUE;
-}
-
 static void
 ohm_alarm_expired_cb (LibIdletime *idletime, guint alarm, gpointer data)
 {
@@ -107,7 +88,7 @@ plugin_connect_idletime (OhmPlugin *plugin)
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initalize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -115,7 +96,7 @@ plugin_connect_idletime (OhmPlugin *plugin)
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initalize (OhmPlugin *plugin)
 {
 	gint value;
 
@@ -125,11 +106,10 @@ plugin_coldplug (OhmPlugin *plugin)
 		plugin_connect_idletime (plugin);
 	}
 
-	ohm_plugin_conf_interested (plugin, "xorg.has_xauthority", CONF_XORG_HASXAUTH_CHANGED);
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -137,7 +117,7 @@ plugin_coldplug (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_XORG_HASXAUTH_CHANGED) {
 		if (value == 1) {
@@ -146,19 +126,23 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 static void
-plugin_unload (OhmPlugin *plugin)
+plugin_destroy (OhmPlugin *plugin)
 {
 	g_object_unref (idletime);
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM IdleTime",			/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	plugin_unload,			/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initalize,		/* initalize */
+	plugin_destroy,			/* destroy */
+	plugin_notify		/* notify */
+);
+
+OHM_PLUGIN_REQUIRES ("xorg");
+
+OHM_PLUGIN_PROVIDES ("idle.momentary", "idle.powersave", "idle.powerdown");
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_INTERESTED ({"xorg.has_xauthority", CONF_XORG_HASXAUTH_CHANGED});
diff --git a/plugins/glue/powerstatus/ohm-plugin-powerstatus.c b/plugins/glue/powerstatus/ohm-plugin-powerstatus.c
index d07fdf7..aaf3baa 100644
--- a/plugins/glue/powerstatus/ohm-plugin-powerstatus.c
+++ b/plugins/glue/powerstatus/ohm-plugin-powerstatus.c
@@ -39,26 +39,6 @@ typedef struct {
 static OhmPluginCacheData data;
 
 /**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* add in the required, suggested and prevented plugins */
-	ohm_plugin_suggest (plugin, "battery");
-
-	/* tell ohmd what keys we are going to provide so it can create them */
-	ohm_plugin_conf_provide (plugin, "powerstatus.low");
-	ohm_plugin_conf_provide (plugin, "powerstatus.critical");
-	return TRUE;
-}
-
-/**
  * check_system_power_state:
  * @plugin: This class instance
  *
@@ -85,7 +65,7 @@ check_system_power_state (OhmPlugin *plugin)
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initialise:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -93,13 +73,8 @@ check_system_power_state (OhmPlugin *plugin)
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initialise (OhmPlugin *plugin)
 {
-	/* 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);
-
 	/* initial values */
 	ohm_plugin_conf_get_key (plugin, "battery.percentage", &(data.percentage));
 	ohm_plugin_conf_get_key (plugin, "powerstatus.percentage_low", &(data.percentage_low));
@@ -109,7 +84,7 @@ plugin_coldplug (OhmPlugin *plugin)
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -117,7 +92,7 @@ plugin_coldplug (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_BATTERY_CHANGED) {
 		data.percentage = value;
@@ -131,14 +106,24 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM PowerStatus",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initialise,		/* initialise */
+	NULL,				/* destroy */
+	plugin_notify			/* notify */
+);
+
+OHM_PLUGIN_SUGGESTS ("battery");
+
+OHM_PLUGIN_PROVIDES ("powerstatus.low", "powerstatus.critical");
+
+OHM_PLUGIN_INTERESTED (
+	{"battery.percentage", CONF_BATTERY_CHANGED},
+	{"powerstatus.percentage_low", CONF_BATTERY_CHANGED},
+	{"powerstatus.percentage_critical", CONF_BATTERY_CHANGED}
+);
+
 
-OHM_INIT_PLUGIN (plugin_info);
diff --git a/plugins/glue/timeremaining/ohm-plugin-timeremaining.c b/plugins/glue/timeremaining/ohm-plugin-timeremaining.c
index 7756b5d..611f458 100644
--- a/plugins/glue/timeremaining/ohm-plugin-timeremaining.c
+++ b/plugins/glue/timeremaining/ohm-plugin-timeremaining.c
@@ -37,27 +37,6 @@ typedef struct {
 static OhmPluginCacheData data;
 
 /**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* add in the required, suggested and prevented plugins */
-	ohm_plugin_suggest (plugin, "battery");
-	ohm_plugin_suggest (plugin, "acadapter");
-
-	/* tell ohmd what keys we are going to provide so it can create them */
-	ohm_plugin_conf_provide (plugin, "timeremaining.to_charge");
-	ohm_plugin_conf_provide (plugin, "timeremaining.to_discharge");
-	return TRUE;
-}
-
-/**
  * check_system_power_state:
  * @plugin: This class instance
  *
@@ -71,7 +50,7 @@ check_system_power_state (OhmPlugin *plugin)
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initialize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -79,12 +58,8 @@ check_system_power_state (OhmPlugin *plugin)
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initialize (OhmPlugin *plugin)
 {
-	/* interested keys */
-	ohm_plugin_conf_interested (plugin, "battery.percentage", CONF_BATTERY_PERCENT_CHANGED);
-	ohm_plugin_conf_interested (plugin, "acadapter.state", CONF_AC_STATE_CHANGED);
-
 	/* initial values */
 	ohm_plugin_conf_get_key (plugin, "battery.percentage", &(data.percentage));
 	ohm_plugin_conf_get_key (plugin, "acadapter.state", &(data.ac_state));
@@ -93,7 +68,7 @@ plugin_coldplug (OhmPlugin *plugin)
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -101,7 +76,7 @@ plugin_coldplug (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_BATTERY_PERCENT_CHANGED) {
 		data.percentage = value;
@@ -112,14 +87,22 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM timeremaining",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initialize,		/* initialize */
+	NULL,				/* destroy */
+	plugin_notify			/* notify */
+);
+
+OHM_PLUGIN_SUGGESTS ("battery", "acadapter");
+
+OHM_PLUGIN_PROVIDES ("timeremaining.to_charge", "timeremaining.to_discharge");
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_INTERESTED (
+	{"battery.percentage", CONF_BATTERY_PERCENT_CHANGED},
+	{"acadapter.state", CONF_AC_STATE_CHANGED}
+);
+	
diff --git a/plugins/glue/xorg/ohm-plugin-xorg.c b/plugins/glue/xorg/ohm-plugin-xorg.c
index 0758700..3f0b226 100644
--- a/plugins/glue/xorg/ohm-plugin-xorg.c
+++ b/plugins/glue/xorg/ohm-plugin-xorg.c
@@ -28,21 +28,6 @@
 
 #include <ohm-plugin.h>
 
-/**
- * plugin_preload:
- *
- * 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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	/* add in the required, suggested and prevented plugins */
-	ohm_plugin_conf_provide (plugin, "xorg.has_xauthority");
-	return TRUE;
-}
-
 static gboolean
 plugin_poll_startup (gpointer data)
 {
@@ -74,14 +59,14 @@ plugin_poll_startup (gpointer data)
 }
 
 /**
- * plugin_coldplug:
+ * plugin_initialize:
  *
  * 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)
+plugin_initialize (OhmPlugin *plugin)
 {
 	gboolean ret;
 
@@ -97,14 +82,14 @@ plugin_coldplug (OhmPlugin *plugin)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM xorg finder",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	NULL,				/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initialize,		/* initialize */
+	NULL,				/* destroy */
+	NULL				/* notify */
+);
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_PROVIDES ("xorg.has_xauthority");
diff --git a/plugins/glue/xrandr/ohm-plugin-xrandr.c b/plugins/glue/xrandr/ohm-plugin-xrandr.c
index 5dc4805..628e3f8 100644
--- a/plugins/glue/xrandr/ohm-plugin-xrandr.c
+++ b/plugins/glue/xrandr/ohm-plugin-xrandr.c
@@ -29,23 +29,7 @@ enum {
 };
 
 /**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (OhmPlugin *plugin)
-{
-	ohm_plugin_require (plugin, "xorg");
-	ohm_plugin_conf_provide (plugin, "xrandr.position");
-	return TRUE;
-}
-
-/**
- * plugin_coldplug:
+ * plugin_initialize:
  * @plugin: This class instance
  *
  * Coldplug, i.e. read and set the initial state of the plugin.
@@ -53,14 +37,13 @@ plugin_preload (OhmPlugin *plugin)
  * dangerous to assume the key values are anything other than the defaults.
  */
 static void
-plugin_coldplug (OhmPlugin *plugin)
+plugin_initialize (OhmPlugin *plugin)
 {
 	ohm_plugin_conf_set_key (plugin, "xrandr.position", 0);
-	ohm_plugin_conf_interested (plugin, "xrandr.position", CONF_XRANDR_POSITION_CHANGED);
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -68,7 +51,7 @@ plugin_coldplug (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_XRANDR_POSITION_CHANGED) {
 		if (value == 0) {
@@ -79,14 +62,18 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"OHM HAL XRANDR",		/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
+	OHM_LICENSE_LGPL,		/* license */
+	plugin_initialize,		/* initialize */
+	NULL,				/* destroy */
+	plugin_notify			/* notify */
+);
+
+OHM_PLUGIN_REQUIRES ("xorg");
+
+OHM_PLUGIN_PROVIDES ("xrandr.position");
 
-OHM_INIT_PLUGIN (plugin_info);
+OHM_PLUGIN_INTERESTED ({"xrandr.position", CONF_XRANDR_POSITION_CHANGED});
diff --git a/plugins/policy/display/ohm-plugin-display.c b/plugins/policy/display/ohm-plugin-display.c
index 5e26e8f..a81f1d2 100644
--- a/plugins/policy/display/ohm-plugin-display.c
+++ b/plugins/policy/display/ohm-plugin-display.c
@@ -35,50 +35,6 @@ enum {
 	CONF_LAST
 };
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (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, "idle");
-	ohm_plugin_suggest (plugin, "acadapter");
-	ohm_plugin_suggest (plugin, "buttons");
-	ohm_plugin_suggest (plugin, "xrandr");
-	ohm_plugin_suggest (plugin, "backlight");
-	return TRUE;
-}
-
-/**
- * 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, "acadapter.state", CONF_AC_STATE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "backlight.state", CONF_BACKLIGHT_STATE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "button.lid", CONF_LID_STATE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "button.tablet", CONF_TABLET_STATE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "idle.powersave", CONF_IDLE_POWERSAVE_CHANGED);
-	ohm_plugin_conf_interested (plugin, "idle.momentary", CONF_IDLE_MOMENTARY_CHANGED);
-	ohm_plugin_conf_interested (plugin, "display.value_ac", CONF_BRIGHTNESS_AC_CHANGED);
-	ohm_plugin_conf_interested (plugin, "display.value_battery", CONF_BRIGHTNESS_BATTERY_CHANGED);
-	ohm_plugin_conf_interested (plugin, "display.value_idle", CONF_BRIGHTNESS_IDLE_CHANGED);
-}
-
 static void
 reset_brightness (OhmPlugin *plugin)
 {
@@ -175,7 +131,7 @@ lid_closed (OhmPlugin *plugin, gboolean is_closed)
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -183,7 +139,7 @@ lid_closed (OhmPlugin *plugin, gboolean is_closed)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	switch (id) {
 	case CONF_BRIGHTNESS_AC_CHANGED:
@@ -214,14 +170,32 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"Display",			/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
-
-OHM_INIT_PLUGIN (plugin_info);
+	OHM_LICENSE_LGPL,		/* license */
+	NULL,				/* initialize */
+	NULL,				/* destroy */
+	plugin_notify			/* notify */
+);
+
+OHM_PLUGIN_SUGGESTS (
+	"idle",
+	"acadapter",
+	"buttons",
+	"xrandr",
+	"backlight"
+);
+
+OHM_PLUGIN_INTERESTED (
+	{"acadapter.state", CONF_AC_STATE_CHANGED},
+	{"backlight.state", CONF_BACKLIGHT_STATE_CHANGED},
+	{"button.lid", CONF_LID_STATE_CHANGED},
+	{"button.tablet", CONF_TABLET_STATE_CHANGED},
+	{"idle.powersave", CONF_IDLE_POWERSAVE_CHANGED},
+	{"idle.momentary", CONF_IDLE_MOMENTARY_CHANGED},
+	{"display.value_ac", CONF_BRIGHTNESS_AC_CHANGED},
+	{"display.value_battery", CONF_BRIGHTNESS_BATTERY_CHANGED},
+	{"display.value_idle", CONF_BRIGHTNESS_IDLE_CHANGED}
+);
diff --git a/plugins/policy/suspend/ohm-plugin-suspend.c b/plugins/policy/suspend/ohm-plugin-suspend.c
index 712464d..2c3d5c5 100644
--- a/plugins/policy/suspend/ohm-plugin-suspend.c
+++ b/plugins/policy/suspend/ohm-plugin-suspend.c
@@ -74,42 +74,6 @@ system_suspend (OhmPlugin *plugin)
 	return ret;
 }
 
-/**
- * plugin_preload:
- * @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 gboolean
-plugin_preload (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, "idle");
-	ohm_plugin_suggest (plugin, "buttons");
-	return TRUE;
-}
-
-/**
- * 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, "button.power", CONF_BUTTON_POWER_CHANGED);
-	ohm_plugin_conf_interested (plugin, "button.lid", CONF_BUTTON_LID_CHANGED);
-	ohm_plugin_conf_interested (plugin, "idle.powerdown", CONF_IDLE_POWERDOWN_CHANGED);
-	ohm_plugin_conf_interested (plugin, "suspend.fixme_inhibit", CONF_INHIBIT_CHANGED);
-}
-
 static void
 power_button_pressed (OhmPlugin *plugin)
 {
@@ -163,7 +127,7 @@ system_is_idle (OhmPlugin *plugin)
 }
 
 /**
- * plugin_conf_notify:
+ * plugin_notify:
  * @plugin: This class instance
  *
  * Notify the plugin that a key marked with ohm_plugin_conf_interested ()
@@ -171,7 +135,7 @@ system_is_idle (OhmPlugin *plugin)
  * An enumerated numeric id rather than the key is returned for processing speed.
  */
 static void
-plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
+plugin_notify (OhmPlugin *plugin, gint id, gint value)
 {
 	if (id == CONF_BUTTON_LID_CHANGED) {
 		if (value == 1) {
@@ -192,14 +156,24 @@ plugin_conf_notify (OhmPlugin *plugin, gint id, gint value)
 	}
 }
 
-static OhmPluginInfo plugin_info = {
+OHM_PLUGIN_DESCRIPTION (
 	"suspend",			/* description */
 	"0.0.1",			/* version */
 	"richard at hughsie.com",		/* author */
-	plugin_preload,			/* preload */
-	NULL,				/* unload */
-	plugin_coldplug,		/* coldplug */
-	plugin_conf_notify,		/* conf_notify */
-};
-
-OHM_INIT_PLUGIN (plugin_info);
+	OHM_LICENSE_LGPL,		/* license */
+	NULL,				/* initialize */
+	NULL,				/* destroy */
+	plugin_notify			/* notify */
+);
+
+OHM_PLUGIN_SUGGESTS (
+	"idle",
+	"buttons"
+);
+
+OHM_PLUGIN_INTERESTED (
+	{"button.power", CONF_BUTTON_POWER_CHANGED},
+	{"button.lid", CONF_BUTTON_LID_CHANGED},
+	{"idle.powerdown", CONF_IDLE_POWERDOWN_CHANGED},
+	{"suspend.fixme_inhibit", CONF_INHIBIT_CHANGED}
+);
-- 
1.5.3.GIT


--------------040904070102060909030406--


More information about the Ohm-devel mailing list