mirror of
https://github.com/X11Libre/xf86-input-joystick.git
synced 2026-03-24 01:34:06 +00:00
Add a generic jstkCloseDevice helper function
This is a preparation patch for adding support for server managed fds. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
committed by
Peter Hutterer
parent
6de3b75c45
commit
341d23ceaa
@@ -209,10 +209,7 @@ jstkOpenDevice_bsd(JoystickDevPtr joystick, Bool probe)
|
||||
static void
|
||||
jstkCloseDevice_bsd(JoystickDevPtr joystick)
|
||||
{
|
||||
if ((joystick->fd >= 0)) {
|
||||
xf86CloseSerial(joystick->fd);
|
||||
joystick->fd = -1;
|
||||
}
|
||||
jstkCloseDevice(joystick);
|
||||
if (joystick->devicedata != NULL) {
|
||||
if (((struct jstk_bsd_hid_data*)joystick->devicedata)->data_buf)
|
||||
free(((struct jstk_bsd_hid_data*)joystick->devicedata)->data_buf);
|
||||
|
||||
@@ -210,10 +210,7 @@ jstkOpenDevice_evdev(JoystickDevPtr joystick, Bool probe)
|
||||
static void
|
||||
jstkCloseDevice_evdev(JoystickDevPtr joystick)
|
||||
{
|
||||
if ((joystick->fd >= 0)) {
|
||||
xf86CloseSerial(joystick->fd);
|
||||
joystick->fd = -1;
|
||||
}
|
||||
jstkCloseDevice(joystick);
|
||||
if (joystick->devicedata) {
|
||||
free(joystick->devicedata);
|
||||
joystick->devicedata = NULL;
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include "backend_joystick.h"
|
||||
|
||||
|
||||
static void jstkCloseDevice_joystick(JoystickDevPtr joystick);
|
||||
static int jstkReadData_joystick(JoystickDevPtr joystick,
|
||||
JOYSTICKEVENT *event,
|
||||
int *number);
|
||||
@@ -82,7 +81,7 @@ jstkOpenDevice_joystick(JoystickDevPtr joystick, Bool probe)
|
||||
if (ioctl(joystick->fd, JSIOCGVERSION, &driver_version) == -1) {
|
||||
xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGVERSION on '%s' failed: %s\n",
|
||||
joystick->device, strerror(errno));
|
||||
jstkCloseDevice_joystick(joystick);
|
||||
jstkCloseDevice(joystick);
|
||||
return -1;
|
||||
}
|
||||
if ((driver_version >> 16) < 1) {
|
||||
@@ -95,21 +94,21 @@ jstkOpenDevice_joystick(JoystickDevPtr joystick, Bool probe)
|
||||
if (ioctl(joystick->fd, JSIOCGAXES, &axes) == -1) {
|
||||
xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGAXES on '%s' failed: %s\n",
|
||||
joystick->device, strerror(errno));
|
||||
jstkCloseDevice_joystick(joystick);
|
||||
jstkCloseDevice(joystick);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(joystick->fd, JSIOCGBUTTONS, &buttons) == -1) {
|
||||
xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGBUTTONS on '%s' failed: %s\n",
|
||||
joystick->device, strerror(errno));
|
||||
jstkCloseDevice_joystick(joystick);
|
||||
jstkCloseDevice(joystick);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(joystick->fd, JSIOCGNAME(128), joy_name) == -1) {
|
||||
xf86Msg(X_ERROR, "Joystick: ioctl JSIOCGNAME on '%s' failed: %s\n",
|
||||
joystick->device, strerror(errno));
|
||||
jstkCloseDevice_joystick(joystick);
|
||||
jstkCloseDevice(joystick);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -127,30 +126,11 @@ jstkOpenDevice_joystick(JoystickDevPtr joystick, Bool probe)
|
||||
|
||||
joystick->open_proc = jstkOpenDevice_joystick;
|
||||
joystick->read_proc = jstkReadData_joystick;
|
||||
joystick->close_proc = jstkCloseDevice_joystick;
|
||||
joystick->close_proc = jstkCloseDevice;
|
||||
return joystick->fd;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* jstkCloseDevice --
|
||||
*
|
||||
* close the handle.
|
||||
*
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
static void
|
||||
jstkCloseDevice_joystick(JoystickDevPtr joystick)
|
||||
{
|
||||
if ((joystick->fd >= 0)) {
|
||||
xf86CloseSerial(joystick->fd);
|
||||
joystick->fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
*
|
||||
* jstkReadData --
|
||||
|
||||
18
src/jstk.c
18
src/jstk.c
@@ -34,6 +34,7 @@
|
||||
#include <xf86Xinput.h>
|
||||
#include <exevents.h> /* Needed for InitValuator/Proximity stuff */
|
||||
#include <xf86Opt.h>
|
||||
#include <xf86_OSproc.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <xf86Module.h>
|
||||
@@ -98,6 +99,23 @@ jstkOpenDevice(JoystickDevPtr priv, BOOL probe)
|
||||
return fd;
|
||||
}
|
||||
|
||||
/*
|
||||
***************************************************************************
|
||||
*
|
||||
* jstkCloseDevice --
|
||||
*
|
||||
* Called to close the device specified in priv, this is a helper for
|
||||
* backend proc_close functions
|
||||
*
|
||||
***************************************************************************
|
||||
*/
|
||||
void jstkCloseDevice(JoystickDevPtr priv)
|
||||
{
|
||||
if ((priv->fd >= 0)) {
|
||||
xf86CloseSerial(priv->fd);
|
||||
priv->fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***************************************************************************
|
||||
|
||||
@@ -123,4 +123,6 @@ typedef struct _JoystickDevRec {
|
||||
BUTTON button[MAXBUTTONS]; /* Configuration per button */
|
||||
} JoystickDevRec;
|
||||
|
||||
void jstkCloseDevice(JoystickDevPtr priv);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user