From f09f487a294148e8d9c0476a7bacba7f5473d57e Mon Sep 17 00:00:00 2001 From: JP Flouret Date: Wed, 1 Apr 2020 15:05:03 -0700 Subject: [PATCH 1/3] Add user-data paramater to notification callback --- include/ViGEm/Client.h | 8 ++++++-- src/Internal.h | 1 + src/ViGEmClient.cpp | 13 +++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/ViGEm/Client.h b/include/ViGEm/Client.h index 722f3f4..3acc105 100644 --- a/include/ViGEm/Client.h +++ b/include/ViGEm/Client.h @@ -111,6 +111,7 @@ extern "C" { EVT_VIGEM_X360_NOTIFICATION( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, + LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber @@ -124,6 +125,7 @@ extern "C" { EVT_VIGEM_DS4_NOTIFICATION( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, + LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, DS4_LIGHTBAR_COLOR LightbarColor @@ -291,10 +293,11 @@ extern "C" { * \param vigem The driver connection object. * \param target The target device object. * \param notification The notification callback. + * \param userData The user data passed to the notification callback. * * \return A VIGEM_ERROR. */ - VIGEM_API VIGEM_ERROR vigem_target_x360_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_X360_NOTIFICATION notification); + VIGEM_API VIGEM_ERROR vigem_target_x360_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_X360_NOTIFICATION notification, LPVOID userData); /** * \fn VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PVIGEM_DS4_NOTIFICATION notification); @@ -309,10 +312,11 @@ extern "C" { * \param vigem The driver connection object. * \param target The target device object. * \param notification The notification callback. + * \param userData The user data passed to the notification callback. * * \return A VIGEM_ERROR. */ - VIGEM_API VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_DS4_NOTIFICATION notification); + VIGEM_API VIGEM_ERROR vigem_target_ds4_register_notification(PVIGEM_CLIENT vigem, PVIGEM_TARGET target, PFN_VIGEM_DS4_NOTIFICATION notification, LPVOID userData); /** * \fn void vigem_target_x360_unregister_notification(PVIGEM_TARGET target); diff --git a/src/Internal.h b/src/Internal.h index d8f52ea..888a5a7 100644 --- a/src/Internal.h +++ b/src/Internal.h @@ -65,6 +65,7 @@ typedef struct _VIGEM_TARGET_T USHORT ProductId; VIGEM_TARGET_TYPE Type; FARPROC Notification; + LPVOID NotificationUserData; bool closingNotificationThreads; HANDLE cancelNotificationThreadEvent; diff --git a/src/ViGEmClient.cpp b/src/ViGEmClient.cpp index e4d0b88..7e5e2f7 100644 --- a/src/ViGEmClient.cpp +++ b/src/ViGEmClient.cpp @@ -106,7 +106,7 @@ public: void ProcessNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target) override { if(target->Notification != nullptr) - PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, + PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, target->NotificationUserData, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LargeMotor, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->SmallMotor, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LedNumber @@ -126,7 +126,7 @@ public: void ProcessNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target) override { if (target->Notification != nullptr) - PFN_VIGEM_DS4_NOTIFICATION(target->Notification)(client, target, + PFN_VIGEM_DS4_NOTIFICATION(target->Notification)(client, target, target->NotificationUserData, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LargeMotor, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.SmallMotor, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LightbarColor @@ -658,7 +658,8 @@ void vigem_notification_thread_worker( VIGEM_ERROR vigem_target_x360_register_notification( PVIGEM_CLIENT vigem, PVIGEM_TARGET target, - PFN_VIGEM_X360_NOTIFICATION notification + PFN_VIGEM_X360_NOTIFICATION notification, + LPVOID userData ) { if (!vigem) @@ -677,6 +678,7 @@ VIGEM_ERROR vigem_target_x360_register_notification( return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED; target->Notification = reinterpret_cast(notification); + target->NotificationUserData = userData; if (target->cancelNotificationThreadEvent == 0) target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); @@ -704,7 +706,8 @@ VIGEM_ERROR vigem_target_x360_register_notification( VIGEM_ERROR vigem_target_ds4_register_notification( PVIGEM_CLIENT vigem, PVIGEM_TARGET target, - PFN_VIGEM_DS4_NOTIFICATION notification + PFN_VIGEM_DS4_NOTIFICATION notification, + LPVOID userData ) { if (!vigem) @@ -723,6 +726,7 @@ VIGEM_ERROR vigem_target_ds4_register_notification( return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED; target->Notification = reinterpret_cast(notification); + target->NotificationUserData = userData; if (target->cancelNotificationThreadEvent == 0) target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); @@ -767,6 +771,7 @@ void vigem_target_x360_unregister_notification(PVIGEM_TARGET target) } target->Notification = nullptr; + target->NotificationUserData = nullptr; } void vigem_target_ds4_unregister_notification(PVIGEM_TARGET target) From 4ad5aa90e1d11c3aeb1e6c9b1a6e34d16d36a879 Mon Sep 17 00:00:00 2001 From: JP Flouret Date: Wed, 1 Apr 2020 15:39:55 -0700 Subject: [PATCH 2/3] Add user-data parameter to Tester app --- app/Tester/Tester.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Tester/Tester.cpp b/app/Tester/Tester.cpp index 70cb574..f3c8ece 100644 --- a/app/Tester/Tester.cpp +++ b/app/Tester/Tester.cpp @@ -16,6 +16,7 @@ static std::mutex m; VOID CALLBACK notification( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, + LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, UCHAR LedNumber @@ -46,7 +47,7 @@ int main() ret = vigem_target_add(client, x360); - ret = vigem_target_x360_register_notification(client, x360, ¬ification); + ret = vigem_target_x360_register_notification(client, x360, ¬ification, nullptr); #endif const auto ds4 = vigem_target_ds4_alloc(); From cbb94a3750de1edb0ce81e91a12abc4e85a298d1 Mon Sep 17 00:00:00 2001 From: JP Flouret Date: Thu, 2 Apr 2020 10:26:30 -0700 Subject: [PATCH 3/3] Moved user-data to last parameter of notification --- app/Tester/Tester.cpp | 4 ++-- include/ViGEm/Client.h | 8 ++++---- src/ViGEmClient.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Tester/Tester.cpp b/app/Tester/Tester.cpp index f3c8ece..5dcf350 100644 --- a/app/Tester/Tester.cpp +++ b/app/Tester/Tester.cpp @@ -16,10 +16,10 @@ static std::mutex m; VOID CALLBACK notification( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, - LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, - UCHAR LedNumber + UCHAR LedNumber, + LPVOID UserData ) { m.lock(); diff --git a/include/ViGEm/Client.h b/include/ViGEm/Client.h index 3acc105..3d36283 100644 --- a/include/ViGEm/Client.h +++ b/include/ViGEm/Client.h @@ -111,10 +111,10 @@ extern "C" { EVT_VIGEM_X360_NOTIFICATION( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, - LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, - UCHAR LedNumber + UCHAR LedNumber, + LPVOID UserData ); typedef EVT_VIGEM_X360_NOTIFICATION *PFN_VIGEM_X360_NOTIFICATION; @@ -125,10 +125,10 @@ extern "C" { EVT_VIGEM_DS4_NOTIFICATION( PVIGEM_CLIENT Client, PVIGEM_TARGET Target, - LPVOID UserData, UCHAR LargeMotor, UCHAR SmallMotor, - DS4_LIGHTBAR_COLOR LightbarColor + DS4_LIGHTBAR_COLOR LightbarColor, + LPVOID UserData ); typedef EVT_VIGEM_DS4_NOTIFICATION *PFN_VIGEM_DS4_NOTIFICATION; diff --git a/src/ViGEmClient.cpp b/src/ViGEmClient.cpp index 7e5e2f7..18e8bd8 100644 --- a/src/ViGEmClient.cpp +++ b/src/ViGEmClient.cpp @@ -106,10 +106,11 @@ public: void ProcessNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target) override { if(target->Notification != nullptr) - PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, target->NotificationUserData, + PFN_VIGEM_X360_NOTIFICATION(target->Notification)(client, target, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LargeMotor, ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->SmallMotor, - ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LedNumber + ((PXUSB_REQUEST_NOTIFICATION)lpPayloadBuffer)->LedNumber, + target->NotificationUserData ); } }; @@ -126,10 +127,11 @@ public: void ProcessNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target) override { if (target->Notification != nullptr) - PFN_VIGEM_DS4_NOTIFICATION(target->Notification)(client, target, target->NotificationUserData, + PFN_VIGEM_DS4_NOTIFICATION(target->Notification)(client, target, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LargeMotor, ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.SmallMotor, - ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LightbarColor + ((PDS4_REQUEST_NOTIFICATION)lpPayloadBuffer)->Report.LightbarColor, + target->NotificationUserData ); } };