hal/hald/linux2/addons Makefile.am,1.5,1.6 addon-pmu.c,NONE,1.1

David Zeuthen david at freedesktop.org
Sun May 8 20:43:28 PDT 2005


Update of /cvs/hal/hal/hald/linux2/addons
In directory gabe:/tmp/cvs-serv17086/hald/linux2/addons

Modified Files:
	Makefile.am 
Added Files:
	addon-pmu.c 
Log Message:
2005-05-08  David Zeuthen  <davidz at redhat.com>

        * hald/linux2/addons/addon-pmu.c: New file (polls /dev/apm for
        lid button events)

        * hald/linux2/addons/Makefile.am (libexec_PROGRAMS): Also build
        hald-addon-pmu

        * hald/linux2/pmu.c (battery_refresh): Support battery.current
        (lid_button_refresh): New function
        (pmu_lid_compute_udi): New function
        (pmu_poll): New function
        (pmu_synthesize_hotplug_events): Add lid object and setup a timeout
        for polling

        * fdi/policy/10osvendor/10-power-mgmt-policy.fdi: Run the pmu addon
        to detect lid button events.



Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/addons/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile.am	5 Apr 2005 16:31:31 -0000	1.5
+++ Makefile.am	9 May 2005 03:43:26 -0000	1.6
@@ -8,7 +8,7 @@
 	-I$(top_srcdir) \
 	@PACKAGE_CFLAGS@
 
-libexec_PROGRAMS  = hald-addon-hid-ups hald-addon-acpi hald-addon-storage
+libexec_PROGRAMS  = hald-addon-hid-ups hald-addon-acpi hald-addon-storage hald-addon-pmu
 
 if HAVE_LIBUSB
 libexec_PROGRAMS += hald-addon-usb-csr
@@ -20,6 +20,9 @@
 hald_addon_acpi_SOURCES = addon-acpi.c
 hald_addon_acpi_LDADD = $(top_builddir)/libhal/libhal.la
 
+hald_addon_pmu_SOURCES = addon-pmu.c
+hald_addon_pmu_LDADD = $(top_builddir)/libhal/libhal.la
+
 hald_addon_storage_SOURCES = addon-storage.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
 

--- NEW FILE: addon-pmu.c ---
/***************************************************************************
 * CVSID: $Id: addon-pmu.c,v 1.1 2005/05/09 03:43:26 david Exp $
 *
 * addon-pmu-lid.c : Poll the lid button for PMU on Apple computers
 *
 * Copyright (C) 2005 David Zeuthen, <david at fubar.dk>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 **************************************************************************/

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <linux/adb.h>
#include <linux/pmu.h>

#include "libhal/libhal.h"

#include "../probing/shared.h"

int
main (int argc, char *argv[])
{
	int fd;
	char *udi;
	LibHalContext *ctx = NULL;
	DBusError error;
	DBusConnection *conn;
	int rd;
	char buf[256];
	int state;
	int new_state;
	char *strstate;

	fd = -1;

	if ((getenv ("HALD_VERBOSE")) != NULL)
		is_verbose = TRUE;

	udi = getenv ("UDI");
	if (udi == NULL)
		goto out;

	dbus_error_init (&error);
	if ((conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error)) == NULL)
		goto out;
	
	if ((ctx = libhal_ctx_new ()) == NULL)
		goto out;
	if (!libhal_ctx_set_dbus_connection (ctx, conn))
		goto out;
	if (!libhal_ctx_init (ctx, &error))
		goto out;

	/* initial state */
	if ((strstate = getenv ("HAL_PROP_BUTTON_STATE_VALUE")) == NULL) {
		dbg ("Cannot get HAL_PROP_BUTTON_STATE_VALUE");
		goto out;
	}
	if (strcmp (strstate, "true") == 0)
		state = TRUE;
	else
		state = FALSE;

	if ((fd = open ("/dev/adb", O_RDWR | O_NONBLOCK)) < 0) {
                dbg ("Cannot open /dev/adb");
                goto out;
	}

	while (1) {
		int n;

		buf[0] = PMU_PACKET;
		buf[1] = PMU_GET_COVER;

		n = write (fd, buf, 2);
		if (n == 2) {
			int i;

			rd = read (fd, buf, sizeof (buf));
			if (rd <= 0) {
				dbg ("Error reading from fd; read returned %d; err=%s", strerror (errno));
				goto out;
			}

#if 0
			dbg ("Read 0x%02x bytes", rd);				
			for (i = 0; i < rd; i++) {
				dbg ("%02x : 0x%02x", i, buf[i]);
			}
#endif

			if (rd >= 2) {
				new_state = (((buf[1]) & 0x01) != 0);

				if (new_state != state) {
					dbg ("lid state change: %d", new_state);
					dbus_error_init (&error);
					libhal_device_set_property_bool (
						ctx, udi, "button.state.value", new_state, &error);
					dbus_error_init (&error);
					libhal_device_emit_condition (ctx, udi, "ButtonPressed", "", &error);
				}

				state = new_state;
			}

			
		}

		sleep (1);
	}




out:
	if (fd >= 0)
		close (fd);

	return 0;
}




More information about the hal-commit mailing list