From 8a3354d11bbd799b39e3e1677cda0f02ca9cb61e Mon Sep 17 00:00:00 2001 From: Lysann Schlegel Date: Sat, 8 Dec 2012 13:11:36 +0100 Subject: [PATCH] OSX 10.6 compatibility --- src/CMakeLists.txt | 6 ++++-- src/os_mac/os_mac.h | 7 +++++++ src/os_mac/os_mac.m | 26 +++++++++++++++++++++++++- src/os_mac/os_mac_find.m | 18 +++++++++++++++++- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9b69837..d3c9f4e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,18 +58,20 @@ if(WIN32) elseif(LINUX) target_link_libraries(wiiuse m ${BLUEZ_LIBRARIES}) elseif(APPLE) + # link libraries find_library(IOBLUETOOTH_FRAMEWORK NAMES IOBluetooth) - find_library(COREFOUNDATION_FRAMEWORK NAMES CoreFoundation) - find_library(FOUNDATION_FRAMEWORK NAMES Foundation) target_link_libraries(wiiuse ${IOBLUETOOTH_FRAMEWORK} ${COREFOUNDATION_FRAMEWORK} ${FOUNDATION_FRAMEWORK}) + + # do not link Objective-C runtime with clang + set_target_properties(wiiuse PROPERTIES XCODE_ATTRIBUTE_CLANG_LINK_OBJC_RUNTIME "NO") endif() set_property(TARGET diff --git a/src/os_mac/os_mac.h b/src/os_mac/os_mac.h index 7537f7b..11c05a3 100644 --- a/src/os_mac/os_mac.h +++ b/src/os_mac/os_mac.h @@ -42,6 +42,13 @@ #import "../wiiuse_internal.h" +#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 1 +#else +#define WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE 0 +#endif + + @interface WiiuseWiimote : NSObject { wiimote* wm; // reference to the C wiimote struct diff --git a/src/os_mac/os_mac.m b/src/os_mac/os_mac.m index 517441a..f843ab8 100644 --- a/src/os_mac/os_mac.m +++ b/src/os_mac/os_mac.m @@ -243,7 +243,12 @@ byte* data = (byte*) data_; // This is done in case the control channel woke up this handler - if(!data || ([channel PSM] == kBluetoothL2CAPPSMHIDControl)) { +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + BluetoothL2CAPPSM psm = channel.PSM; +#else + BluetoothL2CAPPSM psm = [channel getPSM]; +#endif + if(!data || (psm == kBluetoothL2CAPPSMHIDControl)) { return; } @@ -255,6 +260,25 @@ [newData release]; } +#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +// the following delegate methods were required on 10.6. They are here to get rid of 10.6 compiler warnings. +- (void)l2capChannelOpenComplete:(IOBluetoothL2CAPChannel*)l2capChannel status:(IOReturn)error { + /* no-op */ +} +- (void)l2capChannelClosed:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +- (void)l2capChannelReconfigured:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +- (void)l2capChannelWriteComplete:(IOBluetoothL2CAPChannel*)l2capChannel refcon:(void*)refcon status:(IOReturn)error { + /* no-op */ +} +- (void)l2capChannelQueueSpaceAvailable:(IOBluetoothL2CAPChannel*)l2capChannel { + /* no-op */ +} +#endif + @end #pragma mark - diff --git a/src/os_mac/os_mac_find.m b/src/os_mac/os_mac_find.m index d576a19..4107a3e 100644 --- a/src/os_mac/os_mac_find.m +++ b/src/os_mac/os_mac_find.m @@ -43,12 +43,19 @@ #import #import #import +#if !WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE +#import // IOBluetoothLocalDeviceGetPowerState +#endif #pragma mark - #pragma mark WiiuseDeviceInquiry +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE @interface WiiuseDeviceInquiry : NSObject { +#else +@interface WiiuseDeviceInquiry : NSObject { +#endif wiimote** wiimotes; NSUInteger maxDevices; int timeout; @@ -68,8 +75,17 @@ - (id) initWithMemory:(wiimote**)wiimotes_ maxDevices:(int)maxDevices_ timeout:(int)timeout_ { self = [super init]; if(self) { + + BluetoothHCIPowerState powerState = kBluetoothHCIPowerStateUnintialized; +#if WIIUSE_MAC_OS_X_VERSION_10_7_OR_ABOVE + if([IOBluetoothHostController defaultController]) + powerState = [IOBluetoothHostController defaultController].powerState; +#else + // yes it is deprecated. no, there is no alternative (on 10.6). + IOBluetoothLocalDeviceGetPowerState(&powerState); +#endif if (![IOBluetoothHostController defaultController] || - [IOBluetoothHostController defaultController].powerState == kBluetoothHCIPowerStateOFF) + powerState != kBluetoothHCIPowerStateON) { WIIUSE_DEBUG("Bluetooth hardware not available."); [self release];