hal: Branch 'master' - 10 commits

Danny Kukawka dkukawka at kemper.freedesktop.org
Mon Jan 19 04:21:16 PST 2009


 doc/spec/hal-spec-interfaces.xml            |   48 +++
 doc/spec/hal-spec-properties.xml            |   53 ++++
 fdi/policy/10osvendor/10-leds.fdi           |   15 +
 fdi/policy/10osvendor/20-acl-management.fdi |    5 
 fdi/policy/10osvendor/Makefile.am           |    1 
 hald/linux/addons/.gitignore                |    1 
 hald/linux/addons/Makefile.am               |    3 
 hald/linux/addons/addon-leds.c              |  347 ++++++++++++++++++++++++++++
 hald/linux/device.c                         |  146 +++++++++--
 policy/Makefile.am                          |    1 
 policy/org.freedesktop.hal.leds.policy      |   28 ++
 11 files changed, 618 insertions(+), 30 deletions(-)

New commits:
commit 674bb9b20b95b30aaf3d8b6824b0ee2e552c9f5f
Merge: 93c3cff... 93ebe7d...
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Jan 19 13:19:14 2009 +0100

    Merge branch 'master' of ssh://dkukawka@people.freedesktop.org/~dkukawka/hal

commit 93ebe7d53439e002ed08b1045601c001cde00d5d
Merge: 511a684... 978715a...
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Wed Jan 14 16:05:26 2009 +0100

    Merge branch 'master' of ssh://dkukawka@git.freedesktop.org/git/hal

commit 511a68455ac86856bac2c21e8849c6db231e0ddc
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Jan 5 20:26:12 2009 +0100

    add ACL support for scsi_generic scanner devices
    
    Added ACL support for scsi_generic scanner devices.

diff --git a/fdi/policy/10osvendor/20-acl-management.fdi b/fdi/policy/10osvendor/20-acl-management.fdi
index 83f4f33..124d889 100644
--- a/fdi/policy/10osvendor/20-acl-management.fdi
+++ b/fdi/policy/10osvendor/20-acl-management.fdi
@@ -51,6 +51,11 @@
 	<merge key="access_control.file" type="copy_property">scsi_generic.device</merge>
 	<merge key="access_control.type" type="string">cdrom</merge>
       </match>
+      <match key="info.capabilities" contains="scanner">
+	<append key="info.capabilities" type="strlist">access_control</append>
+	<merge key="access_control.file" type="copy_property">scsi_generic.device</merge>
+	<merge key="access_control.type" type="string">scanner</merge>
+      </match>
       <!-- usb floppy bnc#336327 -->
       <match key="@info.parent:@info.parent:@info.parent:usb.interface.class" int="8">
 	<match key="@info.parent:@info.parent:@info.parent:usb.interface.subclass" int="4">
commit b09774739efe4215aa03e7812bca8a50be65e2c1
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Mon Dec 15 08:55:04 2008 +0100

    fixed serial.port handling for USB serial devices
    
    Fixed serial.port handling for USB serial devices. Since USB devices
    can have several ports and since the order of /dev/ttyUSB* depends on
    the device order, it make no sense to base serial.port for USB devices
    on the number in /dev/ttyUSB*. Here is the port number of the USB
    device itself more important to detect/match devices.
    
    Changed the spec description and handling/detection of serial.port for
    USB serial devices to use device/port_number info from sysfs. This change
    shouldn't affect existing matches in fdi files (as e.g. for modems) as
    long as there wheren't more than one USB serial device in the machine as
    the entry was generated. I imply this for now with this change.
    
    This change allow us to match e.g. modems also if you put more than one
    modem with USB serial ports to a machine. For more see:
    https://bugzilla.novell.com/show_bug.cgi?id=458307

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index d6136bd..b28a5bc 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -2883,8 +2883,9 @@ org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'}
               <entry>example: 0</entry>
               <entry>Yes</entry>
               <entry>
-                The port number of the device, based on the number in
-                <literal>serial.device</literal>
+                The port number of the device. For USB serial devices it's the port number of the
+		serial device itself. For other serial devices, where is no device port info 
+		available, it's based on the number in <literal>serial.device</literal>.
               </entry>
             </row>
             <row>
diff --git a/hald/linux/device.c b/hald/linux/device.c
index a2bc6a6..c1f8deb 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -3102,8 +3102,14 @@ serial_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent
 						hal_device_property_get_string (parent_dev, "info.product"));
 	} else if (sscanf (last_elem, "ttyUSB%d", &portnum) == 1) {
 		HalDevice *usbdev;
+		int port_number;
 
-		hal_device_property_set_int (d, "serial.port", portnum);
+		/* try to get the port number of the device and not of the whole USB subsystem */
+		if (hal_util_get_int_from_file (sysfs_path, "device/port_number", &port_number, 10)) {
+			hal_device_property_set_int (d, "serial.port", port_number);
+		} else {
+			hal_device_property_set_int (d, "serial.port", portnum);
+		}
 		hal_device_property_set_string (d, "serial.type", "usb");
 
 		usbdev = hal_device_store_find (hald_get_gdl (), 
commit a476876bd9f094f94583194d8d208bcb77cd5f49
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Thu Dec 11 20:11:56 2008 +0100

    fix ACL handling for drm devices
    
    Fixed ACL handling for drm devices. Use linux.device_file instead
    of input.device for access_control.file.

diff --git a/fdi/policy/10osvendor/20-acl-management.fdi b/fdi/policy/10osvendor/20-acl-management.fdi
index 22f325b..83f4f33 100644
--- a/fdi/policy/10osvendor/20-acl-management.fdi
+++ b/fdi/policy/10osvendor/20-acl-management.fdi
@@ -197,7 +197,7 @@
     <!-- graphics cards, e.g. for 3d accelleration -->
     <match key="info.capabilities" contains="drm">
 	<append key="info.capabilities" type="strlist">access_control</append>
-	<merge key="access_control.file" type="copy_property">input.device</merge>
+	<merge key="access_control.file" type="copy_property">linux.device_file</merge>
 	<merge key="access_control.type" type="string">video</merge>
     </match>
 
commit b0a2575f13ce9b18d07a2798e0d4c83cbb3059e5
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Fri Dec 5 15:19:57 2008 +0100

    fix joystick detection (patch by Ari Mustonen)
    
    Fix joystick/touchpad/tablet detection. Path contributed via
    https://launchpad.net/bugs/284129 by Ari Mustonen.

diff --git a/hald/linux/device.c b/hald/linux/device.c
index 9c9fce3..a2bc6a6 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1065,42 +1065,52 @@ static void
 input_test_abs (HalDevice *d, const char *sysfs_path)
 {
 	char *s;
-	long bitmask[NBITS(ABS_MAX)];
-	int num_bits;
+	long bitmask_abs[NBITS(ABS_MAX)];
+	long bitmask_key[NBITS(KEY_MAX)];
+	int num_bits_abs;
+	int num_bits_key;
 
 	s = hal_util_get_string_from_file (sysfs_path, "capabilities/abs");
 	if (s == NULL)
 		goto out;
-	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));
+	num_bits_abs = input_str_to_bitmask (s, bitmask_abs, sizeof (bitmask_abs));
 
-	if (test_bit (ABS_X, bitmask) && test_bit (ABS_Y, bitmask)) {
-		if (test_bit (ABS_PRESSURE, bitmask)) {
-			hal_device_add_capability (d, "input.touchpad");
-			goto out;
-		} else {
-			/*
-			 * This path is taken by VMware's USB mouse, which has
-			 * absolute axes, but no touch/pressure button.
-			 */
-			hal_device_add_capability (d, "input.mouse");
-			goto out;
-		}
-        }
+	if (test_bit (ABS_X, bitmask_abs) && test_bit (ABS_Y, bitmask_abs)) {
 
-        /* TODO: Hmm; this code looks sketchy... why do we do !test_bit on the Y axis ?? */
-	if (test_bit(ABS_X, bitmask) && !test_bit(ABS_Y, bitmask)) {
-		long bitmask_touch[NBITS(KEY_MAX)];
+		s = hal_util_get_string_from_file (sysfs_path, "capabilities/key");
+		if (s != NULL)
+		{
+			num_bits_key = input_str_to_bitmask (s, bitmask_key, sizeof (bitmask_key));
 
-		hal_device_add_capability (d, "input.joystick");
+			if (test_bit (BTN_STYLUS, bitmask_key)) {
+				hal_device_add_capability (d, "input.tablet");
+				goto out;
+			}
 
-		s = hal_util_get_string_from_file (sysfs_path, "capabilities/key");
-		if (s == NULL)
-			goto out;
-		input_str_to_bitmask (s, bitmask_touch, sizeof (bitmask_touch));
+			if (test_bit (BTN_TOUCH, bitmask_key)) {
+				hal_device_add_capability (d, "input.touchpad");
+				goto out;
+			}
 
-		if (test_bit(BTN_TOUCH, bitmask_touch)) {
-			hal_device_add_capability (d, "input.tablet");
-                }
+			if (test_bit (BTN_TRIGGER, bitmask_key) || test_bit (BTN_A, bitmask_key) || test_bit (BTN_1, bitmask_key)) {
+				hal_device_add_capability (d, "input.joystick");
+				goto out;
+			}
+
+			if (test_bit (BTN_MOUSE, bitmask_key)) {
+				/*
+				 * This path is taken by VMware's USB mouse, which has
+				 * absolute axes, but no touch/pressure button.
+				 */
+				hal_device_add_capability (d, "input.mouse");
+				goto out;
+			}
+		}
+
+		if (test_bit (ABS_PRESSURE, bitmask_abs)) {
+			hal_device_add_capability (d, "input.touchpad");
+			goto out;
+		}
 	}
 out:
 	;
commit 9b564550ad6fbae7d74ec388c8541d9abdaee100
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Fri Nov 28 19:45:00 2008 +0100

    add org.freedesktop.Hal.Device.Leds interface to spec
    
    Added org.freedesktop.Hal.Device.Leds interface to the spec.

diff --git a/doc/spec/hal-spec-interfaces.xml b/doc/spec/hal-spec-interfaces.xml
index 07a335c..edd360d 100644
--- a/doc/spec/hal-spec-interfaces.xml
+++ b/doc/spec/hal-spec-interfaces.xml
@@ -763,6 +763,54 @@ $ dbus-send --system --print-reply --dest=org.freedesktop.Hal \
     </para>
   </sect1>
 
+  <sect1 id="interface-device-leds">
+    <title>org.freedesktop.Hal.Device.Leds interface</title>
+    <para>
+      This interface provides a mechanism to get/set the brightness of
+      a LED (light-emitting diode). The following methods are available:
+    </para>
+
+    <informaltable>
+      <tgroup cols="2">
+        <thead>
+          <row>
+            <entry>Method</entry>
+            <entry>Returns</entry>
+            <entry>Parameters</entry>
+            <entry>Throws</entry>
+            <entry>Description</entry>
+          </row>
+        </thead>
+        <tbody>
+          <row>
+            <entry>GetBrightness</entry>
+            <entry>Int</entry>
+            <entry></entry>
+            <entry></entry>
+            <entry>
+              Get the current brightness of the LED.
+            </entry>
+          </row>
+          <row>
+            <entry>SetBrightness</entry>
+            <entry></entry>
+            <entry>Int brightness</entry>
+            <entry></entry>
+            <entry>
+              Set the current brightness of the LED. The value 0 deactivate
+	      normally the LED, any higher value active the LED again.
+            </entry>
+          </row>
+
+        </tbody>
+      </tgroup>
+    </informaltable>
+
+    <para>
+      This interface does not emit any signals.
+    </para>
+  </sect1>
+
   <sect1 id="interface-device-laptop-panel">
     <title>org.freedesktop.Hal.Device.LaptopPanel interface</title>
     <para>
commit 4948bdd2254931513cf5974e9c9f6c52705fab75
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Fri Nov 28 19:33:04 2008 +0100

    update .gitignore for hald/linux/addons
    
    Updated .gitignore for hald/linux/addons, added hald-addon-leds.

diff --git a/hald/linux/addons/.gitignore b/hald/linux/addons/.gitignore
index a075638..7fac742 100644
--- a/hald/linux/addons/.gitignore
+++ b/hald/linux/addons/.gitignore
@@ -19,5 +19,6 @@ hald-addon-cpufreq
 hald-addon-dell-backlight
 hald-addon-imac-backlight
 hald-addon-rfkill-killswitch
+hald-addon-leds
 *.o
 *~
commit 33d15dd2d91f06c6eb629eae5694b4945ef1ba7d
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Fri Nov 28 19:30:19 2008 +0100

    add a new singleton addon to handle leds
    
    Added a new singleton addon to handle led devices. The new interface
    is called org.freedesktop.Hal.Device.Leds and provide these methodes:
     - int SetBrightness (int brightness_value)
     - int GetBrightness ()

diff --git a/fdi/policy/10osvendor/10-leds.fdi b/fdi/policy/10osvendor/10-leds.fdi
new file mode 100644
index 0000000..1d14545
--- /dev/null
+++ b/fdi/policy/10osvendor/10-leds.fdi
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deviceinfo version="0.2">
+
+  <device>
+    <match key="info.capabilities" contains="leds">
+      <match key="leds.device_name" exists="true">
+        <match key="leds.function" exists="true">
+          <append key="info.addons.singleton" type="strlist">hald-addon-leds</append>
+        </match>
+      </match>
+    </match>
+  </device>
+
+</deviceinfo>
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index a30aac0..67c021c 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -5,6 +5,7 @@ dist_fdi_DATA = 			\
 	10-input-policy.fdi		\
 	10-dockstation.fdi		\
 	10-laptop-panel-mgmt-policy.fdi	\
+	10-leds.fdi			\
 	10-power-mgmt-policy.fdi	\
 	10-rfkill-switch.fdi		\
 	10-tabletPCs.fdi		\
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index ccfb6e6..b4a7ef9 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -14,6 +14,7 @@ libexec_PROGRAMS  = 			\
 	hald-addon-hid-ups 		\
 	hald-addon-input 		\
 	hald-addon-ipw-killswitch	\
+	hald-addon-leds			\
 	hald-addon-rfkill-killswitch	\
 	hald-addon-storage
 
@@ -105,3 +106,5 @@ hald_addon_ipw_killswitch_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 hald_addon_rfkill_killswitch_SOURCES = addon-rfkill-killswitch.c ../../logger.c ../../util_helper.c ../../util_helper_priv.c 
 hald_addon_rfkill_killswitch_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
 
+hald_addon_leds_SOURCES = addon-leds.c ../../logger.c ../../util_helper.c ../../util_helper_priv.c 
+hald_addon_leds_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
diff --git a/hald/linux/addons/addon-leds.c b/hald/linux/addons/addon-leds.c
new file mode 100644
index 0000000..86997b1
--- /dev/null
+++ b/hald/linux/addons/addon-leds.c
@@ -0,0 +1,347 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * addon-leds.c: 
+ * Copyright (C) 2008 Danny Kukawka <danny.kukawka at web.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h> 
+
+#include <glib.h>
+#include <glib/gmain.h>
+#include <glib/gstdio.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
+#include "../../util_helper_priv.h"
+
+static GMainLoop *gmain = NULL;
+static LibHalContext *ctx = NULL;
+static GHashTable *leds = NULL;
+
+/* Getting current brightness */
+static int
+get_leds_brightness (const char *udi)
+{
+	FILE *f;
+	char buf[64];
+	char path[256];
+	char *sysfs_path;
+	int brightness;
+	
+	f = NULL;
+
+	if (!g_hash_table_lookup_extended (leds, udi, NULL, (gpointer) &sysfs_path)) {
+		return -1;
+	}
+
+	snprintf (path, sizeof (path), "%s/brightness", sysfs_path);
+
+        if ((f = fopen (path, "rb")) == NULL) {
+		HAL_WARNING(("Could not read brightness from '%s' for device '%s'", path, udi));
+		return -1;
+	}
+
+	if (fgets (buf, sizeof (buf), f) == NULL) {
+		HAL_ERROR (("Cannot read from '%s' for device '%s'", path, udi));
+                goto out;
+        }
+
+	errno = 0;
+	brightness = strtol (buf, NULL, 10);
+	if (errno != 0) { 
+		brightness = -1;
+	} 
+
+out:
+        if (f != NULL)
+                fclose (f);
+
+        return brightness;
+}
+
+/* Setting current brightness of the led */
+static int
+set_leds_brightness (const char *udi, int level)
+{
+	int fd, l, ret;
+	char path[256];
+	char buf[5];	/* Assume we don't need more */
+	char *sysfs_path;
+
+	ret = -1;	
+
+	if (!g_hash_table_lookup_extended (leds, udi, NULL, (gpointer) &sysfs_path)) {
+		return -1;
+	}
+
+	snprintf (path, sizeof (path), "%s/brightness", sysfs_path);
+
+	fd = open (path, O_WRONLY);
+	if (fd < 0) {
+		HAL_WARNING(("Could not open '%s' for '%s', error='%s'", sysfs_path, udi, strerror(errno)));
+		goto out;
+	}
+
+	if ((l = snprintf (buf, 4, "%d", level)) < 4) {
+		if (write (fd, buf, l) < 0) {
+			HAL_WARNING(("Could not write '%s' to '%s'", buf , sysfs_path));
+		} else {
+			/* everything okay */
+			ret = level;
+		}
+	}
+
+out:
+	if (fd >= 0)
+		close (fd);
+
+	return ret;
+}
+
+/* DBus filter function */
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
+{
+	DBusError err;
+	DBusMessage *reply;
+	const char *_udi;
+	char *sysfs_path;
+
+	if ((_udi = dbus_message_get_path (message)) == NULL) {
+		HAL_DEBUG (("Couldn't get the udi for this call, ignore it."));
+		return DBUS_HANDLER_RESULT_HANDLED;
+	} else {
+		if(!g_hash_table_lookup_extended (leds, _udi, NULL, (gpointer *) &sysfs_path)) {
+			HAL_DEBUG (("This device (%s) isn't yet handled by the addon.", _udi));
+			return DBUS_HANDLER_RESULT_HANDLED;
+		}
+	}
+
+	dbus_error_init (&err);
+
+	if (!check_priv (ctx, connection, message, dbus_message_get_path (message), "org.freedesktop.hal.leds.brightness")) {
+		HAL_DEBUG(("User don't have the permissions to call the interface"));
+		return DBUS_HANDLER_RESULT_HANDLED;
+	}
+
+	reply = NULL;
+
+	if (dbus_message_is_method_call (message,
+					 "org.freedesktop.Hal.Device.Leds",
+					 "SetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message,
+					   &err,
+					   DBUS_TYPE_INT32, &brightness,
+					   DBUS_TYPE_INVALID)) {
+			int return_code = 0;
+			int set;
+
+			set = set_leds_brightness (_udi, brightness);
+
+			reply = dbus_message_new_method_return (message);
+			if (reply == NULL)
+				goto error;
+
+			if (set == brightness)
+				return_code = 0;
+			else
+				return_code = 1;
+
+			dbus_message_append_args (reply,
+						  DBUS_TYPE_INT32, &return_code,
+						  DBUS_TYPE_INVALID);
+
+			dbus_connection_send (connection, reply, NULL);
+		}
+	} else if (dbus_message_is_method_call (message,
+					 	"org.freedesktop.Hal.Device.Leds",
+						"GetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message,
+					   &err,
+					   DBUS_TYPE_INVALID)) {
+			brightness = get_leds_brightness(_udi);
+
+			reply = dbus_message_new_method_return (message);
+			if (reply == NULL)
+				goto error;
+
+			dbus_message_append_args (reply,
+						  DBUS_TYPE_INT32, &brightness,
+						  DBUS_TYPE_INVALID);
+			dbus_connection_send (connection, reply, NULL);
+		}
+	}
+
+error:
+	if (reply != NULL)
+		dbus_message_unref (reply);
+
+	return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static void
+add_device (LibHalContext *ctx,
+	    const char *udi,
+	    const LibHalPropertySet *properties)
+{
+	DBusError err;
+	DBusConnection *dbus_connection;
+	const char* sysfs_path;
+	static gboolean initialized = FALSE;
+
+	if ((sysfs_path = libhal_ps_get_string (properties, "linux.sysfs_path")) == NULL) {
+		HAL_ERROR(("%s has no property linux.sysfs_path", udi));
+		return;
+	}
+
+	/* claim the interface */
+	
+        if ((dbus_connection = libhal_ctx_get_dbus_connection(ctx)) == NULL) {
+                HAL_WARNING (("Cannot get DBus connection"));
+                return;
+        }
+
+	if (!initialized) {
+		dbus_connection_add_filter (dbus_connection, filter_function, NULL, NULL);
+		initialized = TRUE;
+	}
+
+	dbus_error_init (&err);
+
+	if (!libhal_device_claim_interface (ctx,
+					    udi,
+					    "org.freedesktop.Hal.Device.Leds",
+					    "    <method name=\"SetBrightness\">\n"
+					    "      <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
+					    "      <arg name=\"return_code\" direction=\"out\" type=\"i\"/>\n"
+					    "    </method>\n"
+					    "    <method name=\"GetBrightness\">\n"
+					    "      <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
+					    "    </method>\n",
+					    &err)) {
+		HAL_ERROR (("Cannot claim interface 'org.freedesktop.Hal.Device.Leds'"));
+		return;
+	}
+	
+	g_hash_table_insert (leds, g_strdup(udi), g_strdup(sysfs_path));
+}
+
+static void
+remove_device (LibHalContext *ctx,
+	       const char *udi,
+	       const LibHalPropertySet *properties)
+{
+	gpointer sysfs_path;
+	gboolean handling_udi;
+
+	HAL_DEBUG (("Removing channel for '%s'", udi));
+
+	handling_udi = g_hash_table_lookup_extended (leds, udi, NULL, &sysfs_path);
+
+	if (!handling_udi) {
+		HAL_ERROR(("DeviceRemove called for unknown device: '%s'.", udi));
+		return;
+	}
+
+	g_hash_table_remove (leds, udi);
+
+	if (g_hash_table_size (leds) == 0) {
+		HAL_INFO(("no more devices, exiting"));
+		g_main_loop_quit (gmain);
+	}
+}
+
+int
+main (int argc, char *argv[])
+{
+	DBusConnection *dbus_connection;
+	DBusError error;
+	const char *commandline;
+
+	hal_set_proc_title_init (argc, argv);
+
+	setup_logger ();
+
+	dbus_error_init (&error);
+	if ((ctx = libhal_ctx_init_direct (&error)) == NULL) {
+		HAL_WARNING (("Unable to init libhal context"));
+		goto out;
+	}
+
+	if ((dbus_connection = libhal_ctx_get_dbus_connection(ctx)) == NULL) {
+		HAL_WARNING (("Cannot get DBus connection"));
+		goto out;
+	}
+
+	if ((commandline = getenv ("SINGLETON_COMMAND_LINE")) == NULL) {
+		HAL_WARNING (("SINGLETON_COMMAND_LINE not set"));
+		goto out;
+	}
+
+	libhal_ctx_set_singleton_device_added (ctx, add_device);
+	libhal_ctx_set_singleton_device_removed (ctx, remove_device);
+
+	dbus_connection_setup_with_g_main (dbus_connection, NULL);
+	dbus_connection_set_exit_on_disconnect (dbus_connection, 0);
+
+	dbus_error_init (&error);
+
+	if (!libhal_device_singleton_addon_is_ready (ctx, commandline, &error)) {
+		goto out;
+	}
+
+	leds = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+	gmain = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (gmain);
+
+	return 0;
+
+out:
+	HAL_DEBUG (("An error occured, exiting cleanly"));
+	if (ctx != NULL) {
+		dbus_error_init (&error);
+		libhal_ctx_shutdown (ctx, &error);
+		libhal_ctx_free (ctx);
+	}
+
+	return 0;
+}
diff --git a/policy/Makefile.am b/policy/Makefile.am
index 28f31d4..b506a08 100644
--- a/policy/Makefile.am
+++ b/policy/Makefile.am
@@ -8,6 +8,7 @@ dist_polkit_policy_DATA =    				\
 	org.freedesktop.hal.power-management.policy	\
 	org.freedesktop.hal.killswitch.policy		\
 	org.freedesktop.hal.dockstation.policy		\
+	org.freedesktop.hal.leds.policy			\
 	org.freedesktop.hal.wol.policy
 
 if HAVE_ACLMGMT
diff --git a/policy/org.freedesktop.hal.leds.policy b/policy/org.freedesktop.hal.leds.policy
new file mode 100644
index 0000000..c7d852e
--- /dev/null
+++ b/policy/org.freedesktop.hal.leds.policy
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE policyconfig PUBLIC
+ "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
+ "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">
+
+<!--
+Policy definitions for HAL's ACL Management mechanism
+
+Copyright (c) 2008 Danny Kukawka <danny.kukawka at web.de>
+
+HAL is licensed to you under your choice of the the Academic Free
+License Version 2.1, or the GNU General Public License version 2. Some
+individual source files may be under the GPL only. See COPYING for
+details.
+-->
+
+<policyconfig>
+
+  <action id="org.freedesktop.hal.leds.brightness">
+    <description>Set the brightness of a led device</description>
+    <message>System policy prevents adjusting the led brightness</message>
+    <defaults>
+      <allow_inactive>no</allow_inactive>
+      <allow_active>yes</allow_active>
+    </defaults>
+  </action>
+
+</policyconfig>
commit eef409dfc82433edb32c73ce352671ab7fb1f79d
Author: Danny Kukawka <danny.kukawka at web.de>
Date:   Fri Nov 28 19:24:13 2008 +0100

    add the leds linux kernel subsystem to HAL
    
    Added the leds linux kernel subsystem to HAL. These are the current
    properties of led devices:
     - leds.device_name (string, mandatory)
     - leds.function (string, mandatory)
     - leds.colour

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index 2b40f62..d6136bd 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -2012,6 +2012,54 @@ org.freedesktop.Hal.Device.Volume.method_signatures = {'ssas', 'as', 'as'}
       </informaltable>
     </sect2>
 
+    <sect2 id="device-properties-leds">
+      <title>
+        leds namespace
+      </title>
+      <para>
+        Device objects with <literal>info.subsystem</literal> set to <literal>leds
+        </literal> are LED (light-emitting diode) devices.
+      </para>
+      <informaltable>
+        <tgroup cols="2">
+          <thead>
+            <row>
+              <entry>Key (type)</entry>
+              <entry>Values</entry>
+              <entry>Mandatory</entry>
+              <entry>Description</entry>
+            </row>
+          </thead>
+          <tbody>
+            <row>
+              <entry>
+                <literal>leds.device_name</literal> (string)
+              </entry>
+              <entry>example: iwl-phy0, tpacpi</entry>
+              <entry>Yes</entry>
+              <entry>The name of the related led device</entry>
+            </row>
+            <row>
+              <entry>
+                <literal>leds.colour</literal> (string)
+              </entry>
+              <entry>example: green, orange</entry>
+              <entry>No</entry>
+              <entry>The colour of the LED</entry>
+            </row>
+            <row>
+              <entry>
+                <literal>leds.function</literal> (string)
+              </entry>
+              <entry>example: radio, power, standby, batt</entry>
+              <entry>Yes</entry>
+              <entry>The function of the LED.</entry>
+            </row>
+          </tbody>
+        </tgroup>
+      </informaltable>
+    </sect2>
+
     <sect2 id="device-properties-modemif">
       <title>
         modem namespace
diff --git a/hald/linux/device.c b/hald/linux/device.c
index d16ac3a..9c9fce3 100644
--- a/hald/linux/device.c
+++ b/hald/linux/device.c
@@ -1259,6 +1259,72 @@ iucv_compute_udi (HalDevice *d)
 	return TRUE;
 
 }
+/*--------------------------------------------------------------------------------------------------------------*/
+
+static HalDevice *
+leds_add (const gchar *sysfs_path, const gchar *device_file, HalDevice *parent_dev, const gchar *parent_path)
+{
+	HalDevice *d;
+	const gchar *dev_name;
+        gchar **attributes;
+
+	d = hal_device_new ();
+
+	if (parent_dev != NULL)
+                hal_device_property_set_string (d, "info.parent", hal_device_get_udi (parent_dev));
+        else
+                hal_device_property_set_string (d, "info.parent", "/org/freedesktop/Hal/devices/computer");
+
+	hal_device_property_set_string (d, "linux.sysfs_path", sysfs_path);
+	hal_util_set_driver (d, "info.linux.driver", sysfs_path);
+
+	hal_device_property_set_string (d, "info.category", "leds");
+	hal_device_add_capability (d, "leds");
+
+	dev_name = hal_util_get_last_element (sysfs_path);
+	if (dev_name) {
+	        attributes = g_strsplit_set (dev_name, ":", 0);
+	
+		if (attributes != NULL) {
+			if (attributes[0] != NULL && attributes[0][0] != '\0')
+				hal_device_property_set_string (d, "leds.device_name", attributes[0]);
+			if (attributes[1] != NULL && attributes[1][0] != '\0')
+				hal_device_property_set_string (d, "leds.colour", attributes[1]);
+			if (attributes[2] != NULL && attributes[2][0] != '\0')
+				hal_device_property_set_string (d, "leds.function", attributes[2]);
+		}
+		g_strfreev (attributes);
+	}
+	
+	return d;
+}
+
+static gboolean
+leds_compute_udi (HalDevice *d)
+{
+	gchar udi[256];
+	const char *name;
+	const char *colour;
+	const char *function;
+
+        name = hal_device_property_get_string (d, "leds.device_name");
+        colour = hal_device_property_get_string (d, "leds.colour");
+        function = hal_device_property_get_string (d, "leds.function");
+
+	if (name && function && colour) {
+		hald_compute_udi (udi, sizeof (udi), "/org/freedesktop/Hal/devices/leds_%s_%s_%s", name, function, colour);
+	} else if (name && function) {
+		hald_compute_udi (udi, sizeof (udi), "/org/freedesktop/Hal/devices/leds_%s_%s", name, function);
+	} else if (name) {
+		hald_compute_udi (udi, sizeof (udi), "/org/freedesktop/Hal/devices/leds_%s", name);
+	} else {
+		hald_compute_udi (udi, sizeof (udi), "/org/freedesktop/Hal/devices/leds_unknown");
+	}
+	
+	hal_device_set_udi (d, udi);
+	return TRUE;
+}
+
 
 /*--------------------------------------------------------------------------------------------------------------*/
 
@@ -4238,6 +4304,13 @@ static DevHandler dev_handler_iucv = {
 	.remove      = dev_remove
 };
 
+static DevHandler dev_handler_leds = {
+	.subsystem   = "leds",
+	.add         = leds_add,
+	.compute_udi = leds_compute_udi,
+	.remove      = dev_remove
+};
+
 static DevHandler dev_handler_memstick = { 
 	.subsystem   = "memstick",
 	.add         = memstick_add,
@@ -4526,6 +4599,7 @@ static DevHandler *dev_handlers[] = {
 	&dev_handler_ieee1394,
 	&dev_handler_input,
 	&dev_handler_iucv,
+	&dev_handler_leds,
 	&dev_handler_mmc,
 	&dev_handler_memstick,
 	&dev_handler_memstick_host,


More information about the hal-commit mailing list