[PATCH xf86-input-joystick 2/3] Add a generic jstkCloseDevice helper function
Hans de Goede
hdegoede at redhat.com
Thu Mar 13 06:49:52 PDT 2014
This is a preparation patch for adding support for server managed fds.
Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
src/backend_bsd.c | 5 +----
src/backend_evdev.c | 5 +----
src/backend_joystick.c | 30 +++++-------------------------
src/jstk.c | 18 ++++++++++++++++++
src/jstk.h | 2 ++
5 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/src/backend_bsd.c b/src/backend_bsd.c
index 9fa3035..f3f501e 100644
--- a/src/backend_bsd.c
+++ b/src/backend_bsd.c
@@ -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);
diff --git a/src/backend_evdev.c b/src/backend_evdev.c
index 6d6f644..2a7b0e2 100644
--- a/src/backend_evdev.c
+++ b/src/backend_evdev.c
@@ -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;
diff --git a/src/backend_joystick.c b/src/backend_joystick.c
index c84654e..d335bc2 100644
--- a/src/backend_joystick.c
+++ b/src/backend_joystick.c
@@ -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,32 +126,13 @@ 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 --
*
* Reads data from fd and stores it in the JoystickDevRec struct
diff --git a/src/jstk.c b/src/jstk.c
index bee34fc..211fe32 100644
--- a/src/jstk.c
+++ b/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;
+ }
+}
/*
***************************************************************************
diff --git a/src/jstk.h b/src/jstk.h
index ed5e4a7..4955435 100644
--- a/src/jstk.h
+++ b/src/jstk.h
@@ -123,4 +123,6 @@ typedef struct _JoystickDevRec {
BUTTON button[MAXBUTTONS]; /* Configuration per button */
} JoystickDevRec;
+void jstkCloseDevice(JoystickDevPtr priv);
+
#endif
--
1.9.0
More information about the xorg-devel
mailing list