hal/hald/linux2 acpi.c,1.27,1.28
Danny Kukawka
dkukawka at freedesktop.org
Wed Aug 10 23:51:23 PDT 2005
Update of /cvs/hal/hal/hald/linux2
In directory gabe:/tmp/cvs-serv30016/hald/linux2
Modified Files:
acpi.c
Log Message:
2005-08-11 Danny Kukawka <danny.kukawka at web.de>
* hald/linux2/acpi.c (acpi_poll_battery), (acpi_poll_acadap),
(acpi_poll): Splitted acpi_poll() into acpi_poll_battery() and
acpi_poll_acadapt().
(battery_refresh):battery.present is now read
from /proc/acpi/battery/*/state instead of reading the information
from /proc/acpi/battery/*/info since reading from the info proc entry
takes very long on several systems. If a ACPI battery event occurs,
we now also gather the information for ac_adapter.present. This helps
to detect the AC online/offline state for machine which do not trigger
an ACPI event for AC online/offline but still report battery events
by an issuing ACPI event.
(ac_adapter_refresh_poll), (battery_refresh_poll),
(battery_poll_infrequently), (ac_adapter_refresh),
(acpi_synthesize_hotplug_events): Status for battery.reporting.last_full
is now read by battery_poll_infrequently (). This saves several
open/read calls to /proc/acpi/battery/*/{info,state} and enables
reuse of the information gathered (makes reopening of the {info,state}
proc entries unnecessary). battery_poll_infrequently () is invoked:
every 60 minutes and once a AC adapter ACPI event occurs. This prevents
open/read calls to /proc/acpi/battery/*/info more often then intended.
Index: acpi.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/acpi.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- acpi.c 2 Aug 2005 16:17:38 -0000 1.27
+++ acpi.c 11 Aug 2005 06:51:21 -0000 1.28
@@ -57,6 +57,16 @@
} ACPIDevHandler;
static void
+ac_adapter_refresh_poll (HalDevice *d)
+{
+ const char *path;
+ path = hal_device_property_get_string (d, "linux.acpi_path");
+ if (path == NULL)
+ return;
+ hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "state", "state", 0, "on-line", FALSE);
+}
+
+static void
battery_refresh_poll (HalDevice *d)
{
const char *path;
@@ -86,8 +96,6 @@
"state", "remaining capacity", 0, 10, TRUE);
hal_util_set_int_elem_from_file (d, "battery.reporting.rate", path,
"state", "present rate", 0, 10, TRUE);
- hal_util_set_int_elem_from_file (d, "battery.reporting.last_full", path,
- "info", "last full capacity", 0, 10, TRUE);
/*
* we'll need this if we need to convert mAh to mWh, but we should
* also update it here anyway as the value will have changed
@@ -165,6 +173,129 @@
;
}
+static void
+battery_poll_infrequently (gpointer data) {
+
+ GSList *i;
+ GSList *battery_devices;
+ HalDevice *d;
+ const char *path;
+
+ battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+ "battery.type",
+ "primary");
+
+ for (i = battery_devices; i != NULL; i = g_slist_next (i)) {
+ d = HAL_DEVICE (i->data);
+ if (hal_device_has_property (d, "linux.acpi_type") &&
+ hal_device_property_get_bool (d, "battery.present")) {
+ hal_util_grep_discard_existing_data ();
+ device_property_atomic_update_begin ();
+ path = hal_device_property_get_string (d, "linux.acpi_path");
+ if (path != NULL)
+ hal_util_set_int_elem_from_file (d, "battery.reporting.last_full", path,
+ "info", "last full capacity", 0, 10, TRUE);
+ device_property_atomic_update_end ();
+ }
+ }
+
+ g_slist_free (battery_devices);
+}
+
+
+static gboolean
+acpi_poll_battery ()
+{
+ GSList *i;
+ GSList *battery_devices;
+ HalDevice *d;
+
+ battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+ "battery.type",
+ "primary");
+ /*
+ * These forced updates take care of really broken BIOS's that don't
+ * emit batt events.
+ */
+ for (i = battery_devices; i != NULL; i = g_slist_next (i)) {
+ d = HAL_DEVICE (i->data);
+ if (hal_device_has_property (d, "linux.acpi_type") &&
+ hal_device_property_get_bool (d, "battery.present")) {
+ hal_util_grep_discard_existing_data ();
+ device_property_atomic_update_begin ();
+ battery_refresh_poll (d);
+ device_property_atomic_update_end ();
+ }
+ }
+
+ g_slist_free (battery_devices);
+ return TRUE;
+}
+
+static gboolean
+acpi_poll_acadap ()
+{
+ GSList *i;
+ GSList *acadap_devices;
+ HalDevice *d;
+
+ acadap_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
+ "info.category",
+ "ac_adapter");
+ /*
+ * These forced updates take care of really broken BIOS's that don't
+ * emit acad events.
+ */
+ for (i = acadap_devices; i != NULL; i = g_slist_next (i)) {
+ d = HAL_DEVICE (i->data);
+ if (hal_device_has_property (d, "linux.acpi_type")) {
+ hal_util_grep_discard_existing_data ();
+ device_property_atomic_update_begin ();
+ ac_adapter_refresh_poll (d);
+ device_property_atomic_update_end ();
+ }
+ }
+ g_slist_free (acadap_devices);
+ return TRUE;
+}
+
+static gboolean
+acpi_poll (gpointer data)
+{
+ /*
+ * These forced updates take care of really broken BIOS's that don't
+ * emit acad or acadapt events.
+ */
+ acpi_poll_acadap();
+ acpi_poll_battery();
+ return TRUE;
+}
+
+static gboolean
+ac_adapter_refresh (HalDevice *d, ACPIDevHandler *handler)
+{
+ const char *path;
+ path = hal_device_property_get_string (d, "linux.acpi_path");
+ if (path == NULL)
+ return FALSE;
+
+ device_property_atomic_update_begin ();
+ /* only set up device new if really needed */
+ if (!hal_device_has_capability (d, "ac_adapter")){
+ hal_device_property_set_string (d, "info.product", "AC Adapter");
+ hal_device_property_set_string (d, "info.category", "ac_adapter");
+ hal_device_add_capability (d, "ac_adapter");
+ }
+ /* get .present value */
+ ac_adapter_refresh_poll (d);
+ device_property_atomic_update_end ();
+
+ /* refresh last full if ac plugged in/out */
+ battery_poll_infrequently(NULL);
+
+ return TRUE;
+}
+
static gboolean
battery_refresh (HalDevice *d, ACPIDevHandler *handler)
{
@@ -190,7 +321,7 @@
/* Since we're using reuse==TRUE make sure we get fresh data for first read */
hal_util_grep_discard_existing_data ();
- hal_util_set_bool_elem_from_file (d, "battery.present", path, "info", "present", 0, "yes", TRUE);
+ hal_util_set_bool_elem_from_file (d, "battery.present", path, "state", "present", 0, "yes", TRUE);
if (!hal_device_property_get_bool (d, "battery.present")) {
device_property_atomic_update_begin ();
hal_device_property_remove (d, "battery.is_rechargeable");
@@ -346,6 +477,9 @@
battery_refresh_poll (d);
device_property_atomic_update_end ();
+
+ /* poll ac adapter for machines which n */
+ acpi_poll_acadap();
}
return TRUE;
@@ -387,35 +521,6 @@
return TRUE;
}
-static void
-ac_adapter_refresh_poll (HalDevice *d)
-{
- const char *path;
- path = hal_device_property_get_string (d, "linux.acpi_path");
- if (path == NULL)
- return;
- hal_util_set_bool_elem_from_file (d, "ac_adapter.present", path, "state", "state", 0, "on-line", FALSE);
-}
-
-static gboolean
-ac_adapter_refresh (HalDevice *d, ACPIDevHandler *handler)
-{
- const char *path;
- path = hal_device_property_get_string (d, "linux.acpi_path");
- if (path == NULL)
- return FALSE;
-
- device_property_atomic_update_begin ();
- hal_device_property_set_string (d, "info.product", "AC Adapter");
- hal_device_property_set_string (d, "info.category", "ac_adapter");
- hal_device_add_capability (d, "ac_adapter");
-
- /* get .present value */
- ac_adapter_refresh_poll (d);
- device_property_atomic_update_end ();
- return TRUE;
-}
-
static gboolean
button_refresh (HalDevice *d, ACPIDevHandler *handler)
{
@@ -491,50 +596,6 @@
}
-static gboolean
-acpi_poll (gpointer data)
-{
- GSList *i;
- GSList *battery_devices;
- GSList *acadap_devices;
- HalDevice *d;
-
- battery_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
- "battery.type",
- "primary");
- acadap_devices = hal_device_store_match_multiple_key_value_string (hald_get_gdl (),
- "info.category",
- "ac_adapter");
- /*
- * These forced updates take care of really broken BIOS's that don't
- * emit acad or batt events.
- */
- for (i = battery_devices; i != NULL; i = g_slist_next (i)) {
- d = HAL_DEVICE (i->data);
- if (hal_device_has_property (d, "linux.acpi_type") &&
- hal_device_property_get_bool (d, "battery.present")) {
- hal_util_grep_discard_existing_data ();
- device_property_atomic_update_begin ();
- battery_refresh_poll (d);
- device_property_atomic_update_end ();
- }
- }
- for (i = acadap_devices; i != NULL; i = g_slist_next (i)) {
- d = HAL_DEVICE (i->data);
- if (hal_device_has_property (d, "linux.acpi_type")) {
- hal_util_grep_discard_existing_data ();
- device_property_atomic_update_begin ();
- ac_adapter_refresh_poll (d);
- device_property_atomic_update_end ();
- }
- }
-
- g_slist_free (battery_devices);
- g_slist_free (acadap_devices);
-
- return TRUE;
-}
-
/** Scan the data structures exported by the kernel and add hotplug
* events for adding ACPI objects.
*
@@ -595,6 +656,10 @@
g_timeout_add (ACPI_POLL_INTERVAL,
acpi_poll,
NULL);
+ /* setup timer for things that we need only to poll infrequently*/
+ g_timeout_add (ACPI_POLL_INTERVAL*120,
+ battery_poll_infrequently,
+ NULL);
out:
return ret;
More information about the hal-commit
mailing list