From f695f088a748008c8341c10b41301bb3bd43747b Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Tue, 1 Jan 2013 16:53:59 +1300 Subject: [PATCH] Add usb thread to check for usb updates. --- .../Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp | 34 ++++++++++++++++++- .../Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.h | 7 ++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp index 2e7b56efc6..b0b3f349aa 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp @@ -21,20 +21,52 @@ #include "WII_IPC_HLE.h" #include "WII_IPC_HLE_Device_hid.h" #include "errno.h" -#include + +#if defined(_MSC_VER) || defined(__MINGW32__) +# include +#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ +#define _TIMEVAL_DEFINED +struct timeval { + long tv_sec; + long tv_usec; +}; +#endif /* _TIMEVAL_DEFINED */ +#else +# include +#endif #define MAX_DEVICE_DEVNUM 256 static u64 hidDeviceAliases[MAX_DEVICE_DEVNUM]; +// Regular thread +void CWII_IPC_HLE_Device_hid::checkUsbUpdates(CWII_IPC_HLE_Device_hid* hid) +{ + timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 500; + + while (hid->usb_thread_running) + libusb_handle_events_timeout(NULL, &tv); + + return; +} + + CWII_IPC_HLE_Device_hid::CWII_IPC_HLE_Device_hid(u32 _DeviceID, const std::string& _rDeviceName) : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName) { memset(hidDeviceAliases, 0, sizeof(hidDeviceAliases)); libusb_init(NULL); + + usb_thread_running = true; + usb_thread = std::thread(checkUsbUpdates, this); } CWII_IPC_HLE_Device_hid::~CWII_IPC_HLE_Device_hid() { + usb_thread_running = false; + usb_thread.join(); + for ( std::map::const_iterator iter = open_devices.begin(); iter != open_devices.end(); ++iter ) { libusb_close(iter->second); diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.h index 2acc2e0e7f..58c3c88da2 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.h @@ -20,6 +20,7 @@ #include "WII_IPC_HLE.h" #include "WII_IPC_HLE_Device.h" #include "libusb.h" +#include "Thread.h" #include #define HID_ID_MASK 0x0000FFFFFFFFFFFF @@ -130,11 +131,13 @@ private: void ConvertEndpointToWii(WiiHIDEndpointDescriptor *dest, const struct libusb_endpoint_descriptor *src); int Align(int num, int alignment); - + static void checkUsbUpdates(CWII_IPC_HLE_Device_hid* hid); + struct libusb_device_handle * GetDeviceByDevNum(u32 devNum); std::map open_devices; std::map device_identifiers; - + std::thread usb_thread; + bool usb_thread_running; typedef struct {