16573Sphitran /***************************************************************************
26573Sphitran *
36573Sphitran * probe-acpi.c : Probe for ACPI device information
46573Sphitran *
5*8693SKerry.Shu@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
66573Sphitran * Use is subject to license terms.
76573Sphitran *
86573Sphitran * Licensed under the Academic Free License version 2.1
96573Sphitran *
106573Sphitran **************************************************************************/
116573Sphitran
126573Sphitran #ifdef HAVE_CONFIG_H
136573Sphitran #include <config.h>
146573Sphitran #endif
156573Sphitran
166573Sphitran #include <errno.h>
176573Sphitran #include <string.h>
186573Sphitran #include <strings.h>
196573Sphitran #include <ctype.h>
206573Sphitran #include <stdlib.h>
216573Sphitran #include <stdio.h>
226573Sphitran #include <sys/ioctl.h>
236573Sphitran #include <fcntl.h>
246573Sphitran #include <unistd.h>
256573Sphitran #include <glib.h>
266573Sphitran
276573Sphitran #include <libhal.h>
286573Sphitran #include <logger.h>
296573Sphitran #include "../utils/acpi.h"
306573Sphitran
316573Sphitran int
main(int argc,char * argv[])326573Sphitran main(int argc, char *argv[])
336573Sphitran {
346573Sphitran int ret = 1;
356573Sphitran int fd = -1;
366573Sphitran char *udi;
376573Sphitran char device_file[HAL_PATH_MAX] = "/devices";
386573Sphitran char *devfs_path;
396573Sphitran LibHalContext *ctx = NULL;
406573Sphitran DBusError error;
416573Sphitran
426573Sphitran if ((udi = getenv("UDI")) == NULL)
436573Sphitran goto out;
446573Sphitran if ((devfs_path = getenv("HAL_PROP_SOLARIS_DEVFS_PATH")) == NULL)
456573Sphitran goto out;
466573Sphitran strlcat(device_file, devfs_path, HAL_PATH_MAX);
476573Sphitran
486573Sphitran setup_logger();
496573Sphitran
506573Sphitran dbus_error_init(&error);
516573Sphitran if ((ctx = libhal_ctx_init_direct(&error)) == NULL)
526573Sphitran goto out;
536573Sphitran
546573Sphitran HAL_DEBUG(("Doing probe-acpi for %s (udi=%s)",
556573Sphitran device_file, udi));
566573Sphitran
576573Sphitran if ((fd = open(device_file, O_RDONLY | O_NONBLOCK)) < 0) {
586573Sphitran HAL_DEBUG(("Cannot open %s: %s", device_file, strerror(errno)));
596573Sphitran goto out;
606573Sphitran }
616573Sphitran if (strstr(udi, "_ac")) {
626573Sphitran ac_adapter_update(ctx, udi, fd);
636573Sphitran } else if (strstr(udi, "_battery")) {
646573Sphitran battery_update(ctx, udi, fd);
656573Sphitran } else if (strstr(udi, "_lid")) {
666573Sphitran lid_update(ctx, udi, fd);
67*8693SKerry.Shu@Sun.COM } else if (strstr(udi, "_hotkey")) {
686573Sphitran laptop_panel_update(ctx, udi, fd);
696573Sphitran }
706573Sphitran
716573Sphitran ret = 0;
726573Sphitran
736573Sphitran out:
746573Sphitran if (fd >= 0) {
756573Sphitran close(fd);
766573Sphitran }
776573Sphitran
786573Sphitran if (ctx != NULL) {
796573Sphitran libhal_ctx_shutdown(ctx, &error);
806573Sphitran libhal_ctx_free(ctx);
816573Sphitran if (dbus_error_is_set(&error)) {
826573Sphitran dbus_error_free(&error);
836573Sphitran }
846573Sphitran }
856573Sphitran
866573Sphitran return (ret);
876573Sphitran }
88