Aric Stewart : winejoystick.drv: Gracefully handle polling an unplugged device.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Mar 3 11:39:43 CST 2016
Module: wine
Branch: master
Commit: 2281a7bd7ce351551207d3efc51970066488b1a6
URL: http://source.winehq.org/git/wine.git/?a=commit;h=2281a7bd7ce351551207d3efc51970066488b1a6
Author: Aric Stewart <aric at codeweavers.com>
Date: Wed Mar 2 14:49:04 2016 -0600
winejoystick.drv: Gracefully handle polling an unplugged device.
Signed-off-by: Aric Stewart <aric at codeweavers.com>
Signed-off-by: Ken Thomases <ken at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/winejoystick.drv/joystick_osx.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/dlls/winejoystick.drv/joystick_osx.c b/dlls/winejoystick.drv/joystick_osx.c
index 72552d0..48c05a0 100644
--- a/dlls/winejoystick.drv/joystick_osx.c
+++ b/dlls/winejoystick.drv/joystick_osx.c
@@ -633,6 +633,25 @@ LRESULT driver_joyGetDevCaps(DWORD_PTR device_id, JOYCAPSW* caps, DWORD size)
return JOYERR_NOERROR;
}
+/*
+ * Helper to get the value from an element
+ */
+static LRESULT driver_getElementValue(IOHIDDeviceRef device, IOHIDElementRef element, IOHIDValueRef *pValueRef)
+{
+ IOReturn ret;
+ ret = IOHIDDeviceGetValue(device, element, pValueRef);
+ switch (ret)
+ {
+ case kIOReturnSuccess:
+ return JOYERR_NOERROR;
+ case kIOReturnNotAttached:
+ return JOYERR_UNPLUGGED;
+ default:
+ ERR("IOHIDDeviceGetValue returned 0x%x\n",ret);
+ return JOYERR_NOCANDO;
+ }
+}
+
/**************************************************************************
* driver_joyGetPosEx
*/
@@ -655,6 +674,7 @@ LRESULT driver_joyGetPosEx(DWORD_PTR device_id, JOYINFOEX* info)
CFIndex i, count;
IOHIDValueRef valueRef;
long value;
+ LRESULT rc;
if ((joystick = joystick_from_id(device_id)) == NULL)
return MMSYSERR_NODRIVER;
@@ -673,7 +693,9 @@ LRESULT driver_joyGetPosEx(DWORD_PTR device_id, JOYINFOEX* info)
for (i = 0; i < count; i++)
{
IOHIDElementRef button = (IOHIDElementRef)CFArrayGetValueAtIndex(joystick->buttons, i);
- IOHIDDeviceGetValue(device, button, &valueRef);
+ rc = driver_getElementValue(device, button, &valueRef);
+ if (rc != JOYERR_NOERROR)
+ return rc;
value = IOHIDValueGetIntegerValue(valueRef);
if (value)
{
@@ -690,7 +712,9 @@ LRESULT driver_joyGetPosEx(DWORD_PTR device_id, JOYINFOEX* info)
DWORD* field = (DWORD*)((char*)info + axis_map[i].offset);
if (joystick->axes[i].element)
{
- IOHIDDeviceGetValue(device, joystick->axes[i].element, &valueRef);
+ rc = driver_getElementValue(device, joystick->axes[i].element, &valueRef);
+ if (rc != JOYERR_NOERROR)
+ return rc;
value = IOHIDValueGetIntegerValue(valueRef) - joystick->axes[i].min_value;
*field = MulDiv(value, 0xFFFF, joystick->axes[i].max_value - joystick->axes[i].min_value);
}
@@ -706,7 +730,9 @@ LRESULT driver_joyGetPosEx(DWORD_PTR device_id, JOYINFOEX* info)
{
if (joystick->hatswitch)
{
- IOHIDDeviceGetValue(device, joystick->hatswitch, &valueRef);
+ rc = driver_getElementValue(device, joystick->hatswitch, &valueRef);
+ if (rc != JOYERR_NOERROR)
+ return rc;
value = IOHIDValueGetIntegerValue(valueRef);
if (value >= 8)
info->dwPOV = JOY_POVCENTERED;
More information about the wine-cvs
mailing list