diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/ar/HIDRemote.h | 280 | ||||
-rw-r--r-- | osdep/ar/HIDRemote.m | 3450 |
2 files changed, 1865 insertions, 1865 deletions
diff --git a/osdep/ar/HIDRemote.h b/osdep/ar/HIDRemote.h index 9dd16faa5a..33f59f322d 100644 --- a/osdep/ar/HIDRemote.h +++ b/osdep/ar/HIDRemote.h @@ -73,78 +73,78 @@ typedef enum { - kHIDRemoteModeNone = 0L, - kHIDRemoteModeShared, // Share the remote with others - let's you listen to the remote control events as long as noone has an exclusive lock on it - // (RECOMMENDED ONLY FOR SPECIAL PURPOSES) + kHIDRemoteModeNone = 0L, + kHIDRemoteModeShared, // Share the remote with others - let's you listen to the remote control events as long as noone has an exclusive lock on it + // (RECOMMENDED ONLY FOR SPECIAL PURPOSES) - kHIDRemoteModeExclusive, // Try to acquire an exclusive lock on the remote (NOT RECOMMENDED) + kHIDRemoteModeExclusive, // Try to acquire an exclusive lock on the remote (NOT RECOMMENDED) - kHIDRemoteModeExclusiveAuto // Try to acquire an exclusive lock on the remote whenever the application has focus. Temporarily release control over the - // remote when another application has focus (RECOMMENDED) + kHIDRemoteModeExclusiveAuto // Try to acquire an exclusive lock on the remote whenever the application has focus. Temporarily release control over the + // remote when another application has focus (RECOMMENDED) } HIDRemoteMode; typedef enum { - /* A code reserved for "no button" (needed for tracking) */ - kHIDRemoteButtonCodeNone = 0L, - - /* Standard codes - available for white plastic and aluminum remote */ - kHIDRemoteButtonCodeUp, - kHIDRemoteButtonCodeDown, - kHIDRemoteButtonCodeLeft, - kHIDRemoteButtonCodeRight, - kHIDRemoteButtonCodeCenter, - kHIDRemoteButtonCodeMenu, - - /* Extra codes - Only available for the new aluminum version of the remote */ - kHIDRemoteButtonCodePlay, - - /* Masks */ - kHIDRemoteButtonCodeCodeMask = 0xFFL, - kHIDRemoteButtonCodeHoldMask = (1L << 16L), - kHIDRemoteButtonCodeSpecialMask = (1L << 17L), - kHIDRemoteButtonCodeAluminumMask = (1L << 21L), // PRIVATE - only used internally - - /* Hold button standard codes - available for white plastic and aluminum remote */ - kHIDRemoteButtonCodeUpHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeUp), - kHIDRemoteButtonCodeDownHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeDown), - kHIDRemoteButtonCodeLeftHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeLeft), - kHIDRemoteButtonCodeRightHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeRight), - kHIDRemoteButtonCodeCenterHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeCenter), - kHIDRemoteButtonCodeMenuHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeMenu), - - /* Hold button extra codes - Only available for aluminum version of the remote */ - kHIDRemoteButtonCodePlayHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodePlay), - - /* DEPRECATED codes - compatibility with HIDRemote 1.0 */ - kHIDRemoteButtonCodePlus = kHIDRemoteButtonCodeUp, - kHIDRemoteButtonCodePlusHold = kHIDRemoteButtonCodeUpHold, - kHIDRemoteButtonCodeMinus = kHIDRemoteButtonCodeDown, - kHIDRemoteButtonCodeMinusHold = kHIDRemoteButtonCodeDownHold, - kHIDRemoteButtonCodePlayPause = kHIDRemoteButtonCodeCenter, - kHIDRemoteButtonCodePlayPauseHold = kHIDRemoteButtonCodeCenterHold, - - /* Special purpose codes */ - kHIDRemoteButtonCodeIDChanged = (kHIDRemoteButtonCodeSpecialMask|(1L << 18L)), // (the ID of the connected remote has changed, you can safely ignore this) - #ifdef _HIDREMOTE_EXTENSIONS - #define _HIDREMOTE_EXTENSIONS_SECTION 1 - #include "HIDRemoteAdditions.h" - #undef _HIDREMOTE_EXTENSIONS_SECTION - #endif /* _HIDREMOTE_EXTENSIONS */ + /* A code reserved for "no button" (needed for tracking) */ + kHIDRemoteButtonCodeNone = 0L, + + /* Standard codes - available for white plastic and aluminum remote */ + kHIDRemoteButtonCodeUp, + kHIDRemoteButtonCodeDown, + kHIDRemoteButtonCodeLeft, + kHIDRemoteButtonCodeRight, + kHIDRemoteButtonCodeCenter, + kHIDRemoteButtonCodeMenu, + + /* Extra codes - Only available for the new aluminum version of the remote */ + kHIDRemoteButtonCodePlay, + + /* Masks */ + kHIDRemoteButtonCodeCodeMask = 0xFFL, + kHIDRemoteButtonCodeHoldMask = (1L << 16L), + kHIDRemoteButtonCodeSpecialMask = (1L << 17L), + kHIDRemoteButtonCodeAluminumMask = (1L << 21L), // PRIVATE - only used internally + + /* Hold button standard codes - available for white plastic and aluminum remote */ + kHIDRemoteButtonCodeUpHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeUp), + kHIDRemoteButtonCodeDownHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeDown), + kHIDRemoteButtonCodeLeftHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeLeft), + kHIDRemoteButtonCodeRightHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeRight), + kHIDRemoteButtonCodeCenterHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeCenter), + kHIDRemoteButtonCodeMenuHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodeMenu), + + /* Hold button extra codes - Only available for aluminum version of the remote */ + kHIDRemoteButtonCodePlayHold = (kHIDRemoteButtonCodeHoldMask|kHIDRemoteButtonCodePlay), + + /* DEPRECATED codes - compatibility with HIDRemote 1.0 */ + kHIDRemoteButtonCodePlus = kHIDRemoteButtonCodeUp, + kHIDRemoteButtonCodePlusHold = kHIDRemoteButtonCodeUpHold, + kHIDRemoteButtonCodeMinus = kHIDRemoteButtonCodeDown, + kHIDRemoteButtonCodeMinusHold = kHIDRemoteButtonCodeDownHold, + kHIDRemoteButtonCodePlayPause = kHIDRemoteButtonCodeCenter, + kHIDRemoteButtonCodePlayPauseHold = kHIDRemoteButtonCodeCenterHold, + + /* Special purpose codes */ + kHIDRemoteButtonCodeIDChanged = (kHIDRemoteButtonCodeSpecialMask|(1L << 18L)), // (the ID of the connected remote has changed, you can safely ignore this) + #ifdef _HIDREMOTE_EXTENSIONS + #define _HIDREMOTE_EXTENSIONS_SECTION 1 + #include "HIDRemoteAdditions.h" + #undef _HIDREMOTE_EXTENSIONS_SECTION + #endif /* _HIDREMOTE_EXTENSIONS */ } HIDRemoteButtonCode; typedef enum { - kHIDRemoteModelUndetermined = 0L, // Assume a white plastic remote - kHIDRemoteModelWhitePlastic, // Signal *likely* to be coming from a white plastic remote - kHIDRemoteModelAluminum // Signal *definitely* coming from an aluminum remote + kHIDRemoteModelUndetermined = 0L, // Assume a white plastic remote + kHIDRemoteModelWhitePlastic, // Signal *likely* to be coming from a white plastic remote + kHIDRemoteModelAluminum // Signal *definitely* coming from an aluminum remote } HIDRemoteModel; typedef enum { - kHIDRemoteAluminumRemoteSupportLevelNone = 0L, // This system has no support for the Aluminum Remote at all - kHIDRemoteAluminumRemoteSupportLevelEmulation, // This system possibly has support for the Aluminum Remote (via emulation) - kHIDRemoteAluminumRemoteSupportLevelNative // This system has native support for the Aluminum Remote + kHIDRemoteAluminumRemoteSupportLevelNone = 0L, // This system has no support for the Aluminum Remote at all + kHIDRemoteAluminumRemoteSupportLevelEmulation, // This system possibly has support for the Aluminum Remote (via emulation) + kHIDRemoteAluminumRemoteSupportLevelNative // This system has native support for the Aluminum Remote } HIDRemoteAluminumRemoteSupportLevel; @class HIDRemote; @@ -153,46 +153,46 @@ typedef enum @protocol HIDRemoteDelegate // Notification of button events -- (void)hidRemote:(HIDRemote *)hidRemote // The instance of HIDRemote sending this - eventWithButton:(HIDRemoteButtonCode)buttonCode // Event for the button specified by code - isPressed:(BOOL)isPressed // The button was pressed (YES) / released (NO) - fromHardwareWithAttributes:(NSMutableDictionary *)attributes; // Information on the device this event comes from +- (void)hidRemote:(HIDRemote *)hidRemote // The instance of HIDRemote sending this + eventWithButton:(HIDRemoteButtonCode)buttonCode // Event for the button specified by code + isPressed:(BOOL)isPressed // The button was pressed (YES) / released (NO) + fromHardwareWithAttributes:(NSMutableDictionary *)attributes; // Information on the device this event comes from @optional // Notification of ID changes -- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when the user switched to a remote control with a different ID - remoteIDChangedOldID:(SInt32)old - newID:(SInt32)newID - forHardwareWithAttributes:(NSMutableDictionary *)attributes; +- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when the user switched to a remote control with a different ID + remoteIDChangedOldID:(SInt32)old + newID:(SInt32)newID + forHardwareWithAttributes:(NSMutableDictionary *)attributes; // Notification about hardware additions/removals -- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when new hardware was found / added to HIDRemote's pool - foundNewHardwareWithAttributes:(NSMutableDictionary *)attributes; +- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when new hardware was found / added to HIDRemote's pool + foundNewHardwareWithAttributes:(NSMutableDictionary *)attributes; -- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when initialization of new hardware as requested failed - failedNewHardwareWithError:(NSError *)error; +- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when initialization of new hardware as requested failed + failedNewHardwareWithError:(NSError *)error; -- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when hardware was removed from HIDRemote's pool - releasedHardwareWithAttributes:(NSMutableDictionary *)attributes; +- (void)hidRemote:(HIDRemote *)hidRemote // Invoked when hardware was removed from HIDRemote's pool + releasedHardwareWithAttributes:(NSMutableDictionary *)attributes; // ### WARNING: Unless you know VERY PRECISELY what you are doing, do not implement any of the delegate methods below. ### // Matching of newly found receiver hardware -- (BOOL)hidRemote:(HIDRemote *)hidRemote // Invoked when new hardware is inspected - inspectNewHardwareWithService:(io_service_t)service // - prematchResult:(BOOL)prematchResult; // Return YES if HIDRemote should go on with this hardware and try - // to use it, or NO if it should not be persued further. +- (BOOL)hidRemote:(HIDRemote *)hidRemote // Invoked when new hardware is inspected + inspectNewHardwareWithService:(io_service_t)service // + prematchResult:(BOOL)prematchResult; // Return YES if HIDRemote should go on with this hardware and try + // to use it, or NO if it should not be persued further. // Exlusive lock lending - (BOOL)hidRemote:(HIDRemote *)hidRemote - lendExclusiveLockToApplicationWithInfo:(NSDictionary *)applicationInfo; + lendExclusiveLockToApplicationWithInfo:(NSDictionary *)applicationInfo; - (void)hidRemote:(HIDRemote *)hidRemote - exclusiveLockReleasedByApplicationWithInfo:(NSDictionary *)applicationInfo; + exclusiveLockReleasedByApplicationWithInfo:(NSDictionary *)applicationInfo; - (BOOL)hidRemote:(HIDRemote *)hidRemote - shouldRetryExclusiveLockWithInfo:(NSDictionary *)applicationInfo; + shouldRetryExclusiveLockWithInfo:(NSDictionary *)applicationInfo; @end @@ -201,65 +201,65 @@ typedef enum @interface HIDRemote : NSObject { - // IOMasterPort - mach_port_t _masterPort; - - // Notification ports - IONotificationPortRef _notifyPort; - CFRunLoopSourceRef _notifyRLSource; - - // Matching iterator - io_iterator_t _matchingServicesIterator; - - // SecureInput notification - io_object_t _secureInputNotification; - - // Service attributes - NSMutableDictionary *_serviceAttribMap; - - // Mode - HIDRemoteMode _mode; - BOOL _autoRecover; - NSTimer *_autoRecoveryTimer; - - // Delegate - NSObject <HIDRemoteDelegate> *_delegate; - - // Last seen ID and remote model - SInt32 _lastSeenRemoteID; - HIDRemoteModel _lastSeenModel; - SInt32 _lastSeenModelRemoteID; - - // Unused button codes - NSArray *_unusedButtonCodes; - - // Simulate Plus/Minus Hold - BOOL _simulateHoldEvents; - - // SecureEventInput workaround - BOOL _secureEventInputWorkAround; - UInt64 _lastSecureEventInputPIDSum; - uid_t _lastFrontUserSession; - - // Exclusive lock lending - BOOL _exclusiveLockLending; - BOOL _sendExclusiveResourceReuseNotification; - NSNumber *_waitForReturnByPID; - NSNumber *_returnToPID; - BOOL _isRestarting; - - // Status notifications - BOOL _sendStatusNotifications; - NSString *_pidString; - - // Status - BOOL _applicationIsTerminating; - BOOL _isStopping; - - // Thread safety - #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING /* #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING if you're running your HIDRemote instance on a background thread (requires OS X 10.5 or later) */ - NSThread *_runOnThread; - #endif + // IOMasterPort + mach_port_t _masterPort; + + // Notification ports + IONotificationPortRef _notifyPort; + CFRunLoopSourceRef _notifyRLSource; + + // Matching iterator + io_iterator_t _matchingServicesIterator; + + // SecureInput notification + io_object_t _secureInputNotification; + + // Service attributes + NSMutableDictionary *_serviceAttribMap; + + // Mode + HIDRemoteMode _mode; + BOOL _autoRecover; + NSTimer *_autoRecoveryTimer; + + // Delegate + NSObject <HIDRemoteDelegate> *_delegate; + + // Last seen ID and remote model + SInt32 _lastSeenRemoteID; + HIDRemoteModel _lastSeenModel; + SInt32 _lastSeenModelRemoteID; + + // Unused button codes + NSArray *_unusedButtonCodes; + + // Simulate Plus/Minus Hold + BOOL _simulateHoldEvents; + + // SecureEventInput workaround + BOOL _secureEventInputWorkAround; + UInt64 _lastSecureEventInputPIDSum; + uid_t _lastFrontUserSession; + + // Exclusive lock lending + BOOL _exclusiveLockLending; + BOOL _sendExclusiveResourceReuseNotification; + NSNumber *_waitForReturnByPID; + NSNumber *_returnToPID; + BOOL _isRestarting; + + // Status notifications + BOOL _sendStatusNotifications; + NSString *_pidString; + + // Status + BOOL _applicationIsTerminating; + BOOL _isStopping; + + // Thread safety + #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING /* #define HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING if you're running your HIDRemote instance on a background thread (requires OS X 10.5 or later) */ + NSThread *_runOnThread; + #endif } #pragma mark -- PUBLIC: Shared HID Remote -- @@ -271,7 +271,7 @@ typedef enum - (HIDRemoteAluminumRemoteSupportLevel)aluminiumRemoteSystemSupportLevel; #pragma mark -- PUBLIC: Interface / API -- -- (BOOL)startRemoteControl:(HIDRemoteMode)hidRemoteMode; +- (BOOL)startRemoteControl:(HIDRemoteMode)hidRemoteMode; - (void)stopRemoteControl; - (BOOL)isStarted; @@ -374,5 +374,5 @@ extern NSString *kHIDRemoteDNStatusActionNoNeed; #pragma mark -- Driver compatibility flags -- typedef enum { - kHIDRemoteCompatibilityFlagsStandardHIDRemoteDevice = 1L, + kHIDRemoteCompatibilityFlagsStandardHIDRemoteDevice = 1L, } HIDRemoteCompatibilityFlags; diff --git a/osdep/ar/HIDRemote.m b/osdep/ar/HIDRemote.m index 4e5b88e770..977b9cbdb9 100644 --- a/osdep/ar/HIDRemote.m +++ b/osdep/ar/HIDRemote.m @@ -52,23 +52,23 @@ #import "HIDRemote.h" // Callback Prototypes -static void HIDEventCallback( void * target, - IOReturn result, - void * refcon, - void * sender); +static void HIDEventCallback( void * target, + IOReturn result, + void * refcon, + void * sender); -static void ServiceMatchingCallback( void *refCon, - io_iterator_t iterator); +static void ServiceMatchingCallback( void *refCon, + io_iterator_t iterator); -static void ServiceNotificationCallback(void * refCon, - io_service_t service, - natural_t messageType, - void * messageArgument); +static void ServiceNotificationCallback(void * refCon, + io_service_t service, + natural_t messageType, + void * messageArgument); -static void SecureInputNotificationCallback( void * refCon, - io_service_t service, - natural_t messageType, - void * messageArgument); +static void SecureInputNotificationCallback( void * refCon, + io_service_t service, + natural_t messageType, + void * messageArgument); // Shared HIDRemote instance static HIDRemote *sHIDRemote = nil; @@ -79,1947 +79,1947 @@ static HIDRemote *sHIDRemote = nil; + (HIDRemote *)sharedHIDRemote { - if (sHIDRemote==nil) - { - sHIDRemote = [[HIDRemote alloc] init]; - } - - return (sHIDRemote); + if (sHIDRemote==nil) + { + sHIDRemote = [[HIDRemote alloc] init]; + } + + return (sHIDRemote); } - (id)init { - if ((self = [super init]) != nil) - { - #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING - _runOnThread = [[NSThread currentThread] retain]; - #endif - - // Detect application becoming active/inactive - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationWillResignActiveNotification object:NSApp]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationWillTerminateNotification object:NSApp]; - - // Handle distributed notifications - _pidString = [[NSString alloc] initWithFormat:@"%d", getpid()]; - - [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemotePing object:nil]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemoteRetry object:kHIDRemoteDNHIDRemoteRetryGlobalObject]; - [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemoteRetry object:_pidString]; - - // Enabled by default: simulate hold events for plus/minus - _simulateHoldEvents = YES; - - // Enabled by default: work around for a locking issue introduced with Security Update 2008-004 / 10.4.9 and beyond (credit for finding this workaround goes to Martin Kahr) - _secureEventInputWorkAround = YES; - _secureInputNotification = 0; - - // Initialize instance variables - _lastSeenRemoteID = -1; - _lastSeenModel = kHIDRemoteModelUndetermined; - _unusedButtonCodes = [[NSMutableArray alloc] init]; - _exclusiveLockLending = NO; - _sendExclusiveResourceReuseNotification = YES; - _applicationIsTerminating = NO; - - // Send status notifications - _sendStatusNotifications = YES; - } - - return (self); + if ((self = [super init]) != nil) + { + #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING + _runOnThread = [[NSThread currentThread] retain]; + #endif + + // Detect application becoming active/inactive + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationWillResignActiveNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_appStatusChanged:) name:NSApplicationWillTerminateNotification object:NSApp]; + + // Handle distributed notifications + _pidString = [[NSString alloc] initWithFormat:@"%d", getpid()]; + + [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemotePing object:nil]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemoteRetry object:kHIDRemoteDNHIDRemoteRetryGlobalObject]; + [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(_handleNotifications:) name:kHIDRemoteDNHIDRemoteRetry object:_pidString]; + + // Enabled by default: simulate hold events for plus/minus + _simulateHoldEvents = YES; + + // Enabled by default: work around for a locking issue introduced with Security Update 2008-004 / 10.4.9 and beyond (credit for finding this workaround goes to Martin Kahr) + _secureEventInputWorkAround = YES; + _secureInputNotification = 0; + + // Initialize instance variables + _lastSeenRemoteID = -1; + _lastSeenModel = kHIDRemoteModelUndetermined; + _unusedButtonCodes = [[NSMutableArray alloc] init]; + _exclusiveLockLending = NO; + _sendExclusiveResourceReuseNotification = YES; + _applicationIsTerminating = NO; + + // Send status notifications + _sendStatusNotifications = YES; + } + + return (self); } - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillResignActiveNotification object:NSApp]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillResignActiveNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:NSApp]; - [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemotePing object:nil]; - [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemoteRetry object:kHIDRemoteDNHIDRemoteRetryGlobalObject]; - [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemoteRetry object:_pidString]; - [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:nil object:nil]; /* As demanded by the documentation for -[NSDistributedNotificationCenter removeObserver:name:object:] */ - - [self stopRemoteControl]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemotePing object:nil]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemoteRetry object:kHIDRemoteDNHIDRemoteRetryGlobalObject]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:kHIDRemoteDNHIDRemoteRetry object:_pidString]; + [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:nil object:nil]; /* As demanded by the documentation for -[NSDistributedNotificationCenter removeObserver:name:object:] */ + + [self stopRemoteControl]; - [self setExclusiveLockLendingEnabled:NO]; + [self setExclusiveLockLendingEnabled:NO]; - [self setDelegate:nil]; + [self setDelegate:nil]; - if (_unusedButtonCodes != nil) - { - [_unusedButtonCodes release]; - _unusedButtonCodes = nil; - } + if (_unusedButtonCodes != nil) + { + [_unusedButtonCodes release]; + _unusedButtonCodes = nil; + } - #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING - [_runOnThread release]; - _runOnThread = nil; - #endif + #ifdef HIDREMOTE_THREADSAFETY_HARDENED_NOTIFICATION_HANDLING + [_runOnThread release]; + _runOnThread = nil; + #endif - [_pidString release]; - _pidString = nil; + [_pidString release]; + _pidString = nil; - [super dealloc]; + [super dealloc]; } #pragma mark -- PUBLIC: System Information -- + (BOOL)isCandelairInstalled { - mach_port_t masterPort = 0; - kern_return_t kernResult; - io_service_t matchingService = 0; - BOOL isInstalled = NO; + mach_port_t masterPort = 0; + kern_return_t kernResult; + io_service_t matchingService = 0; + BOOL isInstalled = NO; - kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort); - if ((kernResult!=kIOReturnSuccess) || (masterPort==0)) { return(NO); } + kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort); + if ((kernResult!=kIOReturnSuccess) || (masterPort==0)) { return(NO); } - if ((matchingService = IOServiceGetMatchingService(masterPort, IOServiceMatching("IOSPIRITIRController"))) != 0) - { - isInstalled = YES; - IOObjectRelease((io_object_t) matchingService); - } + if ((matchingService = IOServiceGetMatchingService(masterPort, IOServiceMatching("IOSPIRITIRController"))) != 0) + { + isInstalled = YES; + IOObjectRelease((io_object_t) matchingService); + } - mach_port_deallocate(mach_task_self(), masterPort); + mach_port_deallocate(mach_task_self(), masterPort); - return (isInstalled); + return (isInstalled); } + (BOOL)isCandelairInstallationRequiredForRemoteMode:(HIDRemoteMode)remoteMode { - return (NO); + return (NO); } - (HIDRemoteAluminumRemoteSupportLevel)aluminiumRemoteSystemSupportLevel { - HIDRemoteAluminumRemoteSupportLevel supportLevel = kHIDRemoteAluminumRemoteSupportLevelNone; - NSEnumerator *attribDictsEnum; - NSDictionary *hidAttribsDict; - - attribDictsEnum = [_serviceAttribMap objectEnumerator]; - - while ((hidAttribsDict = [attribDictsEnum nextObject]) != nil) - { - NSNumber *deviceSupportLevel; - - if ((deviceSupportLevel = [hidAttribsDict objectForKey:kHIDRemoteAluminumRemoteSupportLevel]) != nil) - { - if ([deviceSupportLevel intValue] > (int)supportLevel) - { - supportLevel = [deviceSupportLevel intValue]; - } - } - } - - return (supportLevel); + HIDRemoteAluminumRemoteSupportLevel supportLevel = kHIDRemoteAluminumRemoteSupportLevelNone; + NSEnumerator *attribDictsEnum; + NSDictionary *hidAttribsDict; + + attribDictsEnum = [_serviceAttribMap objectEnumerator]; + + while ((hidAttribsDict = [attribDictsEnum nextObject]) != nil) + { + NSNumber *deviceSupportLevel; + + if ((deviceSupportLevel = [hidAttribsDict objectForKey:kHIDRemoteAluminumRemoteSupportLevel]) != nil) + { + if ([deviceSupportLevel intValue] > (int)supportLevel) + { + supportLevel = [deviceSupportLevel intValue]; + } + } + } + + return (supportLevel); } #pragma mark -- PUBLIC: Interface / API -- - (BOOL)startRemoteControl:(HIDRemoteMode)hidRemoteMode { - if ((_mode == kHIDRemoteModeNone) && (hidRemoteMode != kHIDRemoteModeNone)) - { - kern_return_t kernReturn; - CFMutableDictionaryRef matchDict=NULL; - io_service_t rootService; - - do - { - // Get IOKit master port - kernReturn = IOMasterPort(bootstrap_port, &_masterPort); - if ((kernReturn!=kIOReturnSuccess) || (_masterPort==0)) { break; } - - // Setup notification port - _notifyPort = IONotificationPortCreate(_masterPort); - - if ((_notifyRLSource = IONotificationPortGetRunLoopSource(_notifyPort)) != NULL) - { - CFRunLoopAddSource( CFRunLoopGetCurrent(), - _notifyRLSource, - kCFRunLoopCommonModes); - } - else - { - break; - } - - // Setup SecureInput notification - if ((hidRemoteMode == kHIDRemoteModeExclusive) || (hidRemoteMode == kHIDRemoteModeExclusiveAuto)) - { - if ((rootService = IORegistryEntryFromPath(_masterPort, kIOServicePlane ":/")) != 0) - { - kernReturn = IOServiceAddInterestNotification( _notifyPort, - rootService, - kIOBusyInterest, - SecureInputNotificationCallback, - (void *)self, - &_secureInputNotification); - if (kernReturn != kIOReturnSuccess) { break; } - - [self _updateSessionInformation]; - } - else - { - break; - } - } - - // Setup notification matching dict - matchDict = IOServiceMatching(kIOHIDDeviceKey); - CFRetain(matchDict); - - // Actually add notification - kernReturn = IOServiceAddMatchingNotification( _notifyPort, - kIOFirstMatchNotification, - matchDict, // one reference count consumed by this call - ServiceMatchingCallback, - (void *) self, - &_matchingServicesIterator); - if (kernReturn != kIOReturnSuccess) { break; } - - // Setup serviceAttribMap - _serviceAttribMap = [[NSMutableDictionary alloc] init]; - if (_serviceAttribMap==nil) { break; } - - // Phew .. everything went well! - _mode = hidRemoteMode; - CFRelease(matchDict); - - [self _serviceMatching:_matchingServicesIterator]; - - [self _postStatusWithAction:kHIDRemoteDNStatusActionStart]; - - return (YES); - - }while(0); - - // An error occured. Do necessary clean up. - if (matchDict!=NULL) - { - CFRelease(matchDict); - matchDict = NULL; - } - - [self stopRemoteControl]; - } - - return (NO); + if ((_mode == kHIDRemoteModeNone) && (hidRemoteMode != kHIDRemoteModeNone)) + { + kern_return_t kernReturn; + CFMutableDictionaryRef matchDict=NULL; + io_service_t rootService; + + do + { + // Get IOKit master port + kernReturn = IOMasterPort(bootstrap_port, &_masterPort); + if ((kernReturn!=kIOReturnSuccess) || (_masterPort==0)) { break; } + + // Setup notification port + _notifyPort = IONotificationPortCreate(_masterPort); + + if ((_notifyRLSource = IONotificationPortGetRunLoopSource(_notifyPort)) != NULL) + { + CFRunLoopAddSource( CFRunLoopGetCurrent(), + _notifyRLSource, + kCFRunLoopCommonModes); + } + else + { + break; + } + + // Setup SecureInput notification + if ((hidRemoteMode == kHIDRemoteModeExclusive) || (hidRemoteMode == kHIDRemoteModeExclusiveAuto)) + { + if ((rootService = IORegistryEntryFromPath(_masterPort, kIOServicePlane ":/")) != 0) + { + kernReturn = IOServiceAddInterestNotification( _notifyPort, + rootService, + kIOBusyInterest, + SecureInputNotificationCallback, + (void *)self, + &_secureInputNotification); + if (kernReturn != kIOReturnSuccess) { break; } + + [self _updateSessionInformation]; + } + else + { + break; + } + } + + // Setup notification matching dict + matchDict = IOServiceMatching(kIOHIDDeviceKey); + CFRetain(matchDict); + + // Actually add notification + kernReturn = IOServiceAddMatchingNotification( _notifyPort, + kIOFirstMatchNotification, + matchDict, // one reference count consumed by this call + ServiceMatchingCallback, + (void *) self, + &_matchingServicesIterator); + if (kernReturn != kIOReturnSuccess) { break; } + + // Setup serviceAttribMap + _serviceAttribMap = [[NSMutableDictionary alloc] init]; + if (_serviceAttribMap==nil) { break; } + + // Phew .. everything went well! + _mode = hidRemoteMode; + CFRelease(matchDict); + + [self _serviceMatching:_matchingServicesIterator]; + + [self _postStatusWithAction:kHIDRemoteDNStatusActionStart]; + + return (YES); + + }while(0); + + // An error occured. Do necessary clean up. + if (matchDict!=NULL) + { + CFRelease(matchDict); + matchDict = NULL; + } + + [self stopRemoteControl]; + } + + return (NO); } - (void)stopRemoteControl { - UInt32 serviceCount = 0; - - _autoRecover = NO; - _isStopping = YES; - - if (_autoRecoveryTimer!=nil) - { - [_autoRecoveryTimer invalidate]; - [_autoRecoveryTimer release]; - _autoRecoveryTimer = nil; - } - - if (_serviceAttribMap!=nil) - { - NSDictionary *cloneDict = [[NSDictionary alloc] initWithDictionary:_serviceAttribMap]; - - if (cloneDict!=nil) - { - NSEnumerator *mapKeyEnum = [cloneDict keyEnumerator]; - NSNumber *serviceValue; - - while ((serviceValue = [mapKeyEnum nextObject]) != nil) - { - [self _destructService:(io_object_t)[serviceValue unsignedIntValue]]; - serviceCount++; - }; - - [cloneDict release]; - cloneDict = nil; - } - - [_serviceAttribMap release]; - _serviceAttribMap = nil; - } - - if (_matchingServicesIterator!=0) - { - IOObjectRelease((io_object_t) _matchingServicesIterator); - _matchingServicesIterator = 0; - } - - if (_secureInputNotification!=0) - { - IOObjectRelease((io_object_t) _secureInputNotification); - _secureInputNotification = 0; - } - - if (_notifyRLSource!=NULL) - { - CFRunLoopSourceInvalidate(_notifyRLSource); - _notifyRLSource = NULL; - } - - if (_notifyPort!=NULL) - { - IONotificationPortDestroy(_notifyPort); - _notifyPort = NULL; - } - - if (_masterPort!=0) - { - mach_port_deallocate(mach_task_self(), _masterPort); - _masterPort = 0; - } - - if (_returnToPID!=nil) - { - [_returnToPID release]; - _returnToPID = nil; - } - - if (_mode!=kHIDRemoteModeNone) - { - // Post status - [self _postStatusWithAction:kHIDRemoteDNStatusActionStop]; - - if (_sendStatusNotifications) - { - // In case we were n |