xref: /titanic_41/usr/src/cmd/hal/addons/acpi/addon-acpi.c (revision d2ec54f7875f7e05edd56195adbeb593c947763f)
17b840e52Sphitran /***************************************************************************
27b840e52Sphitran  *
37b840e52Sphitran  * addon-acpi.c : Poll battery and AC adapter devices and update
47b840e52Sphitran  *                   properties
57b840e52Sphitran  *
6*d2ec54f7Sphitran  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
77b840e52Sphitran  * Use is subject to license terms.
87b840e52Sphitran  *
97b840e52Sphitran  * Licensed under the Academic Free License version 2.1
107b840e52Sphitran  *
117b840e52Sphitran  **************************************************************************/
127b840e52Sphitran 
137b840e52Sphitran #pragma ident	"%Z%%M%	%I%	%E% SMI"
147b840e52Sphitran 
157b840e52Sphitran #ifdef HAVE_CONFIG_H
167b840e52Sphitran #include <config.h>
177b840e52Sphitran #endif
187b840e52Sphitran 
197b840e52Sphitran #include <stdio.h>
207b840e52Sphitran #include <unistd.h>
217b840e52Sphitran #include <stdlib.h>
227b840e52Sphitran #include <fcntl.h>
237b840e52Sphitran #include <sys/dkio.h>
247b840e52Sphitran #include <sys/stat.h>
257b840e52Sphitran #include <glib.h>
267b840e52Sphitran 
277b840e52Sphitran #include <libhal.h>
287b840e52Sphitran #include "../../hald/logger.h"
297b840e52Sphitran #include "../../hald/util_helper.h"
30*d2ec54f7Sphitran #include "../../utils/acpi.h"
317b840e52Sphitran 
327b840e52Sphitran int
main(int argc,char ** argv)337b840e52Sphitran main(int argc, char **argv)
347b840e52Sphitran {
357b840e52Sphitran 	LibHalContext *ctx = NULL;
367b840e52Sphitran 	DBusError error;
377b840e52Sphitran 
387b840e52Sphitran 	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
397b840e52Sphitran 
407b840e52Sphitran 	drop_privileges(0);
417b840e52Sphitran 	setup_logger();
427b840e52Sphitran 
437b840e52Sphitran 	dbus_error_init(&error);
447b840e52Sphitran 	if ((ctx = libhal_ctx_init_direct(&error)) == NULL) {
457b840e52Sphitran 		printf("main(): init_direct failed\n");
467b840e52Sphitran 		return (0);
477b840e52Sphitran 	}
487b840e52Sphitran 	dbus_error_init(&error);
497b840e52Sphitran 	if (!libhal_device_addon_is_ready(ctx, getenv("UDI"), &error)) {
507b840e52Sphitran 		return (0);
517b840e52Sphitran 	}
527b840e52Sphitran 
537b840e52Sphitran 	g_timeout_add(BATTERY_POLL_TIMER, update_devices, ctx);
547b840e52Sphitran 
557b840e52Sphitran 	g_main_loop_run(loop);
567b840e52Sphitran }
57