hal/hald/linux2/probing Makefile.am, 1.1, 1.2 probe-hiddev.c, NONE,
1.1
David Zeuthen
david at freedesktop.org
Thu Feb 3 21:24:27 PST 2005
Update of /cvs/hal/hal/hald/linux2/probing
In directory gabe:/tmp/cvs-serv10538/hald/linux2/probing
Modified Files:
Makefile.am
Added Files:
probe-hiddev.c
Log Message:
2005-02-04 David Zeuthen <david at fubar.dk>
* doc/spec/hal-spec.xml.in: Added docs for battery.remaining_time
* hald/linux2/classdev.c (input_get_prober): New function
(usbclass_add): New function
(usbclass_get_prober): New function
(usbclass_compute_udi): New function
(add_classdev_probing_helper_done): Check if post_probing is NULL
(hotplug_event_begin_add_classdev): Use function to get prober since
e.g. class usb covers multiple devices, e.g. hiddev, printers etc.
* hald/linux2/probing/probe-hiddev.c: New file; probe for application
pages a HIDDEV supports and add to hiddev.application_pages strlist
* hald/linux2/addons/addon-hid-ups.c: Detect UPS's on USB HID
interfaces and create plus maintain battery.* properties.
* hald/linux2/addons/Makefile.am: New file
* hald/linux2/Makefile.am (SUBDIRS): Add addons directory
* configure.in: Add hald2/linux2/addons/Makefile.am to AC_OUTPUT
Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am 18 Jan 2005 19:48:13 -0000 1.1
+++ Makefile.am 4 Feb 2005 05:24:25 -0000 1.2
@@ -8,11 +8,14 @@
-I$(top_srcdir) \
@PACKAGE_CFLAGS@
-libexec_PROGRAMS = hald-probe-input
+libexec_PROGRAMS = hald-probe-input hald-probe-hiddev
hald_probe_input_SOURCES = probe-input.c
hald_probe_input_LDADD = $(top_builddir)/libhal/libhal.la
+hald_probe_hiddev_SOURCES = probe-hiddev.c
+hald_probe_hiddev_LDADD = $(top_builddir)/libhal/libhal.la
+
--- NEW FILE: probe-hiddev.c ---
/***************************************************************************
* CVSID: $Id: probe-hiddev.c,v 1.1 2005/02/04 05:24:25 david Exp $
*
* probe-input.c : Probe input devices
*
* Copyright (C) 2004 David Zeuthen, <david at fubar.dk>
*
* Licensed under the Academic Free License version 2.0
*
* 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 <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <asm/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/hiddev.h>
#include "libhal/libhal.h"
int
main (int argc, char *argv[])
{
int fd;
int ret;
char *udi;
char *device_file;
LibHalContext *ctx = NULL;
DBusError error;
DBusConnection *conn;
char name[256] = "Unknown HID device";
unsigned int i;
struct hiddev_devinfo device_info;
fd = -1;
/* assume failure */
ret = 1;
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;
device_file = getenv ("HAL_PROP_HIDDEV_DEVICE");
if (device_file == NULL)
goto out;
fd = open (device_file, O_RDONLY);
if (fd < 0)
goto out;
if (ioctl (fd, HIDIOCGNAME(sizeof (name)), name) >= 0) {
if (!libhal_device_set_property_string (ctx, udi, "hiddev.product", name, &error))
goto out;
if (!libhal_device_set_property_string (ctx, udi, "info.product", name, &error))
goto out;
}
if (ioctl (fd, HIDIOCGDEVINFO, &device_info) < 0)
goto out;
for (i = 0; i < device_info.num_applications; i++) {
int appl;
const char *appl_name;
char buf[256];
if ((appl = ioctl(fd, HIDIOCAPPLICATION, i)) < 0)
goto out;
/* The magic values come from various usage table specs */
switch (appl >> 16)
{
case 0x01 :
appl_name = "Generic Desktop Page";
break;
case 0x0c :
appl_name = "Consumer Product Page";
break;
case 0x80 :
appl_name = "USB Monitor Page";
break;
case 0x81 :
appl_name = "USB Enumerated Values Page";
break;
case 0x82 :
appl_name = "VESA Virtual Controls Page";
break;
case 0x83 :
appl_name = "Reserved Monitor Page";
break;
case 0x84 :
appl_name = "Power Device Page";
break;
case 0x85 :
appl_name = "Battery System Page";
break;
case 0x86 :
case 0x87 :
appl_name = "Reserved Power Device Page";
break;
default :
snprintf (buf, sizeof (buf), "Unknown page 0x%02x", appl);
appl_name = buf;
}
if (!libhal_device_property_strlist_append (ctx, udi, "hiddev.application_pages", appl_name, &error))
goto out;
}
#if 0
if (fork () == 0) {
sleep (10);
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;
main2 (ctx, "/org/freedesktop/Hal/devices/usb_device_51d_2_QB0435136106 _if0_hiddev", fd);
}
else
sleep (2);
#endif
/* success */
ret = 0;
out:
if (fd >= 0)
close (fd);
if (ctx != NULL) {
dbus_error_init (&error);
libhal_ctx_shutdown (ctx, &error);
libhal_ctx_free (ctx);
}
return ret;
}
More information about the hal-commit
mailing list