hal/tools .cvsignore, 1.3, 1.4 Makefile.am, 1.29, 1.30 hal-system-lcd-get-brightness, 1.3, 1.4 hal-system-lcd-set-brightness, 1.3, 1.4 hal-system-power-pmu.c, NONE, 1.1

Richard Hughes hughsient at freedesktop.org
Sun Jan 29 07:51:41 PST 2006


Update of /cvs/hal/hal/tools
In directory gabe:/tmp/cvs-serv1115/tools

Modified Files:
	.cvsignore Makefile.am hal-system-lcd-get-brightness 
	hal-system-lcd-set-brightness 
Added Files:
	hal-system-power-pmu.c 
Log Message:
2006-01-29  Richard Hughes <richard at hughsie.com>
 * hald/linux2/pmu.c: Add the methods laptop_panel_refresh() and pmu_laptop_panel_compute_udi so we can generate a laptop_panel object.
 * hald/linux2/pmu.c (pmu_synthesize_hotplug_events): Tidy up the hotplug code into a new function pmu_synthesize_item() that synthesizes a specific PMU object. Also add the laptop_panel if we have batteries (i.e. a laptop).
 * tools/hal-system-power-pmu.c: This is a new source file to allow us to issue ioctl's from methods invoked by HAL. Its arguments are: setlcd, getlcd, backlightoff, sleep and help.
 * tools/Makefile.am, tools/.cvsignore: Add the source file hal-system-power-pmu to be built.
 * tools/hal-system-lcd-get-brightness, tools/hal-system-lcd-set-brightness: Use the new functionality providied by hal-system-power-pmu for ppc and ppc64 computers. Also remove the check for HAL_PROP_LINUX_ACPI_PATH as pmu does not require or provide this.

Index: .cvsignore
===================================================================
RCS file: /cvs/hal/hal/tools/.cvsignore,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- .cvsignore	14 Aug 2005 21:20:16 -0000	1.3
+++ .cvsignore	29 Jan 2006 15:51:39 -0000	1.4
@@ -12,3 +12,4 @@
 hal-device
 hal-luks-remove
 hal-luks-setup
+hal-system-power-pmu

Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/tools/Makefile.am,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- Makefile.am	21 Jan 2006 17:59:47 -0000	1.29
+++ Makefile.am	29 Jan 2006 15:51:39 -0000	1.30
@@ -9,11 +9,21 @@
 	-I$(top_srcdir) -I$(top_srcdir)/libhal \
 	@PACKAGE_CFLAGS@
 
-bin_PROGRAMS = lshal hal-get-property hal-set-property hal-find-by-capability hal-find-by-property hal-device
+bin_PROGRAMS = \
+	lshal \
+	hal-system-power-pmu \
+	hal-get-property \
+	hal-set-property \
+	hal-find-by-capability \
+	hal-find-by-property \
+	hal-device
 
 lshal_SOURCES = lshal.c
 lshal_LDADD = @PACKAGE_LIBS@ $(top_builddir)/libhal/libhal.la
 
+hal_system_power_pmu_SOURCES = hal-system-power-pmu.c
+hal_system_power_pmu_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
+
 hal_get_property_SOURCES = hal_get_property.c
 hal_get_property_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la
 

Index: hal-system-lcd-get-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-get-brightness,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hal-system-lcd-get-brightness	29 Nov 2005 17:47:54 -0000	1.3
+++ hal-system-lcd-get-brightness	29 Jan 2006 15:51:39 -0000	1.4
@@ -8,12 +8,23 @@
 # (at your option) any later version.
 
 # Check for environment variables
-if [ "$HAL_PROP_LAPTOP_PANEL_ACPI_METHOD" == "" ] || [ "$HAL_PROP_LINUX_ACPI_PATH" == "" ]; then
+if [ "$HAL_PROP_LAPTOP_PANEL_ACPI_METHOD" == "" ]; then
 	echo "Missing or empty environment variable(s)." >&2
 	echo "This script should be started by hald." >&2
 	exit 1
 fi
 
+#FIXME: HAL_PROP_LAPTOP_PANEL_ACPI_METHOD should really be
+#       HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD as now not just ACPI
+if [ "$HAL_PROP_LAPTOP_PANEL_ACPI_METHOD" == "pmu" ]; then
+	value="`./hal-system-power-pmu getlcd`"
+	if [ $? -ne 0 ]; then
+		echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
+		exit 1
+	fi
+	exit ${value}
+fi
+
 # Check for file existance and that it's readable
 if [ ! -r $HAL_PROP_LINUX_ACPI_PATH ]; then
 	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2

Index: hal-system-lcd-set-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-set-brightness,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hal-system-lcd-set-brightness	29 Nov 2005 17:47:54 -0000	1.3
+++ hal-system-lcd-set-brightness	29 Jan 2006 15:51:39 -0000	1.4
@@ -9,7 +9,6 @@
 
 # Check for environment variables
 if [ "$HAL_PROP_LAPTOP_PANEL_ACPI_METHOD" == "" ] || 
-   [ "$HAL_PROP_LINUX_ACPI_PATH" == "" ] ||
    [ "$HAL_PROP_LAPTOP_PANEL_NUM_LEVELS" == "" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
@@ -19,6 +18,15 @@
 # read value for set brightness
 read value
 
+if [ "$HAL_PROP_LAPTOP_PANEL_ACPI_METHOD" == "pmu" ]; then
+	./hal-system-power-pmu setlcd $value
+	if [ $? -ne 0 ]; then
+		echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
+		exit 1
+	fi
+	exit 0
+fi
+
 # Check for file existance and that it's writable
 if [ ! -w $HAL_PROP_LINUX_ACPI_PATH ]; then
 	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2

--- NEW FILE: hal-system-power-pmu.c ---
/*! @file	hal-system-power-pmu.c
 *  @brief	Issue ioctl's from methods invoked by HAL.
 *  @author	Richard Hughes <richard at hughsie.com>
 *  @date	2005-12-11
 */
/*
 * Licensed under the GNU General Public License Version 2
 *
 * 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 Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <getopt.h>
#include <fcntl.h>

#include <sys/ioctl.h>
#include <linux/pmu.h>
#include <libhal/libhal.h>

#define PMUDEV		"/dev/pmu"
#define __u32		unsigned int

/**
 * @defgroup HalSystemPowerPmu  Use PMU specific ioctls
 * @ingroup HalMisc
 *
 * @brief A commandline tool for running PMU specific ioctl's. Uses libhal
 *
 * @{
 */

/** Issues a sleep ioctl
 *
 *  @return			Success, TRUE or FALSE
 */
static int
pmac_sleep (void)
{
	int ret;
	int fd;

	fd = open (PMUDEV, O_RDWR);
	if (fd < 0) {
		fprintf (stderr, "power-pmu : Failed to open " PMUDEV "\n");
		return FALSE;
	}
	/* returns when machine wakes up */
	ret = ioctl (fd, PMU_IOC_SLEEP, 0);
	close (fd);
	if (ret < 0) {
		fprintf (stderr, "power-pmu : PMU_IOC_SLEEP failed\n");
		return FALSE;
	}
	return TRUE;
}

/** Gets the LCD brightness
 *
 *  @param	val		The returned brightness value, 0..15
 *  @return			Success, TRUE or FALSE
 */
static int
pmac_get_lcd_brightness (int *val)
{
	int ret;
	int fd;

	fd = open (PMUDEV, O_RDWR);
	if (fd < 0) {
		fprintf (stderr, "power-pmu : Failed to open " PMUDEV "\n");
		return FALSE;
	}
	ret = ioctl (fd, PMU_IOC_GET_BACKLIGHT, val);
	close (fd);

	if (ret < 0) {
		fprintf (stderr, "power-pmu : PMU_IOC_GET_BACKLIGHT failed\n");
		return FALSE;
	}
	return TRUE;
}

/** Sets the LCD brightness
 *
 *  @param	val		The brightness value we want to set, 0..15
 *  @return			Success, TRUE or FALSE
 */
static int
pmac_set_lcd_brightness (int val)
{
	int ret;
	int fd;

	fd = open (PMUDEV, O_RDWR);
	if (fd < 0) {
		fprintf (stderr, "power-pmu : Failed to open " PMUDEV "\n");
		return FALSE;
	}
	ret = ioctl (fd, PMU_IOC_SET_BACKLIGHT, &val);
	close (fd);

	if (ret < 0) {
		fprintf (stderr, "power-pmu : PMU_IOC_SET_BACKLIGHT failed\n");
		return FALSE;
	}
	return TRUE;
}

/** Print out program usage.
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 */
static void
usage (int argc, char *argv[])
{
	fprintf (stderr, "\nusage : hal-system-power-pmu "
			 "[setlcd x] [getlcd] [suspend]\n");
	fprintf (stderr,
 "\n"
 "        setlcd x       Sets the LCD to a range 0..14 (0 is off)\n"
 "        getlcd         Gets the current LCD brightness value\n"
 "        backlightoff   Turns off the LCD backlight (setlcd turns it on again)\n"
 "        sleep          Initiate an immediate sleep\n"
 "        help           Show this information and exit\n"
 "\n"
 "This program calls PMU specific ioctls from within scripts run by HAL.\n");
}

/** Entry point
 *
 *  @param  argc                Number of arguments given to program
 *  @param  argv                Arguments given to program
 *  @return                     Return code
 */
int
main (int argc, char *argv[])
{
	int brightness;
	int ret;

	if (argc == 2) {
		if (strcmp (argv[1], "sleep") == 0) {
			ret = pmac_sleep ();
			if (ret == FALSE)
				return EXIT_FAILURE;
			return EXIT_SUCCESS;
		}
		if (strcmp (argv[1], "getlcd") == 0) {
			ret = pmac_get_lcd_brightness (&brightness);
			if (ret == FALSE)
				return EXIT_FAILURE;
			/* we subtract 1 as 0 is backlight disable */
			printf ("%i", brightness - 1);
			return EXIT_SUCCESS;
		}
		if (strcmp (argv[1], "backlightoff") == 0) {
			ret = pmac_set_lcd_brightness (0);
			if (ret == FALSE)
				return EXIT_FAILURE;
			return EXIT_SUCCESS;
		}
	} else if (argc == 3) {
		if (strcmp (argv[1], "setlcd") == 0) {
			/* we add 1 as 0 is backlight disable */
			brightness = atoi (argv[2]) + 1;
			ret = pmac_set_lcd_brightness (brightness);
			if (ret == FALSE)
				return EXIT_FAILURE;
			return EXIT_SUCCESS;
		}
	}
	usage (argc, argv);
	return EXIT_SUCCESS;
}

/**
 * @}
 */




More information about the hal-commit mailing list