Merge pull request #9 from jpflouret/master

Add user-data paramater to notification callback
This commit is contained in:
Benjamin Höglinger
2020-04-03 12:28:40 +02:00
committed by GitHub
4 changed files with 24 additions and 11 deletions

View File

@@ -18,7 +18,8 @@ VOID CALLBACK notification(
PVIGEM_TARGET Target,
UCHAR LargeMotor,
UCHAR SmallMotor,
UCHAR LedNumber
UCHAR LedNumber,
LPVOID UserData
)
{
m.lock();
@@ -46,7 +47,7 @@ int main()
ret = vigem_target_add(client, x360);
ret = vigem_target_x360_register_notification(client, x360, &notification);
ret = vigem_target_x360_register_notification(client, x360, &notification, nullptr);
#endif
const auto ds4 = vigem_target_ds4_alloc();

View File

@@ -113,7 +113,8 @@ extern "C" {
PVIGEM_TARGET Target,
UCHAR LargeMotor,
UCHAR SmallMotor,
UCHAR LedNumber
UCHAR LedNumber,
LPVOID UserData
);
typedef EVT_VIGEM_X360_NOTIFICATION *PFN_VIGEM_X360_NOTIFICATION;
@@ -126,7 +127,8 @@ extern "C" {
PVIGEM_TARGET Target,
UCHAR LargeMotor,
UCHAR SmallMotor,
DS4_LIGHTBAR_COLOR LightbarColor
DS4_LIGHTBAR_COLOR LightbarColor,
LPVOID UserData
);
typedef EVT_VIGEM_DS4_NOTIFICATION *PFN_VIGEM_DS4_NOTIFICATION;
@@ -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);

View File

@@ -65,6 +65,7 @@ typedef struct _VIGEM_TARGET_T
USHORT ProductId;
VIGEM_TARGET_TYPE Type;
FARPROC Notification;
LPVOID NotificationUserData;
bool closingNotificationThreads;
HANDLE cancelNotificationThreadEvent;

View File

@@ -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,
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
);
}
};
@@ -129,7 +130,8 @@ public:
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
);
}
};
@@ -658,7 +660,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 +680,7 @@ VIGEM_ERROR vigem_target_x360_register_notification(
return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED;
target->Notification = reinterpret_cast<FARPROC>(notification);
target->NotificationUserData = userData;
if (target->cancelNotificationThreadEvent == 0)
target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
@@ -704,7 +708,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 +728,7 @@ VIGEM_ERROR vigem_target_ds4_register_notification(
return VIGEM_ERROR_CALLBACK_ALREADY_REGISTERED;
target->Notification = reinterpret_cast<FARPROC>(notification);
target->NotificationUserData = userData;
if (target->cancelNotificationThreadEvent == 0)
target->cancelNotificationThreadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
@@ -767,6 +773,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)