1*4035Sphitran /***************************************************************************
2*4035Sphitran  *
3*4035Sphitran  * addon-acpi.c : Poll battery and AC adapter devices and update
4*4035Sphitran  *                   properties
5*4035Sphitran  *
6*4035Sphitran  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
7*4035Sphitran  * Use is subject to license terms.
8*4035Sphitran  *
9*4035Sphitran  * Licensed under the Academic Free License version 2.1
10*4035Sphitran  *
11*4035Sphitran  **************************************************************************/
12*4035Sphitran 
13*4035Sphitran #pragma ident	"%Z%%M%	%I%	%E% SMI"
14*4035Sphitran 
15*4035Sphitran #ifdef HAVE_CONFIG_H
16*4035Sphitran #include <config.h>
17*4035Sphitran #endif
18*4035Sphitran 
19*4035Sphitran #include <stdio.h>
20*4035Sphitran #include <unistd.h>
21*4035Sphitran #include <stdlib.h>
22*4035Sphitran #include <fcntl.h>
23*4035Sphitran #include <sys/dkio.h>
24*4035Sphitran #include <sys/stat.h>
25*4035Sphitran #include <glib.h>
26*4035Sphitran 
27*4035Sphitran #include <libhal.h>
28*4035Sphitran #include "../../hald/logger.h"
29*4035Sphitran #include "../../hald/util_helper.h"
30*4035Sphitran #include "../../utils/battery.h"
31*4035Sphitran 
32*4035Sphitran int
33*4035Sphitran main(int argc, char **argv)
34*4035Sphitran {
35*4035Sphitran 	LibHalContext *ctx = NULL;
36*4035Sphitran 	DBusError error;
37*4035Sphitran 
38*4035Sphitran 	GMainLoop *loop = g_main_loop_new(NULL, FALSE);
39*4035Sphitran 
40*4035Sphitran 	drop_privileges(0);
41*4035Sphitran 	setup_logger();
42*4035Sphitran 
43*4035Sphitran 	dbus_error_init(&error);
44*4035Sphitran 	if ((ctx = libhal_ctx_init_direct(&error)) == NULL) {
45*4035Sphitran 		printf("main(): init_direct failed\n");
46*4035Sphitran 		return (0);
47*4035Sphitran 	}
48*4035Sphitran 	dbus_error_init(&error);
49*4035Sphitran 	if (!libhal_device_addon_is_ready(ctx, getenv("UDI"), &error)) {
50*4035Sphitran 		return (0);
51*4035Sphitran 	}
52*4035Sphitran 
53*4035Sphitran 	g_timeout_add(BATTERY_POLL_TIMER, update_devices, ctx);
54*4035Sphitran 
55*4035Sphitran 	g_main_loop_run(loop);
56*4035Sphitran }
57