diff options
author | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-12-05 21:22:50 +0100 |
---|---|---|
committer | Sascha Hlusiak <saschahlusiak@arcor.de> | 2007-12-05 21:22:50 +0100 |
commit | 032138d7712f6d1e6a50bf83a2dde911b7f3d752 (patch) | |
tree | ce46a2cd6990ba8dae0b20570c0e593d3dd15601 | |
parent | 37aae4731320d4e1301f17a065bc5f1d5a3d1596 (diff) |
Added backend selection code.
From all available backends they are tried in the order: evdev, linux joystick, bsd
usbhid. This needed to separate the backends which were usually used to replace each
other.
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/bsd_jstk.c | 12 | ||||
-rw-r--r-- | src/bsd_jstk.h | 35 | ||||
-rw-r--r-- | src/evdev_jstk.c | 89 | ||||
-rw-r--r-- | src/evdev_jstk.h | 35 | ||||
-rw-r--r-- | src/jstk.c | 52 | ||||
-rw-r--r-- | src/jstk.h | 16 | ||||
-rw-r--r-- | src/linux_jstk.c | 22 | ||||
-rw-r--r-- | src/linux_jstk.h (renamed from src/jstk_hw.h) | 15 |
10 files changed, 253 insertions, 37 deletions
diff --git a/configure.ac b/configure.ac index 6b1b489..4660213 100644 --- a/configure.ac +++ b/configure.ac @@ -111,9 +111,9 @@ XORG_RELEASE_VERSION AC_OUTPUT([Makefile src/Makefile man/Makefile]) echo -echo Building linux joystick backend: $linux_backend -echo Building evdev backend: $evdev_backend -echo Building BSD backend: $bsd_backend +echo Building Linux joystick backend: $linux_backend +echo Building Linux evdev backend: $evdev_backend +echo Building BSD usbhid backend: $bsd_backend if test "x$linux_backend" != "xyes" -a \ "x$bsd_backend" != "xyes" -a \ diff --git a/src/Makefile.am b/src/Makefile.am index fd417b4..d65c859 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,15 +28,15 @@ @DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version @DRIVER_NAME@_drv_ladir = @inputdir@ -@DRIVER_NAME@_drv_la_SOURCES = jstk.c jstk.h jstk_hw.h \ +@DRIVER_NAME@_drv_la_SOURCES = jstk.c jstk.h \ jstk_axis.c jstk_axis.h \ jstk_key.c jstk_key.h \ jstk_options.c jstk_options.h \ StrKeysym.c StrKeysym.h ks_tables.h -BSD_SRCS = bsd_jstk.c -LINUX_SRCS = linux_jstk.c -EVDEV_SRCS = evdev_jstk.c +BSD_SRCS = bsd_jstk.c bsd_jstk.h +LINUX_SRCS = linux_jstk.c linux_jstk.h +EVDEV_SRCS = evdev_jstk.c evdev_jstk.h if BSD_BACKEND @DRIVER_NAME@_drv_la_SOURCES += $(BSD_SRCS) diff --git a/src/bsd_jstk.c b/src/bsd_jstk.c index 64af0cb..38c6d87 100644 --- a/src/bsd_jstk.c +++ b/src/bsd_jstk.c @@ -45,7 +45,6 @@ #include <dev/usb/usbhid.h> #include "jstk.h" -#include "jstk_hw.h" struct jstk_bsd_hid_data { @@ -63,8 +62,6 @@ struct jstk_bsd_hid_data { - - /*********************************************************************** * * jstkOpenDevice -- @@ -76,7 +73,7 @@ struct jstk_bsd_hid_data { */ int -jstkOpenDevice(JoystickDevPtr joystick) +jstkOpenDevice_bsd(JoystickDevPtr joystick) { int cur_axis; int is_joystick, report_id = 0; @@ -187,6 +184,9 @@ jstkOpenDevice(JoystickDevPtr joystick) xf86Msg(X_INFO, "Joystick: %d buttons, %d axes\n", bsddata->buttons, bsddata->axes); + joystick->read_proc = jstkReadData_bsd; + joystick->close_proc = jstkCloseDevice_bsd; + return joystick->fd; } @@ -201,7 +201,7 @@ jstkOpenDevice(JoystickDevPtr joystick) */ void -jstkCloseDevice(JoystickDevPtr joystick) +jstkCloseDevice_bsd(JoystickDevPtr joystick) { if ((joystick->fd >= 0)) { xf86CloseSerial(joystick->fd); @@ -228,7 +228,7 @@ jstkCloseDevice(JoystickDevPtr joystick) */ int -jstkReadData(JoystickDevPtr joystick, +jstkReadData_bsd(JoystickDevPtr joystick, JOYSTICKEVENT *event, int *number) { diff --git a/src/bsd_jstk.h b/src/bsd_jstk.h new file mode 100644 index 0000000..e185476 --- /dev/null +++ b/src/bsd_jstk.h @@ -0,0 +1,35 @@ +/* + * Copyright 2007 by Sascha Hlusiak. <saschahlusiak@freedesktop.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Sascha Hlusiak not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Sascha Hlusiak makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * SASCHA HLUSIAK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL SASCHA HLUSIAK BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef _BSD_JSTK_H_INCLUDED_ +#define _BSD_JSTK_H_INCLUDED_ + +#include "jstk.h" + +int jstkOpenDevice_bsd(JoystickDevPtr joystick); +void jstkCloseDevice_bsd(JoystickDevPtr joystick); +int jstkReadData_bsd(JoystickDevPtr joystick, + JOYSTICKEVENT *event, + int *number); + +#endif diff --git a/src/evdev_jstk.c b/src/evdev_jstk.c index 67e8c5d..4265c76 100644 --- a/src/evdev_jstk.c +++ b/src/evdev_jstk.c @@ -25,6 +25,93 @@ * This provides the backend for Linux evdev devices. * Devices are usually /dev/input/event? **/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif -/* NOTE: IMPLEMENTATION NEEDED */ +#include <unistd.h> +#include <sys/types.h> +#include <sys/ioctl.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <linux/joystick.h> +#include <xf86.h> +#include <xf86_OSproc.h> + +#include "jstk.h" +#include "evdev_jstk.h" + + +/*********************************************************************** + * + * jstkOpenDevice -- + * + * Open and initialize a joystick device. The device name is + * taken from JoystickDevPtr + * Returns the filedescriptor, or -1 in case of error + * + *********************************************************************** + */ + +int +jstkOpenDevice_evdev(JoystickDevPtr joystick) +{ + if (1) { + xf86Msg(X_ERROR, "Joystick: '%s': evdev failed: IMPLEMENTATION MISSING\n", + joystick->device); + return -1; + } + +/* xf86Msg(X_INFO, "Joystick: %s. %d axes, %d buttons\n", + joy_name, axes, buttons); */ + + joystick->read_proc = jstkReadData_evdev; + joystick->close_proc = jstkCloseDevice_evdev; + return joystick->fd; +} + + +/*********************************************************************** + * + * jstkCloseDevice -- + * + * close the handle. + * + *********************************************************************** + */ + +void +jstkCloseDevice_evdev(JoystickDevPtr joystick) +{ +/* if ((joystick->fd >= 0)) { + xf86CloseSerial(joystick->fd); + joystick->fd = -1; + }*/ +} + + +/*********************************************************************** + * + * jstkReadData -- + * + * Reads data from fd and stores it in the JoystickDevRec struct + * fills in the type of event and the number of the button/axis + * return 1 if success, 0 otherwise. Success does not neccessarily + * mean that there is a new event waiting. + * + *********************************************************************** + */ + +int +jstkReadData_evdev(JoystickDevPtr joystick, + JOYSTICKEVENT *event, + int *number) +{ + if (event != NULL) *event = EVENT_NONE; + return 0; + + return 1; +} diff --git a/src/evdev_jstk.h b/src/evdev_jstk.h new file mode 100644 index 0000000..1cd9120 --- /dev/null +++ b/src/evdev_jstk.h @@ -0,0 +1,35 @@ +/* + * Copyright 2007 by Sascha Hlusiak. <saschahlusiak@freedesktop.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Sascha Hlusiak not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Sascha Hlusiak makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * SASCHA HLUSIAK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL SASCHA HLUSIAK BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef _EVDEV_JSTK_H_INCLUDED_ +#define _EVDEV_JSTK_H_INCLUDED_ + +#include "jstk.h" + +int jstkOpenDevice_evdev(JoystickDevPtr joystick); +void jstkCloseDevice_evdev(JoystickDevPtr joystick); +int jstkReadData_evdev(JoystickDevPtr joystick, + JOYSTICKEVENT *event, + int *number); + +#endif @@ -39,11 +39,20 @@ #include "jstk.h" -#include "jstk_hw.h" #include "jstk_axis.h" #include "jstk_key.h" #include "jstk_options.h" +#ifdef LINUX_BACKEND + #include "linux_jstk.h" +#endif +#ifdef BSD_BACKEND + #include "bsd_jstk.h" +#endif +#ifdef EVDEV_BACKEND + #include "evdev_jstk.h" +#endif + #if DEBUG int debug_level = 0; @@ -86,6 +95,41 @@ jstkConvertProc(LocalDevicePtr local, /* *************************************************************************** * + * jstkOpenDevice -- + * + * Called to open the device specified in priv + * The compiled backends are tried one by one and return the first matching + * + * Returns the filedescriptor or -1 in case of error + * + *************************************************************************** + */ +static int +jstkOpenDevice(JoystickDevPtr priv) +{ + int fd; + fd = -1; + +#ifdef EVDEV_BACKEND + if (fd == -1) + fd = jstkOpenDevice_evdev(priv); +#endif +#ifdef LINUX_BACKEND + if (fd == -1) + fd = jstkOpenDevice_joystick(priv); +#endif +#ifdef BSD_BACKEND + if (fd == -1) + fd = jstkOpenDevice_bsd(priv); +#endif + + return fd; +} + + +/* + *************************************************************************** + * * jstkReadProc -- * * Called when data is available to read from the device @@ -104,7 +148,8 @@ jstkReadProc(LocalDevicePtr local) JoystickDevPtr priv = local->private; do { - if ((r=jstkReadData(priv, &event, &number))==0) { + if ((priv->read_proc == NULL) || + ((r=priv->read_proc(priv, &event, &number))==0)) { xf86Msg(X_WARNING, "JOYSTICK: Read failed. Deactivating device.\n"); if (local->fd >= 0) @@ -367,7 +412,8 @@ jstkDeviceControlProc(DeviceIntPtr pJstk, if (local->fd >= 0) RemoveEnabledDevice(local->fd); local->fd = -1; - jstkCloseDevice(priv); + if (priv->close_proc) + priv->close_proc(priv); pJstk->public.on = FALSE; break; @@ -45,6 +45,18 @@ #define DBG(lvl, f) #endif +typedef enum _JOYSTICKEVENT { + EVENT_NONE=0, + EVENT_BUTTON, + EVENT_AXIS +} JOYSTICKEVENT; + +typedef struct _JoystickDevRec *JoystickDevPtr; + +typedef void(*jstkCloseDeviceProc)(JoystickDevPtr joystick); +typedef int(*jstkReadDataProc)(JoystickDevPtr joystick, + JOYSTICKEVENT *event, int *number); + typedef enum _JOYSTICKTYPE{ TYPE_NONE=0, /* Axis value is not relevant */ @@ -95,6 +107,8 @@ typedef struct _BUTTON { typedef struct _JoystickDevRec { int fd; /* Actual file descriptor */ + jstkCloseDeviceProc close_proc; /* Callback for closing the backend */ + jstkReadDataProc read_proc; /* Callback for reading data from the backend */ void *devicedata; /* Extra platform device dependend data */ char *device; /* Name of the device */ @@ -118,6 +132,6 @@ typedef struct _JoystickDevRec { AXIS axis[MAXAXES]; /* Configuration per axis */ BUTTON button[MAXBUTTONS]; /* Configuration per button */ -} JoystickDevRec, *JoystickDevPtr; +} JoystickDevRec; #endif diff --git a/src/linux_jstk.c b/src/linux_jstk.c index 176dd13..2f5c3cc 100644 --- a/src/linux_jstk.c +++ b/src/linux_jstk.c @@ -45,7 +45,7 @@ #include <xf86_OSproc.h> #include "jstk.h" -#include "jstk_hw.h" +#include "linux_jstk.h" /*********************************************************************** @@ -60,7 +60,7 @@ */ int -jstkOpenDevice(JoystickDevPtr joystick) +jstkOpenDevice_joystick(JoystickDevPtr joystick) { char joy_name[128]; unsigned char axes, buttons; @@ -73,7 +73,7 @@ jstkOpenDevice(JoystickDevPtr joystick) } if (ioctl(joystick->fd, JSIOCGVERSION, &driver_version) == -1) { - xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", + xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGVERSION on '%s' failed: %s\n", joystick->device, strerror(errno)); close(joystick->fd); joystick->fd = -1; @@ -87,7 +87,7 @@ jstkOpenDevice(JoystickDevPtr joystick) } if (ioctl(joystick->fd, JSIOCGAXES, &axes) == -1) { - xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", + xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGAXES on '%s' failed: %s\n", joystick->device, strerror(errno)); close(joystick->fd); joystick->fd = -1; @@ -95,7 +95,7 @@ jstkOpenDevice(JoystickDevPtr joystick) } if (ioctl(joystick->fd, JSIOCGBUTTONS, &buttons) == -1) { - xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", + xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGBUTTONS on '%s' failed: %s\n", joystick->device, strerror(errno)); close(joystick->fd); joystick->fd = -1; @@ -103,7 +103,7 @@ jstkOpenDevice(JoystickDevPtr joystick) } if (ioctl(joystick->fd, JSIOCGNAME(128), joy_name) == -1) { - xf86Msg(X_ERROR, "Joystick: ioctl on '%s' failed: %s\n", + xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGNAME on '%s' failed: %s\n", joystick->device, strerror(errno)); close(joystick->fd); joystick->fd = -1; @@ -113,6 +113,8 @@ jstkOpenDevice(JoystickDevPtr joystick) xf86Msg(X_INFO, "Joystick: %s. %d axes, %d buttons\n", joy_name, axes, buttons); + joystick->read_proc = jstkReadData_joystick; + joystick->close_proc = jstkCloseDevice_joystick; return joystick->fd; } @@ -127,7 +129,7 @@ jstkOpenDevice(JoystickDevPtr joystick) */ void -jstkCloseDevice(JoystickDevPtr joystick) +jstkCloseDevice_joystick(JoystickDevPtr joystick) { if ((joystick->fd >= 0)) { xf86CloseSerial(joystick->fd); @@ -149,9 +151,9 @@ jstkCloseDevice(JoystickDevPtr joystick) */ int -jstkReadData(JoystickDevPtr joystick, - JOYSTICKEVENT *event, - int *number) +jstkReadData_joystick(JoystickDevPtr joystick, + JOYSTICKEVENT *event, + int *number) { struct js_event js; if (event != NULL) *event = EVENT_NONE; diff --git a/src/jstk_hw.h b/src/linux_jstk.h index 5e8988c..decc125 100644 --- a/src/jstk_hw.h +++ b/src/linux_jstk.h @@ -24,15 +24,12 @@ #ifndef _LINUX_JSTK_H_INCLUDED_ #define _LINUX_JSTK_H_INCLUDED_ -typedef enum _JOYSTICKEVENT { - EVENT_NONE=0, - EVENT_BUTTON, - EVENT_AXIS -} JOYSTICKEVENT; +#include "jstk.h" -int jstkOpenDevice(JoystickDevPtr joystick); -void jstkCloseDevice(JoystickDevPtr joystick); -int jstkReadData(JoystickDevPtr joystick, - JOYSTICKEVENT *event, int *number); +int jstkOpenDevice_joystick(JoystickDevPtr joystick); +void jstkCloseDevice_joystick(JoystickDevPtr joystick); +int jstkReadData_joystick(JoystickDevPtr joystick, + JOYSTICKEVENT *event, + int *number); #endif |