Thu Nov 27 01:45:00 2008 UTC ()
Add basic battery and ac_adapter support using envsys on NetBSD.
Bump PKGREVISION.
(jmcneill)
diff -r1.8 -r1.9 pkgsrc/sysutils/hal/Makefile
diff -r1.1 -r1.2 pkgsrc/sysutils/hal/files/hald-netbsd/Makefile.am
diff -r1.1 -r1.2 pkgsrc/sysutils/hal/files/hald-netbsd/devinfo_misc.c
diff -r1.1 -r1.2 pkgsrc/sysutils/hal/files/hald-netbsd/osspec.c
diff -r0 -r1.1 pkgsrc/sysutils/hal/files/hald-netbsd/envsys.c
diff -r0 -r1.1 pkgsrc/sysutils/hal/files/hald-netbsd/envsys.h
--- pkgsrc/sysutils/hal/Makefile 2008/11/26 19:45:32 1.8
+++ pkgsrc/sysutils/hal/Makefile 2008/11/27 01:45:00 1.9
| @@ -1,18 +1,18 @@ | | | @@ -1,18 +1,18 @@ |
1 | # $NetBSD: Makefile,v 1.8 2008/11/26 19:45:32 jmcneill Exp $ | | 1 | # $NetBSD: Makefile,v 1.9 2008/11/27 01:45:00 jmcneill Exp $ |
2 | # | | 2 | # |
3 | | | 3 | |
4 | DISTNAME= hal-0.5.11 | | 4 | DISTNAME= hal-0.5.11 |
5 | PKGREVISION= 4 | | 5 | PKGREVISION= 5 |
6 | CATEGORIES= sysutils | | 6 | CATEGORIES= sysutils |
7 | MASTER_SITES= http://hal.freedesktop.org/releases/ | | 7 | MASTER_SITES= http://hal.freedesktop.org/releases/ |
8 | EXTRACT_SUFX= .tar.bz2 | | 8 | EXTRACT_SUFX= .tar.bz2 |
9 | | | 9 | |
10 | MAINTAINER= jmcneill@NetBSD.org | | 10 | MAINTAINER= jmcneill@NetBSD.org |
11 | HOMEPAGE= http://hal.freedesktop.org/ | | 11 | HOMEPAGE= http://hal.freedesktop.org/ |
12 | COMMENT= FreeDesktop hardware abstraction layer | | 12 | COMMENT= FreeDesktop hardware abstraction layer |
13 | | | 13 | |
14 | BUILD_DEFS+= VARBASE | | 14 | BUILD_DEFS+= VARBASE |
15 | | | 15 | |
16 | HAL_USER?= haldaemon | | 16 | HAL_USER?= haldaemon |
17 | HAL_GROUP?= haldaemon | | 17 | HAL_GROUP?= haldaemon |
18 | | | 18 | |
--- pkgsrc/sysutils/hal/files/hald-netbsd/Makefile.am 2008/11/25 23:10:23 1.1
+++ pkgsrc/sysutils/hal/files/hald-netbsd/Makefile.am 2008/11/27 01:45:00 1.2
| @@ -5,19 +5,19 @@ AM_CPPFLAGS = \ | | | @@ -5,19 +5,19 @@ AM_CPPFLAGS = \ |
5 | -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \ | | 5 | -DPACKAGE_SYSCONF_DIR=\""$(sysconfdir)"\" \ |
6 | -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ | | 6 | -DPACKAGE_DATA_DIR=\""$(datadir)"\" \ |
7 | -DPACKAGE_BIN_DIR=\""$(bindir)"\" \ | | 7 | -DPACKAGE_BIN_DIR=\""$(bindir)"\" \ |
8 | -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \ | | 8 | -DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \ |
9 | -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \ | | 9 | -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \ |
10 | -I$(top_srcdir) -I.. \ | | 10 | -I$(top_srcdir) -I.. \ |
11 | @GLIB_CFLAGS@ @DBUS_CFLAGS@ @POLKIT_CFLAGS@ | | 11 | @GLIB_CFLAGS@ @DBUS_CFLAGS@ @POLKIT_CFLAGS@ |
12 | | | 12 | |
13 | if HALD_COMPILE_NETBSD | | 13 | if HALD_COMPILE_NETBSD |
14 | noinst_LTLIBRARIES = libhald_netbsd.la | | 14 | noinst_LTLIBRARIES = libhald_netbsd.la |
15 | endif | | 15 | endif |
16 | | | 16 | |
17 | libhald_netbsd_la_SOURCES = \ | | 17 | libhald_netbsd_la_SOURCES = \ |
18 | osspec.c drvctl.c \ | | 18 | osspec.c drvctl.c envsys.c \ |
19 | devinfo.c devinfo_misc.c \ | | 19 | devinfo.c devinfo_misc.c \ |
20 | hotplug.c hal-file-monitor.c | | 20 | hotplug.c hal-file-monitor.c |
21 | # devinfo_pci.c devinfo_storage.c devinfo_usb.c | | 21 | # devinfo_pci.c devinfo_storage.c devinfo_usb.c |
22 | | | 22 | |
23 | libhald_netbsd_la_LDFLAGS = -lprop | | 23 | libhald_netbsd_la_LDFLAGS = -lprop |
--- pkgsrc/sysutils/hal/files/hald-netbsd/devinfo_misc.c 2008/11/25 23:10:23 1.1
+++ pkgsrc/sysutils/hal/files/hald-netbsd/devinfo_misc.c 2008/11/27 01:45:00 1.2
| @@ -107,28 +107,52 @@ devinfo_cpu_add(HalDevice *parent, const | | | @@ -107,28 +107,52 @@ devinfo_cpu_add(HalDevice *parent, const |
107 | HAL_INFO (("devinfo_cpu_add: parent=%p devnode=%s devfs_path=%s device_type=%s", | | 107 | HAL_INFO (("devinfo_cpu_add: parent=%p devnode=%s devfs_path=%s device_type=%s", |
108 | parent, devnode, devfs_path, device_type)); | | 108 | parent, devnode, devfs_path, device_type)); |
109 | | | 109 | |
110 | d = hal_device_new (); | | 110 | d = hal_device_new (); |
111 | | | 111 | |
112 | devinfo_set_default_properties (d, parent, devnode, devnode); | | 112 | devinfo_set_default_properties (d, parent, devnode, devnode); |
113 | hal_device_add_capability (d, "processor"); | | 113 | hal_device_add_capability (d, "processor"); |
114 | | | 114 | |
115 | devinfo_add_enqueue (d, devnode, &devinfo_cpu_handler); | | 115 | devinfo_add_enqueue (d, devnode, &devinfo_cpu_handler); |
116 | | | 116 | |
117 | return (d); | | 117 | return (d); |
118 | } | | 118 | } |
119 | | | 119 | |
| | | 120 | static void |
| | | 121 | devinfo_default_apply_quirks(HalDevice *d, const char *devnode) |
| | | 122 | { |
| | | 123 | |
| | | 124 | /* acpiacad(4) */ |
| | | 125 | if (strncmp (devnode, "acpiacad", 8) == 0) { |
| | | 126 | hal_device_add_capability (d, "ac_adapter"); |
| | | 127 | |
| | | 128 | /* acpibat(4) */ |
| | | 129 | } else if (strncmp (devnode, "acpibat", 7) == 0) { |
| | | 130 | HalDevice *computer; |
| | | 131 | |
| | | 132 | hal_device_add_capability (d, "battery"); |
| | | 133 | hal_device_property_set_string (d, "battery.type", "primary"); |
| | | 134 | |
| | | 135 | computer = hal_device_store_find(hald_get_gdl (), "/org/freedesktop/Hal/devices/computer"); |
| | | 136 | if (computer) |
| | | 137 | hal_device_property_set_string (computer, "system.formfactor", "laptop"); |
| | | 138 | } |
| | | 139 | |
| | | 140 | } |
| | | 141 | |
120 | static HalDevice * | | 142 | static HalDevice * |
121 | devinfo_default_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type) | | 143 | devinfo_default_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type) |
122 | { | | 144 | { |
123 | char *driver_name; | | 145 | char *driver_name; |
124 | const char *parent_path; | | 146 | const char *parent_path; |
125 | HalDevice *d; | | 147 | HalDevice *d; |
126 | | | 148 | |
127 | d = hal_device_new (); | | 149 | d = hal_device_new (); |
128 | | | 150 | |
129 | devinfo_set_default_properties (d, parent, devnode, devnode); | | 151 | devinfo_set_default_properties (d, parent, devnode, devnode); |
130 | | | 152 | |
| | | 153 | devinfo_default_apply_quirks (d, devnode); |
| | | 154 | |
131 | devinfo_add_enqueue (d, devnode, &devinfo_default_handler); | | 155 | devinfo_add_enqueue (d, devnode, &devinfo_default_handler); |
132 | | | 156 | |
133 | return (d); | | 157 | return (d); |
134 | } | | 158 | } |
--- pkgsrc/sysutils/hal/files/hald-netbsd/osspec.c 2008/11/25 23:10:23 1.1
+++ pkgsrc/sysutils/hal/files/hald-netbsd/osspec.c 2008/11/27 01:45:00 1.2
| @@ -22,44 +22,46 @@ | | | @@ -22,44 +22,46 @@ |
22 | #include <sys/types.h> | | 22 | #include <sys/types.h> |
23 | #include <sys/statvfs.h> | | 23 | #include <sys/statvfs.h> |
24 | | | 24 | |
25 | #include "../osspec.h" | | 25 | #include "../osspec.h" |
26 | #include "../logger.h" | | 26 | #include "../logger.h" |
27 | #include "../hald.h" | | 27 | #include "../hald.h" |
28 | #include "../hald_dbus.h" | | 28 | #include "../hald_dbus.h" |
29 | #include "../device_info.h" | | 29 | #include "../device_info.h" |
30 | #include "../util.h" | | 30 | #include "../util.h" |
31 | #include "../ids.h" | | 31 | #include "../ids.h" |
32 | #include "osspec_netbsd.h" | | 32 | #include "osspec_netbsd.h" |
33 | #include "hotplug.h" | | 33 | #include "hotplug.h" |
34 | #include "drvctl.h" | | 34 | #include "drvctl.h" |
| | | 35 | #include "envsys.h" |
35 | #include "devinfo.h" | | 36 | #include "devinfo.h" |
36 | #include "devinfo_storage.h" | | 37 | #include "devinfo_storage.h" |
37 | | | 38 | |
38 | static void mntinfo_event_init (); | | 39 | static void mntinfo_event_init (); |
39 | static gboolean mntinfo_timeout (gpointer user_data); | | 40 | static gboolean mntinfo_timeout (gpointer user_data); |
40 | | | 41 | |
41 | HalFileMonitor * | | 42 | HalFileMonitor * |
42 | osspec_get_file_monitor (void) | | 43 | osspec_get_file_monitor (void) |
43 | { | | 44 | { |
44 | #warning Please implement | | 45 | #warning Please implement |
45 | return NULL; | | 46 | return NULL; |
46 | } | | 47 | } |
47 | | | 48 | |
48 | void | | 49 | void |
49 | osspec_init (void) | | 50 | osspec_init (void) |
50 | { | | 51 | { |
51 | ids_init (); | | 52 | ids_init (); |
52 | mntinfo_event_init (); | | 53 | mntinfo_event_init (); |
| | | 54 | envsys_init (); |
53 | } | | 55 | } |
54 | | | 56 | |
55 | void | | 57 | void |
56 | osspec_privileged_init (void) | | 58 | osspec_privileged_init (void) |
57 | { | | 59 | { |
58 | drvctl_init (); | | 60 | drvctl_init (); |
59 | } | | 61 | } |
60 | | | 62 | |
61 | void | | 63 | void |
62 | hotplug_queue_now_empty (void) | | 64 | hotplug_queue_now_empty (void) |
63 | { | | 65 | { |
64 | if (hald_is_initialising) { | | 66 | if (hald_is_initialising) { |
65 | osspec_probe_done (); | | 67 | osspec_probe_done (); |
/* $NetBSD: envsys.c,v 1.1 2008/11/27 01:45:00 jmcneill Exp $ */
/*-
* Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/envsys.h>
#include <prop/proplib.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../osspec.h"
#include "../logger.h"
#include "../hald.h"
#include "../hald_dbus.h"
#include "../device_info.h"
#include "../util.h"
#include "devinfo.h"
#include "envsys.h"
#define _DEV_SYSMON "/dev/sysmon"
static int envsys_fd = -1;
static gboolean envsys_timeout(gpointer user_data);
static void envsys_handle_devnode(const char *devnode, prop_array_t properties);
static void envsys_acadapter_handler(HalDevice *d, prop_array_t properties);
static void envsys_battery_handler(HalDevice *d, prop_array_t properties);
static struct envsys_devmap {
const char *capability;
void (*handler)(HalDevice *d, prop_array_t properties);
} devmap[] = {
{ "ac_adapter", envsys_acadapter_handler },
{ "battery", envsys_battery_handler },
};
void
envsys_init(void)
{
envsys_fd = open (_DEV_SYSMON, O_RDONLY);
if (envsys_fd == -1) {
HAL_WARNING (("Couldn't open " _DEV_SYSMON ": %s", strerror(errno)));
return;
}
g_timeout_add (1000, envsys_timeout, NULL);
}
static gboolean
envsys_timeout(gpointer user_data)
{
prop_dictionary_t global_dict;
prop_array_t global_array;
prop_object_iterator_t iter;
prop_dictionary_keysym_t keysym;
int status;
status = prop_dictionary_recv_ioctl (envsys_fd, ENVSYS_GETDICTIONARY, &global_dict);
if (status) {
HAL_WARNING (("envsys_timeout: ENVSYS_GETDICTIONARY failed: %s", strerror(status)));
return FALSE;
}
global_array = prop_dictionary_all_keys (global_dict);
if (global_array == NULL) {
HAL_WARNING (("envsys_timeout: prop_dictionary_all_keys returned NULL"));
return FALSE;
}
iter = prop_array_iterator (global_array);
while ((keysym = (prop_dictionary_keysym_t)prop_object_iterator_next (iter)) != NULL) {
const char *devnode;
prop_object_t obj;
devnode = prop_dictionary_keysym_cstring_nocopy (keysym);
obj = prop_dictionary_get_keysym (global_dict, keysym);
if (obj == NULL || prop_object_type (obj) != PROP_TYPE_ARRAY)
continue;
envsys_handle_devnode (devnode, (prop_array_t)obj);
}
prop_object_iterator_release (iter);
prop_object_release (global_dict);
return TRUE;
}
static void
envsys_handle_devnode(const char *devnode, prop_array_t properties)
{
HalDevice *d;
unsigned int i;
d = hal_device_store_match_key_value_string (hald_get_gdl (), "netbsd.device", devnode);
if (d == NULL)
return;
for (i = 0; i < __arraycount (devmap); i++) {
if (!hal_device_has_capability (d, devmap[i].capability))
continue;
devmap[i].handler (d, properties);
}
return;
}
static void
envsys_acadapter_handler(HalDevice *d, prop_array_t properties)
{
prop_object_iterator_t iter;
prop_dictionary_t prop;
iter = prop_array_iterator (properties);
while ((prop = (prop_dictionary_t)prop_object_iterator_next (iter)) != NULL) {
const char *descr;
uint8_t connected;
if (prop_dictionary_get_cstring_nocopy (prop, "description", &descr) == false)
continue;
if (strcmp (descr, "connected") != 0)
continue;
if (prop_dictionary_get_uint8 (prop, "cur-value", &connected) == false)
continue;
hal_device_property_set_bool (d, "ac_adapter.present", connected);
}
prop_object_iterator_release (iter);
}
static void
envsys_battery_handler(HalDevice *d, prop_array_t properties)
{
prop_object_iterator_t iter;
prop_dictionary_t prop;
device_property_atomic_update_begin ();
hal_device_property_set_bool (d, "battery.is_rechargeable", TRUE);
iter = prop_array_iterator (properties);
while ((prop = (prop_dictionary_t)prop_object_iterator_next (iter)) != NULL) {
const char *descr;
const char *valid;
int64_t intval;
if (prop_dictionary_get_cstring_nocopy (prop, "description", &descr) == false)
continue;
if (prop_dictionary_get_int64 (prop, "cur-value", &intval) == false)
continue;
if (strcmp (descr, "present") == 0)
hal_device_property_set_bool (d, "battery.present", intval);
else if (strcmp (descr, "design cap") == 0)
hal_device_property_set_int (d, "battery.charge_level.design", intval);
else if (strcmp (descr, "last full cap") == 0)
hal_device_property_set_int (d, "battery.charge_level.last_full", intval);
else if (strcmp (descr, "charge") == 0) {
int64_t maxval;
hal_device_property_set_int (d, "battery.charge_level.current", intval);
if (prop_dictionary_get_int64 (prop, "max-value", &maxval) && maxval > 0)
hal_device_property_set_int (d, "battery.charge_level.percentage", intval * 100 / maxval);
else
hal_device_property_set_int (d, "battery.charge_level.percentage", 0);
}
else if (strcmp (descr, "charge rate") == 0) {
if (prop_dictionary_get_cstring_nocopy (prop, "state", &valid) == false)
continue;
if (strcmp (valid, "valid") == 0) {
hal_device_property_set_bool (d, "battery.rechargeable.is_charging", TRUE);
hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", FALSE);
hal_device_property_set_int (d, "battery.charge_level.rate", intval / 3600);
}
} else if (strcmp (descr, "discharge rate") == 0) {
if (prop_dictionary_get_cstring_nocopy (prop, "state", &valid) == false)
continue;
if (strcmp (valid, "valid") == 0) {
hal_device_property_set_bool (d, "battery.rechargeable.is_charging", FALSE);
hal_device_property_set_bool (d, "battery.rechargeable.is_discharging", TRUE);
hal_device_property_set_int (d, "battery.charge_level.rate", intval / 3600);
}
}
}
device_property_atomic_update_end ();
prop_object_iterator_release (iter);
}
/* $NetBSD: envsys.h,v 1.1 2008/11/27 01:45:00 jmcneill Exp $ */
/*-
* Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DEVINFO_ENVSYS_H
#define DEVINFO_ENVSYS_H
#include "devinfo.h"
void envsys_init(void);
#endif /* DEVINFO_ENVSYS_H */