[Pommed-commits] r433 - in trunk: . pommed/mactel
jblache at alioth.debian.org
jblache at alioth.debian.org
Fri Feb 8 20:34:57 UTC 2008
Author: jblache
Date: 2008-02-08 20:34:57 +0000 (Fri, 08 Feb 2008)
New Revision: 433
Modified:
trunk/ChangeLog
trunk/pommed/mactel/acpi.c
Log:
Add power_supply class support to the ACPI code.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-01-23 13:33:31 UTC (rev 432)
+++ trunk/ChangeLog 2008-02-08 20:34:57 UTC (rev 433)
@@ -3,6 +3,7 @@
version 1.15:
- pommed: add support for the MacBook Air1,1.
+ - pommed: add support for power_supply class to the ACPI code.
version 1.14:
- pommed: fix error handling in the audio sample loading code to
Modified: trunk/pommed/mactel/acpi.c
===================================================================
--- trunk/pommed/mactel/acpi.c 2008-01-23 13:33:31 UTC (rev 432)
+++ trunk/pommed/mactel/acpi.c 2008-02-08 20:34:57 UTC (rev 433)
@@ -3,7 +3,7 @@
*
* $Id$
*
- * Copyright (C) 2006-2007 Julien BLACHE <jb at jblache.org>
+ * Copyright (C) 2006-2008 Julien BLACHE <jb at jblache.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -27,20 +28,72 @@
#include "../power.h"
-#define ACPI_AC_STATE "/proc/acpi/ac_adapter/ADP1/state"
-#define ACPI_AC_ONLINE "on-line\n"
-#define ACPI_AC_OFFLINE "off-line\n"
+#define SYSFS_ACPI_AC_STATE "/sys/class/power_supply/ADP1/online"
+#define PROC_ACPI_AC_STATE "/proc/acpi/ac_adapter/ADP1/state"
+#define PROC_ACPI_AC_ONLINE "on-line\n"
+#define PROC_ACPI_AC_OFFLINE "off-line\n"
+
+static int
+proc_check_ac_state(void);
+
+static int
+sysfs_check_ac_state(void);
+
+
/* Internal API */
int
check_ac_state(void)
{
+ if (access(SYSFS_ACPI_AC_STATE, R_OK))
+ return sysfs_check_ac_state();
+ else
+ return proc_check_ac_state();
+}
+
+
+/* sysfs power_supply class variant */
+static int
+sysfs_check_ac_state(void)
+{
FILE *fp;
+ char ac_state;
+ int ret;
+
+ fp = fopen(SYSFS_ACPI_AC_STATE, "r");
+ if (fp == NULL)
+ return AC_STATE_ERROR;
+
+ ret = fread(&ac_state, 1, 1, fp);
+
+ if (ferror(fp) != 0)
+ {
+ logdebug("acpi: Error reading sysfs AC state: %s\n", strerror(errno));
+ return AC_STATE_ERROR;
+ }
+
+ fclose(fp);
+
+ if (ac_state == '1')
+ return AC_STATE_ONLINE;
+
+ if (ac_state == '0')
+ return AC_STATE_OFFLINE;
+
+ return AC_STATE_UNKNOWN;
+}
+
+
+/* procfs variant */
+static int
+proc_check_ac_state(void)
+{
+ FILE *fp;
char buf[128];
int ret;
- fp = fopen(ACPI_AC_STATE, "r");
+ fp = fopen(PROC_ACPI_AC_STATE, "r");
if (fp == NULL)
return AC_STATE_ERROR;
@@ -48,13 +101,13 @@
if (ferror(fp) != 0)
{
- logdebug("acpi: Error reading AC state: %s\n", strerror(errno));
+ logdebug("acpi: Error reading proc AC state: %s\n", strerror(errno));
return AC_STATE_ERROR;
}
if (feof(fp) == 0)
{
- logdebug("acpi: Error reading AC state: buffer too small\n");
+ logdebug("acpi: Error reading proc AC state: buffer too small\n");
return AC_STATE_ERROR;
}
@@ -62,10 +115,10 @@
buf[ret] = '\0';
- if (strstr(buf, ACPI_AC_ONLINE) != NULL)
+ if (strstr(buf, PROC_ACPI_AC_ONLINE) != NULL)
return AC_STATE_ONLINE;
- if (strstr(buf, ACPI_AC_OFFLINE) != NULL)
+ if (strstr(buf, PROC_ACPI_AC_OFFLINE) != NULL)
return AC_STATE_OFFLINE;
return AC_STATE_UNKNOWN;
More information about the Pommed-commits
mailing list