summaryrefslogtreecommitdiff
path: root/battstat/power-management.c
diff options
context:
space:
mode:
Diffstat (limited to 'battstat/power-management.c')
-rw-r--r--battstat/power-management.c76
1 files changed, 60 insertions, 16 deletions
diff --git a/battstat/power-management.c b/battstat/power-management.c
index 53ae081a..94d1adf6 100644
--- a/battstat/power-management.c
+++ b/battstat/power-management.c
@@ -41,6 +41,7 @@
#include "battstat.h"
#include "battstat-hal.h"
+#include "battstat-upower.h"
#define ERR_ACPID _("Can't access ACPI events in /var/run/acpid.socket! " \
"Make sure the ACPI subsystem is working and " \
@@ -66,6 +67,9 @@ static int pm_initialised;
#ifdef HAVE_HAL
static int using_hal;
#endif
+#ifdef HAVE_UPOWER
+static int using_upower;
+#endif
/*
* What follows is a series of platform-specific apm_readinfo functions
@@ -390,13 +394,21 @@ power_management_getinfo( BatteryStatus *status )
return NULL;
}
-#ifdef HAVE_HAL
- if( using_hal )
- {
- battstat_hal_get_battery_info( status );
- return NULL;
- }
-#endif
+ #ifdef HAVE_UPOWER
+ if( using_upower)
+ {
+ battstat_upower_get_battery_info( status );
+ return NULL;
+ }
+ #endif
+
+ #ifdef HAVE_HAL
+ if( using_hal )
+ {
+ battstat_hal_get_battery_info( status );
+ return NULL;
+ }
+ #endif
retval = apm_readinfo( status );
@@ -430,22 +442,19 @@ power_management_getinfo( BatteryStatus *status )
const char *
power_management_initialise (int no_hal, void (*callback) (void))
{
+ char *err;
+ err = g_strdup( ":(" );
#ifdef __linux__
struct stat statbuf;
#endif
-#ifdef HAVE_HAL
- char *err;
- if( no_hal )
- err = g_strdup( ":(" );
- else
- err = battstat_hal_initialise (callback);
+#ifdef HAVE_UPOWER
+ err = battstat_upower_initialise (callback);
-
- if( err == NULL ) /* HAL is up */
+ if( err == NULL ) /* UPOWER is up */
{
pm_initialised = 1;
- using_hal = TRUE;
+ using_upower = TRUE;
return NULL;
}
else
@@ -453,6 +462,22 @@ power_management_initialise (int no_hal, void (*callback) (void))
g_free( err );
#endif
+#ifdef HAVE_HAL
+ if(! no_hal ) {
+ err = battstat_hal_initialise (callback);
+
+ if( err == NULL) /* HAL is up */
+ {
+ pm_initialised = 1;
+ using_hal = TRUE;
+ return NULL;
+ }
+ }
+
+ /* fallback to legacy methods */
+ g_free( err );
+#endif
+
#ifdef __linux__
if (acpi_linux_init(&acpiinfo)) {
@@ -498,6 +523,15 @@ power_management_initialise (int no_hal, void (*callback) (void))
void
power_management_cleanup( void )
{
+#ifdef HAVE_UPOWER
+ if( using_upower)
+ {
+ battstat_upower_cleanup();
+ pm_initialised = 1;
+ return;
+ }
+#endif
+
#ifdef HAVE_HAL
if( using_hal )
{
@@ -525,6 +559,16 @@ power_management_cleanup( void )
}
int
+power_management_using_upower( void)
+{
+#ifdef HAVE_UPOWER
+ return using_upower;
+#else
+ return 0;
+#endif
+}
+
+int
power_management_using_hal( void )
{
#ifdef HAVE_HAL