hal: Branch 'origin' - 4 commits

David Zeuthen david at kemper.freedesktop.org
Mon Jan 8 12:12:16 PST 2007


 configure.in                                 |    7 
 fdi/policy/10osvendor/Makefile.am            |    4 
 hald/linux/addons/Makefile.am                |   10 
 hald/linux/addons/addon-nokia770-backlight.c |  271 +++++++++++++++++++++++++++
 hald/linux/blockdev.c                        |   19 -
 tools/hal-storage-shared.c                   |    4 
 6 files changed, 305 insertions(+), 10 deletions(-)

New commits:
diff-tree 9d5b803c98a59266dbb3f13cec3a9d00d2f55693 (from ab61f8f2208163ccadc7e2d86cf7c561f77f874f)
Author: David Zeuthen <davidz at redhat.com>
Date:   Mon Jan 8 14:10:42 2007 -0500

    call dbus_error_free() directly to avoid spew on stderr
    
    This patch is based on this discussion:
    
    Subject: [PATCH] Replace LIBHAL_FREE_DBUS_ERROR with dbus_error_free() in handle_unmount()
    
    From: Andrey Borzenkov <arvidjaar at mail.ru>
    
    When somebody calls Unmount on ignored media, hald crashes with:
    
    19:00:32.166 [I] hald_dbus.c:2972: Refreshing mount state for
    /org/freedesktop/Hal/devices/volume_uuid_f340078d_4758_4d33_a4ac_a148c95c7558
    since Unmount() completed
    19:00:32.166 [I] hald_dbus.c:3027: failed with 'hal-storage-shared.c 285 :
    INFO: called LIBHAL_FREE_DBUS_ERROR but dbusError was not set.'
    'org.freedesktop.Hal.Device.Volume.PermissionDenied'
    process 4822: arguments to dbus_message_new_error() were incorrect,
    assertion "_dbus_check_is_valid_error_name (error_name)" failed in file
    dbus-message.c line 1207.
    This is normally a bug in some application using the D-Bus library.
    
    The patch is using dbus_error_free() directly instead
    
    Signed-off-by: Andrey Borzenkov <arvidjaar at mail.ru>

diff --git a/tools/hal-storage-shared.c b/tools/hal-storage-shared.c
index 63f831b..bdbd14d 100644
--- a/tools/hal-storage-shared.c
+++ b/tools/hal-storage-shared.c
@@ -291,7 +291,9 @@ handle_unmount (LibHalContext *hal_ctx, 
 		dbus_error_init (&error);
 		if (libhal_device_get_property_bool (hal_ctx, udi, "volume.ignore", &error) || 
 		    dbus_error_is_set (&error)) {
-			LIBHAL_FREE_DBUS_ERROR (&error);
+			if (dbus_error_is_set (&error)) {
+				dbus_error_free (&error);
+			}
 			permission_denied_volume_ignore (device);
 		}
 
diff-tree ab61f8f2208163ccadc7e2d86cf7c561f77f874f (from 310e371ce3b2b5f01237b9f484ba50e8519c222d)
Author: David Zeuthen <davidz at redhat.com>
Date:   Mon Jan 8 13:15:25 2007 -0500

    fix up compile warnings after last patch

diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 717b21d..0925698 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -638,7 +638,6 @@ hotplug_event_begin_add_blockdev (const 
 
 	/* OK, no parent... it might a device-mapper device => check slaves/ subdir in sysfs */
 	if (parent == NULL && !is_partition && !is_fakevolume) {
-		GError *err = NULL;
 		DIR * dir;
 		struct dirent *dp;
 		
@@ -664,7 +663,6 @@ hotplug_event_begin_add_blockdev (const 
 		if ((dir = opendir (path)) == NULL) {
 			HAL_WARNING (("Unable to open %s: %s", path, strerror(errno)));
 		} else {
-			const char *f;
 			while (((dp = readdir (dir)) != NULL) && (parent == NULL)) {
 				char *link;
 				char *target;
diff-tree 310e371ce3b2b5f01237b9f484ba50e8519c222d (from 158636d2efebe95d9129a5e2fcb7cc09899badc9)
Author: Sergey Lapin <slapinid at gmail.com>
Date:   Mon Jan 8 13:14:28 2007 -0500

    use POSIX readdir instead of g_dir_open
    
    As I see through the code, near line 660 of hald/linux/blockdev.c, if I
    set break point on a line with g_dir_open, on n770 device and probably
    others, you'll se memory consumption increase by 100K. So I think
    replacing this call with POSIX readdir would be useful.
    
    Please see attached patch. It will benefit at least when you use kernel
    2.6.16 on arm (nokia 770 is an example; you don't have loopX/slaves in
    sysfs).

diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 7d11ad2..717b21d 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -32,6 +32,7 @@
 #include <mntent.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <dirent.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <syslog.h>
@@ -637,8 +638,10 @@ hotplug_event_begin_add_blockdev (const 
 
 	/* OK, no parent... it might a device-mapper device => check slaves/ subdir in sysfs */
 	if (parent == NULL && !is_partition && !is_fakevolume) {
-		GDir *dir;
 		GError *err = NULL;
+		DIR * dir;
+		struct dirent *dp;
+		
 		char path[HAL_PATH_MAX];
 
 
@@ -657,16 +660,16 @@ hotplug_event_begin_add_blockdev (const 
 
 		g_snprintf (path, HAL_PATH_MAX, "%s/slaves", sysfs_path);
 		HAL_INFO (("Looking in %s", path));
-		if ((dir = g_dir_open (path, 0, &err)) == NULL) {
-			HAL_WARNING (("Unable to open %s: %s", path, err->message));
-			g_error_free (err);
+
+		if ((dir = opendir (path)) == NULL) {
+			HAL_WARNING (("Unable to open %s: %s", path, strerror(errno)));
 		} else {
 			const char *f;
-			while (((f = g_dir_read_name (dir)) != NULL) && (parent == NULL)) {
+			while (((dp = readdir (dir)) != NULL) && (parent == NULL)) {
 				char *link;
 				char *target;
 
-				link = g_strdup_printf ("%s/%s", path, f);
+				link = g_strdup_printf ("%s/%s", path, dp->d_name);
 				target = resolve_symlink (link);
 				HAL_INFO ((" %s -> %s", link, target));
 
@@ -703,7 +706,7 @@ hotplug_event_begin_add_blockdev (const 
 				}
 				g_free (target);
 			}
-			g_dir_close (dir);
+			closedir(dir);
 			HAL_INFO (("Done looking in %s", path));
 		}
 		
diff-tree 158636d2efebe95d9129a5e2fcb7cc09899badc9 (from 91e7fd50a7f5b427f09e91e134f12d6edf552770)
Author: Sergey Lapin <slapinid at gmail.com>
Date:   Mon Jan 8 12:53:28 2007 -0500

    add Nokia 770 backlight addon
    
    It adds addon to support n770 backlight operation.
    It is cleaned-up version. Tried to implement all
    David suggestions.

diff --git a/configure.in b/configure.in
index 68f4f2b..5eaf375 100644
--- a/configure.in
+++ b/configure.in
@@ -535,6 +535,13 @@ elif test "x$with_macbookpro" = "x" ; th
 fi
 AM_CONDITIONAL(BUILD_MACBOOKPRO, test x$BUILD_MACBOOKPRO = xyes)
 
+AC_ARG_WITH(nokia770,     [  --with-nokia770       Whether to build Nokia 770 utils (no)])
+BUILD_N770=no
+if test "x$with_nokia770" = "xyes"; then
+    BUILD_N770=yes
+fi
+AM_CONDITIONAL(BUILD_N770, test x$BUILD_N770 = xyes)
+
 dnl cpufreq
 AC_ARG_WITH(cpufreq,        [  --with-cpufreq          Whether to build cpufreq utils (auto)])
 BUILD_CPUFREQ=no
diff --git a/fdi/policy/10osvendor/Makefile.am b/fdi/policy/10osvendor/Makefile.am
index 39c8507..af2332c 100644
--- a/fdi/policy/10osvendor/Makefile.am
+++ b/fdi/policy/10osvendor/Makefile.am
@@ -21,6 +21,10 @@ if BUILD_USBCSR
 dist_fdi_DATA += 10-usbcsr-mice.fdi
 endif
 
+if BUILD_N770
+dist_fdi_DATA += 10-nokia770-backlight.fdi
+endif
+
 check:
 	for f in $(dist_fdi_DATA); do \
             echo -n "Validate XML in $$f : "; \
diff --git a/hald/linux/addons/Makefile.am b/hald/linux/addons/Makefile.am
index aa23f6e..eb5496e 100644
--- a/hald/linux/addons/Makefile.am
+++ b/hald/linux/addons/Makefile.am
@@ -25,6 +25,11 @@ libexec_PROGRAMS  += 			\
 	hald-addon-acpi-buttons-toshiba
 endif
 
+if BUILD_N770
+libexec_PROGRAMS  +=			\
+	hald-addon-nokia770-backlight
+endif
+
 if BUILD_MACBOOKPRO
 libexec_PROGRAMS += hald-addon-macbookpro-backlight
 hald_addon_macbookpro_backlight_SOURCES = addon-macbookpro-backlight.c ../../logger.c
@@ -62,3 +67,8 @@ hald_addon_pmu_LDADD = $(top_builddir)/l
 
 hald_addon_storage_SOURCES = addon-storage.c ../../logger.c ../../util_helper.c
 hald_addon_storage_LDADD = $(top_builddir)/libhal/libhal.la
+
+if BUILD_N770
+hald_addon_nokia770_backlight_SOURCES = addon-nokia770-backlight.c ../../logger.c ../../util_helper.c
+hald_addon_nokia770_backlight_LDADD = $(top_builddir)/libhal/libhal.la @GLIB_LIBS@
+endif
diff --git a/hald/linux/addons/addon-nokia770-backlight.c b/hald/linux/addons/addon-nokia770-backlight.c
new file mode 100644
index 0000000..b9cefe1
--- /dev/null
+++ b/hald/linux/addons/addon-nokia770-backlight.c
@@ -0,0 +1,271 @@
+/***************************************************************************
+ * CVSID: $Id$
+ *
+ * addon-nokia770-backlight.c : daemon, handling Nokia 770
+ * non-standard backlight. Based on macbookpro addon by
+ * David Zeuthen and Nicolas Boichat
+ *
+ * Copyright (C) 2006 Sergey Lapin <slapinid at gmail.com>
+ *
+ * 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
+ *
+ **************************************************************************/
+
+#include <config.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/io.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h> 
+
+#include <glib/gmain.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+#include "../../util_helper.h"
+
+
+static GMainLoop *main_loop;
+static LibHalContext *halctx = NULL;
+static char * udi;
+static DBusConnection *conn;
+
+#define NUM_BUF_LEN 11
+
+static char buffer[NUM_BUF_LEN];
+
+struct backlight
+{
+    void (*set_backlight_level)(struct backlight * bl, int i);
+    int (*get_backlight_level)(struct backlight * bl);
+    void (*backlight_init)(struct backlight * bl);
+    int bl_min;
+    int bl_max;
+};
+
+struct backlight bl_data;
+
+/* Reads backligh level */
+static int read_backlight(struct backlight * bl)
+{
+ int fd;
+
+ fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_RDONLY);
+ if(fd <0 || read(fd, buffer, NUM_BUF_LEN) < 0)
+    return -1;
+
+ return atoi(buffer);
+}
+
+/* Read maximum bl level */
+/* TODO: set actual maximum level in property.
+   No we have fixed value in FDI file, but it
+   is better to set it in addon code.
+*/
+static void backlight_init(struct backlight * bl)
+{
+    int fd;
+
+    /* Reading maximum backlight level */
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_max", O_RDONLY);
+
+    if(fd <0 || read(fd, buffer, NUM_BUF_LEN - 1) < 0)
+	return;
+
+    bl->bl_max = atoi(buffer);
+    close(fd);
+}
+
+/* Setting backlight level */
+static void write_backlight(struct backlight * bl, int level)
+{
+    int fd, l;
+
+    /* sanity-checking level we're required to set */
+    if(level > bl->bl_max)
+	level = bl->bl_max;
+
+    if(level < bl->bl_min)
+	level = bl->bl_min;
+
+    fd = open("/sys/devices/platform/omapfb/panel/backlight_level", O_WRONLY);
+    l = snprintf(buffer, NUM_BUF_LEN - 1, "%d", level);
+
+    if(l >= (NUM_BUF_LEN - 1)) {
+	close(fd);
+	return;
+    }
+
+    write(fd, buffer, l);
+    close(fd);
+}
+
+/* DBus filter function */
+static DBusHandlerResult
+filter_function (DBusConnection *connection, DBusMessage *message, void *userdata)
+{
+	DBusError err;
+	DBusMessage *reply;
+
+#ifdef DEBUG_N770_BL
+	dbg ("filter_function: sender=%s destination=%s obj_path=%s interface=%s method=%s", 
+	     dbus_message_get_sender (message), 
+	     dbus_message_get_destination (message), 
+	     dbus_message_get_path (message), 
+	     dbus_message_get_interface (message),
+	     dbus_message_get_member (message));
+#endif
+	reply = NULL;
+
+	if (dbus_message_is_method_call (message, 
+					 "org.freedesktop.Hal.Device.LaptopPanel", 
+					 "SetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INT32, &brightness,
+					   DBUS_TYPE_INVALID)) {
+			if (brightness < 0 || brightness > 228) {
+				reply = dbus_message_new_error (message,
+								"org.freedesktop.Hal.Device.LaptopPanel.Invalid",
+								"Brightness has to be between 0 and 228!");
+
+			} else {
+				int return_code;
+
+				bl_data.set_backlight_level (&bl_data, brightness);
+
+				reply = dbus_message_new_method_return (message);
+				if (reply == NULL)
+					goto error;
+
+				return_code = 0;
+				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.LaptopPanel", 
+						"GetBrightness")) {
+		int brightness;
+
+		dbus_error_init (&err);
+		if (dbus_message_get_args (message, 
+					   &err,
+					   DBUS_TYPE_INVALID)) {
+
+			brightness = bl_data.get_backlight_level (&bl_data);
+			if (brightness < bl_data.bl_min)
+				brightness = bl_data.bl_min;
+			if (brightness > bl_data.bl_max)
+				brightness = bl_data.bl_max;
+
+			/* dbg ("getting brightness, it's %d", brightness); */
+
+			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;
+}
+
+/* Setting-up backlight structure */
+static void setup_cb(void)
+{
+ memset(&bl_data, 0, sizeof(struct backlight));
+ bl_data.backlight_init = backlight_init;
+ bl_data.get_backlight_level = read_backlight;
+ bl_data.set_backlight_level = write_backlight;
+}
+
+int
+main (int argc, char *argv[])
+{
+	DBusError err;
+
+	setup_logger ();
+	setup_cb();
+	udi = getenv ("UDI");
+
+	HAL_DEBUG (("udi=%s", udi));
+	if (udi == NULL) {
+		HAL_ERROR (("No device specified"));
+		return -2;
+	}
+
+	dbus_error_init (&err);
+	if ((halctx = libhal_ctx_init_direct (&err)) == NULL) {
+		HAL_ERROR (("Cannot connect to hald"));
+		return -3;
+	}
+
+
+
+	conn = libhal_ctx_get_dbus_connection (halctx);
+	dbus_connection_setup_with_g_main (conn, NULL);
+
+	dbus_connection_add_filter (conn, filter_function, NULL, NULL);
+
+	if (!libhal_device_claim_interface (halctx, 
+					    "/org/freedesktop/Hal/devices/omapfb_bl", 
+					    "org.freedesktop.Hal.Device.LaptopPanel", 
+					    "    <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.LaptopPanel'"));
+		return -4;
+	}
+	dbus_error_init (&err);
+	if (!libhal_device_addon_is_ready (halctx, udi, &err)) {
+		return -4;
+	}
+	bl_data.backlight_init(&bl_data);
+	main_loop = g_main_loop_new (NULL, FALSE);
+	g_main_loop_run (main_loop);
+	return 0;
+}


More information about the hal-commit mailing list