diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-03 00:49:34 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-03 00:49:34 +0100 |
| commit | 70ba2dbf0f49a4f8d1caa2bbed97c8c2358c6fb6 (patch) | |
| tree | e1697049bc32fd47b1e639969b4ff752689c92a8 | |
Initial version: adding some files
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
| -rw-r--r-- | Makefile | 57 | ||||
| -rw-r--r-- | debian/README.Debian | 9 | ||||
| -rw-r--r-- | debian/changelog | 5 | ||||
| -rw-r--r-- | debian/compat | 1 | ||||
| -rw-r--r-- | debian/control | 14 | ||||
| -rw-r--r-- | debian/copyright | 27 | ||||
| -rw-r--r-- | debian/dirs | 3 | ||||
| -rwxr-xr-x | debian/rules | 46 | ||||
| -rw-r--r-- | fdi/11-multitouch.fdi | 40 | ||||
| -rw-r--r-- | src/dbus-abi.h | 34 | ||||
| -rw-r--r-- | src/glib-abi.h | 19 | ||||
| -rw-r--r-- | src/hal-abi.h | 28 | ||||
| -rw-r--r-- | src/multitouch.c | 241 | ||||
| -rw-r--r-- | src/test.c | 7 |
14 files changed, 531 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c387266 --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | LIBRARY = multitouch.so | ||
| 2 | FDIS = 11-multitouch.fdi | ||
| 3 | MODULES = src | ||
| 4 | |||
| 5 | o_src = multitouch | ||
| 6 | |||
| 7 | TARGETS = $(addsuffix /test,$(MODULES)) | ||
| 8 | |||
| 9 | OBJECTS = $(addsuffix .o,\ | ||
| 10 | $(foreach mod,$(MODULES),\ | ||
| 11 | $(addprefix $(mod)/,$(o_$(mod))))) | ||
| 12 | |||
| 13 | TBIN = $(addprefix bin/,$(TARGETS)) | ||
| 14 | TLIB = $(addprefix obj/,$(LIBRARY)) | ||
| 15 | TOBJ = $(addprefix obj/,$(addsuffix .o,$(TARGETS))) | ||
| 16 | TFDI = $(addprefix fdi/,$(FDIS)) | ||
| 17 | OBJS = $(addprefix obj/,$(OBJECTS)) | ||
| 18 | LIBS = #-lhal -ldbus-glib-1 | ||
| 19 | |||
| 20 | DLIB = usr/lib/xorg/modules/input | ||
| 21 | DFDI = usr/share/hal/fdi/policy/20thirdparty | ||
| 22 | |||
| 23 | INCLUDE = -I. | ||
| 24 | OPTS = -O3 | ||
| 25 | |||
| 26 | .PHONY: all clean | ||
| 27 | .PRECIOUS: obj/%.o | ||
| 28 | |||
| 29 | all: $(OBJS) $(TLIB) $(TOBJ) $(TBIN) | ||
| 30 | |||
| 31 | bin/%: obj/%.o | ||
| 32 | @mkdir -p $(@D) | ||
| 33 | gcc $(INCLUDE) $(OPTS) $< $(TLIB) $(LIBS) -o $@ | ||
| 34 | |||
| 35 | $(TLIB): $(OBJS) | ||
| 36 | @rm -f $(TLIB) | ||
| 37 | gcc -shared $(OBJS) -Wl,-soname -Wl,$(LIBRARY) -o $@ | ||
| 38 | |||
| 39 | obj/%.o: %.c | ||
| 40 | @mkdir -p $(@D) | ||
| 41 | gcc -c $< -o $@ | ||
| 42 | |||
| 43 | obj/%.o: %.cc | ||
| 44 | @mkdir -p $(@D) | ||
| 45 | gcc -c $< -o $@ | ||
| 46 | |||
| 47 | clean: | ||
| 48 | rm -rf bin obj | ||
| 49 | |||
| 50 | distclean: clean | ||
| 51 | rm -rf debian/*.log debian/files | ||
| 52 | |||
| 53 | install: $(TLIB) $(TFDI) | ||
| 54 | install -d "$(DESTDIR)/$(DLIB)" | ||
| 55 | install -d "$(DESTDIR)/$(DFDI)" | ||
| 56 | install -m 755 $(TBIN) "$(DESTDIR)/$(DLIB)" | ||
| 57 | install -m 644 $(TFDI) "$(DESTDIR)/$(DFDI)" | ||
diff --git a/debian/README.Debian b/debian/README.Debian new file mode 100644 index 0000000..e1e27bf --- /dev/null +++ b/debian/README.Debian | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | multitouch Xorg driver | ||
| 2 | |||
| 3 | * Install the debian package | ||
| 4 | |||
| 5 | * Restart X | ||
| 6 | |||
| 7 | Enjoy! | ||
| 8 | |||
| 9 | Henrik Rydberg <rydberg@euromail.se> | ||
diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..b6ef16b --- /dev/null +++ b/debian/changelog | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | multitouch (0.1) unstable; urgency=low | ||
| 2 | |||
| 3 | * Add multitouch Xorg input driver | ||
| 4 | |||
| 5 | -- Henrik Rydberg <rydberg@euromail.se> Mon, 03 Nov 2008 00:47:37 +0100 | ||
diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/debian/compat | |||
| @@ -0,0 +1 @@ | |||
| 5 | |||
diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..c74798c --- /dev/null +++ b/debian/control | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | Source: multitouch | ||
| 2 | Section: misc | ||
| 3 | Priority: optional | ||
| 4 | Maintainer: Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | Build-Depends: debhelper (>= 5) | ||
| 6 | Standards-Version: 3.7.2 | ||
| 7 | Homepage: http://web.comhem.se/rydberg/Bits/ | ||
| 8 | |||
| 9 | Package: multitouch | ||
| 10 | Architecture: any | ||
| 11 | Depends: bash (>> 1.99) | ||
| 12 | Description: Multitouch X input driver | ||
| 13 | This package is a multitouch Xorg input driver. | ||
| 14 | |||
diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..bf1dcd2 --- /dev/null +++ b/debian/copyright | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | Source URL: http://web.comhem.se/rydberg/Bits/ | ||
| 2 | |||
| 3 | Upstream Author: Henrik Rydberg <rydberg@euromail.se> | ||
| 4 | |||
| 5 | Copyright: | ||
| 6 | Copyright (C) 2008 Henrik Rydberg (rydberg@euromail.se) | ||
| 7 | |||
| 8 | License: | ||
| 9 | |||
| 10 | This program is free software; you can redistribute it and/or modify | ||
| 11 | it under the terms of the GNU General Public License as published by | ||
| 12 | the Free Software Foundation; either version 2 of the License, or | ||
| 13 | (at your option) any later version. | ||
| 14 | |||
| 15 | This program is distributed in the hope that it will be useful, | ||
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | GNU General Public License for more details. | ||
| 19 | |||
| 20 | You should have received a copy of the GNU General Public License | ||
| 21 | along with this program; if not, write to the Free Software | ||
| 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 23 | |||
| 24 | Packaging: | ||
| 25 | Copyright (C) 2008 by Henrik Rydberg <rydberg@euromail.se> | ||
| 26 | released under GPL 2 | ||
| 27 | |||
diff --git a/debian/dirs b/debian/dirs new file mode 100644 index 0000000..6611862 --- /dev/null +++ b/debian/dirs | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | usr/share/hal/fdi/information/10freedesktop | ||
| 2 | usr/lib/hal | ||
| 3 | |||
diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..90568c9 --- /dev/null +++ b/debian/rules | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #!/usr/bin/make -f | ||
| 2 | # -*- makefile -*- | ||
| 3 | |||
| 4 | # Uncomment this to turn on verbose mode. | ||
| 5 | #export DH_VERBOSE=1 | ||
| 6 | |||
| 7 | build-arch: | ||
| 8 | dh_testdir | ||
| 9 | $(MAKE) | ||
| 10 | |||
| 11 | build-indep: | ||
| 12 | |||
| 13 | build: build-arch build-indep | ||
| 14 | |||
| 15 | install: | ||
| 16 | dh_testdir | ||
| 17 | dh_testroot | ||
| 18 | dh_clean -k | ||
| 19 | dh_installdirs | ||
| 20 | $(MAKE) DESTDIR=$(CURDIR)/debian/hal-applesmc install | ||
| 21 | |||
| 22 | binary-arch: build-arch install | ||
| 23 | dh_testdir | ||
| 24 | dh_testroot | ||
| 25 | dh_link | ||
| 26 | dh_strip | ||
| 27 | dh_compress | ||
| 28 | dh_fixperms | ||
| 29 | dh_installdeb | ||
| 30 | dh_shlibdeps | ||
| 31 | dh_gencontrol | ||
| 32 | dh_md5sums | ||
| 33 | dh_builddeb | ||
| 34 | |||
| 35 | binary-indep: build-indep | ||
| 36 | |||
| 37 | binary: binary-arch binary-indep | ||
| 38 | |||
| 39 | clean: | ||
| 40 | dh_testdir | ||
| 41 | dh_testroot | ||
| 42 | $(MAKE) clean | ||
| 43 | dh_clean | ||
| 44 | |||
| 45 | .PHONY: build-arch build-indep build install binary-arch binary-indep binary clean | ||
| 46 | |||
diff --git a/fdi/11-multitouch.fdi b/fdi/11-multitouch.fdi new file mode 100644 index 0000000..1c82a22 --- /dev/null +++ b/fdi/11-multitouch.fdi | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | |||
| 3 | <deviceinfo version="0.2"> | ||
| 4 | |||
| 5 | <device> | ||
| 6 | <match key="platform.id" contains="applesmc"> | ||
| 7 | <spawn udi="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight"/> | ||
| 8 | <!-- | ||
| 9 | <spawn udi="/org/freedesktop/Hal/devices/applesmc_light_sensor"/> | ||
| 10 | --> | ||
| 11 | </match> | ||
| 12 | </device> | ||
| 13 | |||
| 14 | <device> | ||
| 15 | <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight"> | ||
| 16 | <append key="info.capabilities" type="strlist">keyboard_backlight</append> | ||
| 17 | <merge key="info.product" type="string">Applesmc Keyboard Backlight</merge> | ||
| 18 | <merge key="keyboard_backlight.num_levels" type="int">256</merge> | ||
| 19 | <merge key="keyboard_backlight.access_method" type="string">custom</merge> | ||
| 20 | <merge key="linux.sysfs_path" type="string">/sys/class/leds/smc::kbd_backlight</merge> | ||
| 21 | <append key="info.addons" type="strlist">hald-addon-generic-kbd-backlight</append> | ||
| 22 | </match> | ||
| 23 | </device> | ||
| 24 | |||
| 25 | <!-- | ||
| 26 | <device> | ||
| 27 | <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_light_sensor"> | ||
| 28 | <append key="info.capabilities" type="strlist">light_sensor</append> | ||
| 29 | <merge key="info.product" type="string">Applesmc Light Sensor</merge> | ||
| 30 | <merge key="light_sensor.num_sensors" type="int">1</merge> | ||
| 31 | <merge key="light_sensor.num_levels" type="int">64</merge> | ||
| 32 | <append key="light_sensor.sensor_locations" type="strlist">left</append> | ||
| 33 | <merge key="light_sensor.access_method" type="string">custom</merge> | ||
| 34 | <merge key="linux.sysfs_path" type="string">/sys/devices/platform/applesmc.768/light</merge> | ||
| 35 | <append key="info.addons" type="strlist">hald-addon-generic-light-sensor</append> | ||
| 36 | </match> | ||
| 37 | </device> | ||
| 38 | --> | ||
| 39 | |||
| 40 | </deviceinfo> | ||
diff --git a/src/dbus-abi.h b/src/dbus-abi.h new file mode 100644 index 0000000..ed406f1 --- /dev/null +++ b/src/dbus-abi.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* | ||
| 2 | * DBUS ABI | ||
| 3 | * | ||
| 4 | * The following is all dbus information needed in order to compile | ||
| 5 | * a hald-addon. | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* Structure declarations */ | ||
| 9 | struct DBusMessage; | ||
| 10 | |||
| 11 | /* Allocate 32 bytes for the error structure. */ | ||
| 12 | struct DBusError { | ||
| 13 | char bytes[32]; | ||
| 14 | }; | ||
| 15 | |||
| 16 | /* Define DBus arguments types */ | ||
| 17 | const int DBUS_TYPE_INVALID; | ||
| 18 | const int DBUS_TYPE_INT32 = 'i'; | ||
| 19 | const int DBUS_TYPE_ARRAY = 'a'; | ||
| 20 | |||
| 21 | /* Define DBus handler results */ | ||
| 22 | typedef enum { | ||
| 23 | DBUS_HANDLER_RESULT_HANDLED, | ||
| 24 | DBUS_HANDLER_RESULT_NOT_YET_HANDLED, | ||
| 25 | DBUS_HANDLER_RESULT_NEED_MEMORY | ||
| 26 | } DBusHandlerResult; | ||
| 27 | |||
| 28 | /* Function declarations */ | ||
| 29 | struct DBusMessage * | ||
| 30 | dbus_message_new_error(struct DBusMessage *reply_to, const char *error_name, | ||
| 31 | const char *error_message); | ||
| 32 | struct DBusMessage * | ||
| 33 | dbus_message_new_method_return(struct DBusMessage *method_call); | ||
| 34 | |||
diff --git a/src/glib-abi.h b/src/glib-abi.h new file mode 100644 index 0000000..62b85d5 --- /dev/null +++ b/src/glib-abi.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* | ||
| 2 | * GLIB ABI | ||
| 3 | * | ||
| 4 | * The following is all glib information needed in order to compile | ||
| 5 | * a hald-addon. | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* logical values */ | ||
| 9 | const int TRUE = 1; | ||
| 10 | const int FALSE; | ||
| 11 | |||
| 12 | /* Structure declarations */ | ||
| 13 | struct GMainContext; | ||
| 14 | struct GMainLoop; | ||
| 15 | |||
| 16 | /* Function declarations */ | ||
| 17 | struct GMainLoop *g_main_loop_new(struct GMainContext *context, int is_running); | ||
| 18 | void g_main_loop_run(struct GMainLoop *loop); | ||
| 19 | |||
diff --git a/src/hal-abi.h b/src/hal-abi.h new file mode 100644 index 0000000..277580f --- /dev/null +++ b/src/hal-abi.h | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /* | ||
| 2 | * HAL ABI | ||
| 3 | * | ||
| 4 | * The following is all hal information needed in order to compile | ||
| 5 | * a hald-addon. | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* Structure declarations */ | ||
| 9 | struct LibHalContext; | ||
| 10 | struct DBusConnection; | ||
| 11 | |||
| 12 | /* Simple error handling */ | ||
| 13 | #define setup_logger() | ||
| 14 | #define eprintf(...) (fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n")) | ||
| 15 | #define WARNING(...) eprintf("addon-warning: " __VA_ARGS__) | ||
| 16 | #define DEBUG(...) eprintf("addon-debug: " __VA_ARGS__) | ||
| 17 | #define ERROR(...) eprintf("addon-error: " __VA_ARGS__) | ||
| 18 | #define HAL_WARNING(x) WARNING x | ||
| 19 | #define HAL_DEBUG(x) DEBUG x | ||
| 20 | #define HAL_ERROR(x) ERROR x | ||
| 21 | |||
| 22 | /* Function declarations */ | ||
| 23 | struct LibHalContext * | ||
| 24 | libhal_ctx_init_direct(struct DBusError *error); | ||
| 25 | |||
| 26 | struct DBusConnection * | ||
| 27 | libhal_ctx_get_dbus_connection(struct LibHalContext *ctx); | ||
| 28 | |||
diff --git a/src/multitouch.c b/src/multitouch.c new file mode 100644 index 0000000..537ab69 --- /dev/null +++ b/src/multitouch.c | |||
| @@ -0,0 +1,241 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * addon-generic-kbd-backlight.c: | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * Based on addon-generic-backlight.c: | ||
| 7 | * Copyright (C) 2008 Danny Kukawka <danny.kukawka@web.de> | ||
| 8 | * | ||
| 9 | * Licensed under the Academic Free License version 2.1 | ||
| 10 | * | ||
| 11 | * This program is free software; you can redistribute it and/or modify | ||
| 12 | * it under the terms of the GNU General Public License as published by | ||
| 13 | * the Free Software Foundation; either version 2 of the License, or | ||
| 14 | * (at your option) any later version. | ||
| 15 | * | ||
| 16 | * This program is distributed in the hope that it will be useful, | ||
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | * GNU General Public License for more details. | ||
| 20 | * | ||
| 21 | * You should have received a copy of the GNU General Public License | ||
| 22 | * along with this program; if not, write to the Free Software | ||
| 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 24 | * | ||
| 25 | **************************************************************************/ | ||
| 26 | |||
| 27 | #include <string.h> | ||
| 28 | #include <sys/types.h> | ||
| 29 | #include <sys/stat.h> | ||
| 30 | #include <fcntl.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include <stdio.h> | ||
| 33 | #include <stdlib.h> | ||
| 34 | |||
| 35 | #include "glib-abi.h" | ||
| 36 | #include "dbus-abi.h" | ||
| 37 | #include "hal-abi.h" | ||
| 38 | |||
| 39 | #define HAL_PROPERTY "org.freedesktop.Hal.Device.KeyboardBacklight" | ||
| 40 | |||
| 41 | static const char prop_name[] = HAL_PROPERTY; | ||
| 42 | static const char prop_invalid[] = HAL_PROPERTY ".Invalid"; | ||
| 43 | static const char prop_set[] = "SetBrightness"; | ||
| 44 | static const char prop_get[] = "GetBrightness"; | ||
| 45 | |||
| 46 | static struct GMainLoop *main_loop; | ||
| 47 | static struct LibHalContext *halctx; | ||
| 48 | static struct DBusConnection *conn; | ||
| 49 | |||
| 50 | static char sysfs_path[512]; | ||
| 51 | static int levels; | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Get keyboard backlight level | ||
| 55 | * | ||
| 56 | * Tries to read from the specified sysfs device, and if successful, | ||
| 57 | * updates the internal keyboard backlight state. Warns if the device | ||
| 58 | * cannot be opened or be read from. Always returns the last succesful | ||
| 59 | * read. | ||
| 60 | */ | ||
| 61 | static int get_kbd_backlight() | ||
| 62 | { | ||
| 63 | static int level; | ||
| 64 | int fd; | ||
| 65 | char buf[64]; | ||
| 66 | |||
| 67 | fd = open(sysfs_path, O_RDONLY); | ||
| 68 | if (fd < 0) { | ||
| 69 | HAL_WARNING(("Could not open '%s'", sysfs_path)); | ||
| 70 | return level; | ||
| 71 | } | ||
| 72 | |||
| 73 | memset(buf, 0, sizeof(buf)); | ||
| 74 | if (read(fd, buf, sizeof(buf)) < 0) | ||
| 75 | HAL_WARNING(("Could not read from '%s'", sysfs_path)); | ||
| 76 | else | ||
| 77 | level = atoi(buf); | ||
| 78 | |||
| 79 | close(fd); | ||
| 80 | return level; | ||
| 81 | } | ||
| 82 | |||
| 83 | /** | ||
| 84 | * Set keyboard backlight level | ||
| 85 | * | ||
| 86 | * Warns if the device cannot be opened or be written to. | ||
| 87 | * Returns bytes written on success, negative value on failure. | ||
| 88 | */ | ||
| 89 | static int set_kbd_backlight(int level) | ||
| 90 | { | ||
| 91 | int fd, ret; | ||
| 92 | char buf[64]; | ||
| 93 | |||
| 94 | sprintf(buf, "%d", level); | ||
| 95 | |||
| 96 | fd = open(sysfs_path, O_WRONLY); | ||
| 97 | if (fd < 0) { | ||
| 98 | HAL_WARNING(("Could not open '%s'", sysfs_path)); | ||
| 99 | return -1; | ||
| 100 | } | ||
| 101 | |||
| 102 | ret = write(fd, buf, strlen(buf)); | ||
| 103 | if (ret < 0) | ||
| 104 | HAL_WARNING(("Could not write '%s' to '%s'", buf, sysfs_path)); | ||
| 105 | |||
| 106 | close(fd); | ||
| 107 | return ret; | ||
| 108 | } | ||
| 109 | |||
| 110 | /* DBus set keyboard backlight level */ | ||
| 111 | static struct DBusMessage *dbus_get_kbd_backlight(struct DBusMessage *msg) | ||
| 112 | { | ||
| 113 | struct DBusError err; | ||
| 114 | struct DBusMessage *reply; | ||
| 115 | int level; | ||
| 116 | |||
| 117 | dbus_error_init(&err); | ||
| 118 | if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INVALID)) | ||
| 119 | return dbus_message_new_error(msg, prop_invalid, | ||
| 120 | "Invalid message"); | ||
| 121 | |||
| 122 | level = get_kbd_backlight(); | ||
| 123 | |||
| 124 | reply = dbus_message_new_method_return(msg); | ||
| 125 | if (reply) | ||
| 126 | dbus_message_append_args(reply, DBUS_TYPE_INT32, &level, | ||
| 127 | DBUS_TYPE_INVALID); | ||
| 128 | |||
| 129 | return reply; | ||
| 130 | } | ||
| 131 | |||
| 132 | /* DBus set keyboard backlight level */ | ||
| 133 | static struct DBusMessage *dbus_set_kbd_backlight(struct DBusMessage *msg) | ||
| 134 | { | ||
| 135 | struct DBusError err; | ||
| 136 | int level; | ||
| 137 | |||
| 138 | dbus_error_init(&err); | ||
| 139 | if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level, | ||
| 140 | DBUS_TYPE_INVALID)) | ||
| 141 | return dbus_message_new_error(msg, prop_invalid, | ||
| 142 | "Brightness level argument missing"); | ||
| 143 | |||
| 144 | if (level < 0 || level > levels - 1) | ||
| 145 | return dbus_message_new_error(msg, prop_invalid, | ||
| 146 | "Brightness level is invalid"); | ||
| 147 | |||
| 148 | set_kbd_backlight(level); | ||
| 149 | |||
| 150 | return dbus_message_new_method_return(msg); | ||
| 151 | } | ||
| 152 | |||
| 153 | /* DBus filter function */ | ||
| 154 | static DBusHandlerResult filter_function(struct DBusConnection *connection, | ||
| 155 | struct DBusMessage *message, | ||
| 156 | void *userdata) | ||
| 157 | { | ||
| 158 | struct DBusMessage *reply = NULL; | ||
| 159 | |||
| 160 | if (dbus_message_is_method_call(message, prop_name, prop_get)) | ||
| 161 | reply = dbus_get_kbd_backlight(message); | ||
| 162 | else if (dbus_message_is_method_call(message, prop_name, prop_set)) | ||
| 163 | reply = dbus_set_kbd_backlight(message); | ||
| 164 | |||
| 165 | if (reply) { | ||
| 166 | dbus_connection_send(connection, reply, NULL); | ||
| 167 | dbus_message_unref(reply); | ||
| 168 | } | ||
| 169 | |||
| 170 | return DBUS_HANDLER_RESULT_HANDLED; | ||
| 171 | } | ||
| 172 | |||
| 173 | int main(int argc, char *argv[]) | ||
| 174 | { | ||
| 175 | struct DBusError err; | ||
| 176 | struct stat fs; | ||
| 177 | |||
| 178 | char *udi = getenv("UDI"); | ||
| 179 | char *path = getenv("HAL_PROP_LINUX_SYSFS_PATH"); | ||
| 180 | char *level_str = getenv("HAL_PROP_KEYBOARD_BACKLIGHT_NUM_LEVELS"); | ||
| 181 | |||
| 182 | setup_logger(); | ||
| 183 | |||
| 184 | if (udi == NULL) { | ||
| 185 | HAL_ERROR(("No device specified")); | ||
| 186 | return -2; | ||
| 187 | } | ||
| 188 | if (path == NULL) { | ||
| 189 | HAL_ERROR(("No sysfs path specified")); | ||
| 190 | return -2; | ||
| 191 | } | ||
| 192 | if (level_str == NULL) { | ||
| 193 | HAL_ERROR(("No keyboard_backlight.num_levels defined")); | ||
| 194 | return -2; | ||
| 195 | } | ||
| 196 | |||
| 197 | levels = atoi(level_str); | ||
| 198 | snprintf(sysfs_path, sizeof(sysfs_path), "%s/brightness", path); | ||
| 199 | |||
| 200 | HAL_DEBUG(("udi='%s', path='%s', levels='%d'", udi, path, levels)); | ||
| 201 | |||
| 202 | if (stat(sysfs_path, &fs)) { | ||
| 203 | HAL_ERROR(("The sysfs property path does not exist")); | ||
| 204 | return -2; | ||
| 205 | } | ||
| 206 | |||
| 207 | dbus_error_init(&err); | ||
| 208 | halctx = libhal_ctx_init_direct(&err); | ||
| 209 | |||
| 210 | if (halctx == NULL) { | ||
| 211 | HAL_ERROR(("Cannot connect to hald")); | ||
| 212 | return -3; | ||
| 213 | } | ||
| 214 | |||
| 215 | conn = libhal_ctx_get_dbus_connection(halctx); | ||
| 216 | dbus_connection_setup_with_g_main(conn, NULL); | ||
| 217 | |||
| 218 | dbus_connection_add_filter(conn, filter_function, NULL, NULL); | ||
| 219 | |||
| 220 | if (!libhal_device_claim_interface(halctx, udi, prop_name, | ||
| 221 | " <method name=\"GetBrightness\">\n" | ||
| 222 | " <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n" | ||
| 223 | " </method>\n" | ||
| 224 | " <method name=\"SetBrightness\">\n" | ||
| 225 | " <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n" | ||
| 226 | " </method>\n", | ||
| 227 | &err)) { | ||
| 228 | HAL_ERROR(("Cannot claim interface '" HAL_PROPERTY "'")); | ||
| 229 | return -4; | ||
| 230 | } | ||
| 231 | |||
| 232 | dbus_error_init(&err); | ||
| 233 | if (!libhal_device_addon_is_ready(halctx, udi, &err)) | ||
| 234 | return -4; | ||
| 235 | |||
| 236 | main_loop = g_main_loop_new(NULL, FALSE); | ||
| 237 | g_main_loop_run(main_loop); | ||
| 238 | |||
| 239 | return 0; | ||
| 240 | } | ||
| 241 | |||
diff --git a/src/test.c b/src/test.c new file mode 100644 index 0000000..20f35c6 --- /dev/null +++ b/src/test.c | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <time.h> | ||
| 3 | |||
| 4 | int main(int argc,char* argv[]) | ||
| 5 | { | ||
| 6 | return 0; | ||
| 7 | } | ||
