diff options
| author | Matthew Parlane <parlane@gmail.com> | 2013-01-01 16:53:59 +1300 |
|---|---|---|
| committer | Matthew Parlane <parlane@gmail.com> | 2013-01-01 16:53:59 +1300 |
| commit | f695f088a748008c8341c10b41301bb3bd43747b (patch) | |
| tree | 7fd8cff3d15d91c1c0e261b6437b07358b0e724f /Source | |
| parent | 9411c0ac271fb12a6c877996ea8972f5903831d3 (diff) | |
Add usb thread to check for usb updates.
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_hid.cpp | 34 | ||||
| -rw-r--r-- | Source/Core/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 <time.h> + +#if defined(_MSC_VER) || defined(__MINGW32__) +# include <time.h> +#ifndef _TIMEVAL_DEFINED /* also in winsock[2].h */ +#define _TIMEVAL_DEFINED +struct timeval { + long tv_sec; + long tv_usec; +}; +#endif /* _TIMEVAL_DEFINED */ +#else +# include <sys/time.h> +#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<u32,libusb_device_handle*>::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 <list> #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<u32,libusb_device_handle*> open_devices; std::map<std::string,int> device_identifiers; - + std::thread usb_thread; + bool usb_thread_running; typedef struct { |
