From d087cb95cd4c324828a1747aa4e831fa4f7dc115 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Thu, 4 Dec 2014 16:54:25 +0100 Subject: [PATCH] WiimoteReal: shuffle code around --- Source/Core/Core/HW/WiimoteReal/IOdarwin.mm | 176 ++++++++++---------- 1 file changed, 88 insertions(+), 88 deletions(-) diff --git a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm index f2f0236341..78c13734ba 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm +++ b/Source/Core/Core/HW/WiimoteReal/IOdarwin.mm @@ -10,97 +10,9 @@ } @end -@implementation SearchBT -- (void) deviceInquiryComplete: (IOBluetoothDeviceInquiry *) sender - error: (IOReturn) error - aborted: (BOOL) aborted -{ - done = true; - CFRunLoopStop(CFRunLoopGetCurrent()); -} - -- (void) deviceInquiryDeviceFound: (IOBluetoothDeviceInquiry *) sender - device: (IOBluetoothDevice *) device -{ - NOTICE_LOG(WIIMOTE, "Discovered bluetooth device at %s: %s", - [[device addressString] UTF8String], - [[device name] UTF8String]); - - if ([[sender foundDevices] count] == maxDevices) - [sender stop]; -} -@end - @interface ConnectBT: NSObject {} @end -@implementation ConnectBT -- (void) l2capChannelData: (IOBluetoothL2CAPChannel *) l2capChannel - data: (unsigned char *) data - length: (NSUInteger) length -{ - IOBluetoothDevice *device = [l2capChannel device]; - WiimoteReal::Wiimote *wm = nullptr; - - std::lock_guard lk(WiimoteReal::g_refresh_lock); - - for (int i = 0; i < MAX_WIIMOTES; i++) - { - if (WiimoteReal::g_wiimotes[i] == nullptr) - continue; - if ([device isEqual: WiimoteReal::g_wiimotes[i]->m_btd] == TRUE) - wm = WiimoteReal::g_wiimotes[i]; - } - - if (wm == nullptr) { - ERROR_LOG(WIIMOTE, "Received packet for unknown wiimote"); - return; - } - - if (length > MAX_PAYLOAD) { - WARN_LOG(WIIMOTE, "Dropping packet for wiimote %i, too large", - wm->m_index + 1); - return; - } - - if (wm->m_inputlen != -1) { - WARN_LOG(WIIMOTE, "Dropping packet for wiimote %i, queue full", - wm->m_index + 1); - return; - } - - memcpy(wm->m_input, data, length); - wm->m_inputlen = length; - - CFRunLoopStop(CFRunLoopGetCurrent()); -} - -- (void) l2capChannelClosed: (IOBluetoothL2CAPChannel *) l2capChannel -{ - IOBluetoothDevice *device = [l2capChannel device]; - WiimoteReal::Wiimote *wm = nullptr; - - std::lock_guard lk(WiimoteReal::g_refresh_lock); - - for (int i = 0; i < MAX_WIIMOTES; i++) - { - if (WiimoteReal::g_wiimotes[i] == nullptr) - continue; - if ([device isEqual: WiimoteReal::g_wiimotes[i]->m_btd] == TRUE) - wm = WiimoteReal::g_wiimotes[i]; - } - - if (wm == nullptr) { - ERROR_LOG(WIIMOTE, "Channel for unknown wiimote was closed"); - return; - } - - WARN_LOG(WIIMOTE, "Lost channel to wiimote %i", wm->m_index + 1); - - wm->DisconnectInternal(); -} -@end - namespace WiimoteReal { @@ -346,4 +258,92 @@ void Wiimote::DisablePowerAssertionInternal() } } +} // namespace + +@implementation SearchBT +- (void) deviceInquiryComplete: (IOBluetoothDeviceInquiry *) sender + error: (IOReturn) error + aborted: (BOOL) aborted +{ + done = true; + CFRunLoopStop(CFRunLoopGetCurrent()); } + +- (void) deviceInquiryDeviceFound: (IOBluetoothDeviceInquiry *) sender + device: (IOBluetoothDevice *) device +{ + NOTICE_LOG(WIIMOTE, "Discovered bluetooth device at %s: %s", + [[device addressString] UTF8String], + [[device name] UTF8String]); + + if ([[sender foundDevices] count] == maxDevices) + [sender stop]; +} +@end + +@implementation ConnectBT +- (void) l2capChannelData: (IOBluetoothL2CAPChannel *) l2capChannel + data: (unsigned char *) data + length: (NSUInteger) length +{ + IOBluetoothDevice *device = [l2capChannel device]; + WiimoteReal::Wiimote *wm = nullptr; + + std::lock_guard lk(WiimoteReal::g_refresh_lock); + + for (int i = 0; i < MAX_WIIMOTES; i++) + { + if (WiimoteReal::g_wiimotes[i] == nullptr) + continue; + if ([device isEqual: WiimoteReal::g_wiimotes[i]->m_btd] == TRUE) + wm = WiimoteReal::g_wiimotes[i]; + } + + if (wm == nullptr) { + ERROR_LOG(WIIMOTE, "Received packet for unknown wiimote"); + return; + } + + if (length > MAX_PAYLOAD) { + WARN_LOG(WIIMOTE, "Dropping packet for wiimote %i, too large", + wm->m_index + 1); + return; + } + + if (wm->m_inputlen != -1) { + WARN_LOG(WIIMOTE, "Dropping packet for wiimote %i, queue full", + wm->m_index + 1); + return; + } + + memcpy(wm->m_input, data, length); + wm->m_inputlen = length; + + CFRunLoopStop(CFRunLoopGetCurrent()); +} + +- (void) l2capChannelClosed: (IOBluetoothL2CAPChannel *) l2capChannel +{ + IOBluetoothDevice *device = [l2capChannel device]; + WiimoteReal::Wiimote *wm = nullptr; + + std::lock_guard lk(WiimoteReal::g_refresh_lock); + + for (int i = 0; i < MAX_WIIMOTES; i++) + { + if (WiimoteReal::g_wiimotes[i] == nullptr) + continue; + if ([device isEqual: WiimoteReal::g_wiimotes[i]->m_btd] == TRUE) + wm = WiimoteReal::g_wiimotes[i]; + } + + if (wm == nullptr) { + ERROR_LOG(WIIMOTE, "Channel for unknown wiimote was closed"); + return; + } + + WARN_LOG(WIIMOTE, "Lost channel to wiimote %i", wm->m_index + 1); + + wm->DisconnectInternal(); +} +@end