diff options
author | Landry Breuil <landry@rhaalovely.net> | 2011-03-06 13:34:06 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2011-03-21 18:39:09 +0000 |
commit | f001a92ec540d12e22c04d31bd3ce9e24f57ea3b (patch) | |
tree | 1d4dac202231ca7023a27ff616f54fc9360f6842 /src/openbsd | |
parent | 07100772abb69814c046d81eaffa1be03c7e8272 (diff) | |
download | upower-f001a92ec540d12e22c04d31bd3ce9e24f57ea3b.tar.gz |
openbsd: add up_native_is_laptop()
Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'src/openbsd')
-rw-r--r-- | src/openbsd/up-native.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/openbsd/up-native.c b/src/openbsd/up-native.c index 7c21902..031b01a 100644 --- a/src/openbsd/up-native.c +++ b/src/openbsd/up-native.c @@ -43,3 +43,22 @@ up_native_get_native_path (GObject *object) { return up_apm_native_get_path (UP_APM_NATIVE (object)); } + +/** + * detect if we are on a desktop system or a laptop + * heuristic : laptop if sysctl hw.acpiac0 is present (TODO) or if apm acstate != APM_AC_UNKNOWN + */ +gboolean +up_native_is_laptop() +{ + int apm_fd; + struct apm_power_info bstate; + if ((apm_fd = open("/dev/apm", O_RDONLY)) == -1) { + if (errno != ENXIO && errno != ENOENT) + g_error("cannot open device file"); + } + if (-1 == ioctl(apm_fd, APM_IOC_GETPOWER, &bstate)) + g_error("ioctl on fd %d failed : %s", apm_fd, g_strerror(errno)); + close(apm_fd); + return bstate.ac_state != APM_AC_UNKNOWN; +} |