Rémi Bernon : dinput: Move SendForceFeedbackCommand generic code to device.c.

Alexandre Julliard julliard at winehq.org
Thu Oct 21 16:04:16 CDT 2021


Module: wine
Branch: master
Commit: 45d4c253de159618217a09374bdb016150edd6e8
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=45d4c253de159618217a09374bdb016150edd6e8

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Thu Oct 21 09:53:46 2021 +0200

dinput: Move SendForceFeedbackCommand generic code to device.c.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/device.c         | 30 ++++++++++++++++++++++++++----
 dlls/dinput/device_private.h |  1 +
 dlls/dinput/joystick_hid.c   | 35 ++++++++++++-----------------------
 dlls/dinput/keyboard.c       |  1 +
 dlls/dinput/mouse.c          |  1 +
 5 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index e0aa5141067..b8da627b1ea 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -1770,11 +1770,33 @@ HRESULT WINAPI IDirectInputDevice2WImpl_GetForceFeedbackState( IDirectInputDevic
     return DIERR_UNSUPPORTED;
 }
 
-HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand(LPDIRECTINPUTDEVICE8W iface, DWORD dwFlags)
+HRESULT WINAPI IDirectInputDevice2WImpl_SendForceFeedbackCommand( IDirectInputDevice8W *iface, DWORD command )
 {
-    IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
-    TRACE("(%p)->(0x%08x)\n", This, dwFlags);
-    return DI_NOEFFECT;
+    IDirectInputDeviceImpl *impl = impl_from_IDirectInputDevice8W( iface );
+    HRESULT hr;
+
+    TRACE( "iface %p, flags %x.\n", iface, command );
+
+    switch (command)
+    {
+    case DISFFC_RESET: break;
+    case DISFFC_STOPALL: break;
+    case DISFFC_PAUSE: break;
+    case DISFFC_CONTINUE: break;
+    case DISFFC_SETACTUATORSON: break;
+    case DISFFC_SETACTUATORSOFF: break;
+    default: return DIERR_INVALIDPARAM;
+    }
+
+    if (!(impl->caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
+    if (!impl->vtbl->send_force_feedback_command) return DIERR_UNSUPPORTED;
+
+    EnterCriticalSection( &impl->crit );
+    if (!impl->acquired || !(impl->dwCoopLevel & DISCL_EXCLUSIVE)) hr = DIERR_NOTEXCLUSIVEACQUIRED;
+    else hr = impl->vtbl->send_force_feedback_command( iface, command );
+    LeaveCriticalSection( &impl->crit );
+
+    return hr;
 }
 
 HRESULT WINAPI IDirectInputDevice2WImpl_EnumCreatedEffectObjects(LPDIRECTINPUTDEVICE8W iface,
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 66c51f1672a..b90c6bf2dcd 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -70,6 +70,7 @@ struct dinput_device_vtbl
                              const DIDEVICEOBJECTINSTANCEW *instance );
     HRESULT (*get_effect_info)( IDirectInputDevice8W *iface, DIEFFECTINFOW *info, const GUID *guid );
     HRESULT (*create_effect)( IDirectInputDevice8W *iface, IDirectInputEffect **out );
+    HRESULT (*send_force_feedback_command)( IDirectInputDevice8W *iface, DWORD command );
 };
 
 #define DEVICE_STATE_MAX_SIZE 1024
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index c7e9700ed7c..e9bbfa081e8 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -946,7 +946,7 @@ static BOOL CALLBACK unload_effect_object( IDirectInputEffect *effect, void *con
     return DIENUM_CONTINUE;
 }
 
-static HRESULT WINAPI hid_joystick_SendForceFeedbackCommand( IDirectInputDevice8W *iface, DWORD command )
+static HRESULT hid_joystick_internal_send_force_feedback_command( IDirectInputDevice8W *iface, DWORD command )
 {
     struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface );
     struct pid_control_report *report = &impl->pid_device_control;
@@ -955,7 +955,6 @@ static HRESULT WINAPI hid_joystick_SendForceFeedbackCommand( IDirectInputDevice8
     NTSTATUS status;
     USAGE usage;
     ULONG count;
-    HRESULT hr;
 
     TRACE( "iface %p, flags %x.\n", iface, command );
 
@@ -967,31 +966,20 @@ static HRESULT WINAPI hid_joystick_SendForceFeedbackCommand( IDirectInputDevice8
     case DISFFC_CONTINUE: usage = PID_USAGE_DC_DEVICE_CONTINUE; break;
     case DISFFC_SETACTUATORSON: usage = PID_USAGE_DC_ENABLE_ACTUATORS; break;
     case DISFFC_SETACTUATORSOFF: usage = PID_USAGE_DC_DISABLE_ACTUATORS; break;
-    default: return DIERR_INVALIDPARAM;
     }
 
-    if (!(impl->base.caps.dwFlags & DIDC_FORCEFEEDBACK)) return DIERR_UNSUPPORTED;
+    if (command == DISFFC_RESET) IDirectInputDevice8_EnumCreatedEffectObjects( iface, unload_effect_object, NULL, 0 );
 
-    EnterCriticalSection( &impl->base.crit );
-    if (!impl->base.acquired || !(impl->base.dwCoopLevel & DISCL_EXCLUSIVE))
-        hr = DIERR_NOTEXCLUSIVEACQUIRED;
-    else
-    {
-        if (command == DISFFC_RESET) IDirectInputDevice8_EnumCreatedEffectObjects( iface, unload_effect_object, NULL, 0 );
-
-        count = 1;
-        status = HidP_InitializeReportForID( HidP_Output, report->id, impl->preparsed, report_buf, report_len );
-        if (status != HIDP_STATUS_SUCCESS) hr = status;
-        else status = HidP_SetUsages( HidP_Output, HID_USAGE_PAGE_PID, report->control_coll, &usage,
-                                      &count, impl->preparsed, report_buf, report_len );
+    count = 1;
+    status = HidP_InitializeReportForID( HidP_Output, report->id, impl->preparsed, report_buf, report_len );
+    if (status != HIDP_STATUS_SUCCESS) return status;
 
-        if (status != HIDP_STATUS_SUCCESS) hr = status;
-        else if (WriteFile( impl->device, report_buf, report_len, NULL, NULL )) hr = DI_OK;
-        else hr = DIERR_GENERIC;
-    }
-    LeaveCriticalSection( &impl->base.crit );
+    status = HidP_SetUsages( HidP_Output, HID_USAGE_PAGE_PID, report->control_coll, &usage,
+                             &count, impl->preparsed, report_buf, report_len );
+    if (status != HIDP_STATUS_SUCCESS) return status;
 
-    return hr;
+    if (!WriteFile( impl->device, report_buf, report_len, NULL, NULL )) return DIERR_INPUTLOST;
+    return DI_OK;
 }
 
 static HRESULT WINAPI hid_joystick_EnumCreatedEffectObjects( IDirectInputDevice8W *iface,
@@ -1039,7 +1027,7 @@ static const IDirectInputDevice8WVtbl hid_joystick_vtbl =
     IDirectInputDevice2WImpl_EnumEffects,
     IDirectInputDevice2WImpl_GetEffectInfo,
     IDirectInputDevice2WImpl_GetForceFeedbackState,
-    hid_joystick_SendForceFeedbackCommand,
+    IDirectInputDevice2WImpl_SendForceFeedbackCommand,
     hid_joystick_EnumCreatedEffectObjects,
     IDirectInputDevice2WImpl_Escape,
     IDirectInputDevice2WImpl_Poll,
@@ -1280,6 +1268,7 @@ static const struct dinput_device_vtbl hid_joystick_internal_vtbl =
     hid_joystick_internal_set_property,
     hid_joystick_internal_get_effect_info,
     hid_joystick_internal_create_effect,
+    hid_joystick_internal_send_force_feedback_command,
 };
 
 static DWORD device_type_for_version( DWORD type, DWORD version )
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 8e1b752f016..a04b59e9c0c 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -340,6 +340,7 @@ static const struct dinput_device_vtbl keyboard_internal_vtbl =
     keyboard_internal_set_property,
     NULL,
     NULL,
+    NULL,
 };
 
 static const IDirectInputDevice8WVtbl SysKeyboardWvt =
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index ec3282b267f..faf093489cf 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -653,6 +653,7 @@ static const struct dinput_device_vtbl mouse_internal_vtbl =
     mouse_internal_set_property,
     NULL,
     NULL,
+    NULL,
 };
 
 static const IDirectInputDevice8WVtbl SysMouseWvt =




More information about the wine-cvs mailing list