diff options
author | maestrodd <maestrodd@svn> | 2009-10-23 14:54:46 +0000 |
---|---|---|
committer | maestrodd <maestrodd@svn> | 2009-10-23 14:54:46 +0000 |
commit | bd908a182433ce7cc2678f9e51c7884d66f6d1e4 (patch) | |
tree | dbdf1f2c49c813e4969e64b62438824c53df65af /tools/EventClients | |
parent | e29c9df6d5228423fcdbad090ef64277e2eb146d (diff) |
[OSX] XBMCHelper: updated to new HIDRemoteSDK
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23928 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'tools/EventClients')
-rw-r--r-- | tools/EventClients/Clients/OSXRemote/HIDRemote.h | 29 | ||||
-rw-r--r-- | tools/EventClients/Clients/OSXRemote/HIDRemote.m | 148 |
2 files changed, 126 insertions, 51 deletions
diff --git a/tools/EventClients/Clients/OSXRemote/HIDRemote.h b/tools/EventClients/Clients/OSXRemote/HIDRemote.h index d2a7cf8796..b42f60b712 100644 --- a/tools/EventClients/Clients/OSXRemote/HIDRemote.h +++ b/tools/EventClients/Clients/OSXRemote/HIDRemote.h @@ -5,9 +5,12 @@ // Created by Felix Schwarz on 06.04.07. // Copyright 2007-2009 IOSPIRIT GmbH. All rights reserved. // +// The latest version of this class is available at +// http://www.iospirit.com/developers/hidremote/ +// // ** LICENSE ************************************************************************* // -// Copyright (c) 2007-2009 IOSPIRIT GmbH +// Copyright (c) 2007-2009 IOSPIRIT GmbH (http://www.iospirit.com/) // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, @@ -37,6 +40,18 @@ // // ************************************************************************************ + + +// ************************************************************************************ +// ********************************** DOCUMENTATION *********************************** +// ************************************************************************************ +// +// - a reference is available at http://www.iospirit.com/developers/hidremote/reference/ +// - for a guide, please see http://www.iospirit.com/developers/hidremote/guide/ +// +// ************************************************************************************ + + #import <Cocoa/Cocoa.h> #include <Carbon/Carbon.h> @@ -131,7 +146,8 @@ typedef enum - (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 methods below. +// ### 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 // @@ -298,7 +314,11 @@ typedef enum /* DESCRIPTION - Determine the number of remote controls HIDRemote has currently opened. This is usually 1 on current systems. + Determine the number of remote controls/receivers HIDRemote has currently opened in the mode supplied to + -startRemoteControl: + + RESULT + The number of remote controls/receivers HIDRemote has currently opened. Zero if none could be found or opened. */ - (unsigned)activeRemoteControlCount; @@ -308,7 +328,7 @@ typedef enum ID change notifications by implementing the (optional) -hidRemote:remoteIDChangedOldID:newID: selector. RESULT - Returns the ID of the last seen remote. Returns -1, if the ID is unknown. + The ID of the last seen remote. Returns -1, if the ID is unknown. */ - (SInt32)lastSeenRemoteControlID; @@ -476,6 +496,7 @@ extern NSString *kHIDRemoteDNStatusActionKey; extern NSString *kHIDRemoteDNStatusActionStart; extern NSString *kHIDRemoteDNStatusActionStop; extern NSString *kHIDRemoteDNStatusActionUpdate; +extern NSString *kHIDRemoteDNStatusActionNoNeed; #pragma mark -- Driver compatibility flags -- typedef enum diff --git a/tools/EventClients/Clients/OSXRemote/HIDRemote.m b/tools/EventClients/Clients/OSXRemote/HIDRemote.m index f8e9b9f953..55ea52a776 100644 --- a/tools/EventClients/Clients/OSXRemote/HIDRemote.m +++ b/tools/EventClients/Clients/OSXRemote/HIDRemote.m @@ -5,9 +5,12 @@ // Created by Felix Schwarz on 06.04.07. // Copyright 2007-2009 IOSPIRIT GmbH. All rights reserved. // +// The latest version of this class is available at +// http://www.iospirit.com/developers/hidremote/ +// // ** LICENSE ************************************************************************* // -// Copyright (c) 2007-2009 IOSPIRIT GmbH +// Copyright (c) 2007-2009 IOSPIRIT GmbH (http://www.iospirit.com/) // All rights reserved. // // Redistribution and use in source and binary forms, with or without modification, @@ -37,6 +40,18 @@ // // ************************************************************************************ + + +// ************************************************************************************ +// ********************************** DOCUMENTATION *********************************** +// ************************************************************************************ +// +// - a reference is available at http://www.iospirit.com/developers/hidremote/reference/ +// - for a guide, please see http://www.iospirit.com/developers/hidremote/guide/ +// +// ************************************************************************************ + + #import "HIDRemote.h" // Callback Prototypes @@ -549,10 +564,23 @@ static HIDRemote *sHIDRemote = nil; [_returnToPID release]; [self startRemoteControl:restartInMode]; - - _returnToPID = [[[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey] retain]; + + if (restartInMode != kHIDRemoteModeShared) + { + _returnToPID = [[[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey] retain]; + } } } + else + { + NSNumber *cacheReturnPID = _returnToPID; + + _returnToPID = [[[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey] retain]; + [self _postStatusWithAction:kHIDRemoteDNStatusActionNoNeed]; + [_returnToPID release]; + + _returnToPID = cacheReturnPID; + } } } @@ -564,70 +592,94 @@ static HIDRemote *sHIDRemote = nil; if ((action = [[notification userInfo] objectForKey:kHIDRemoteDNStatusActionKey]) != nil) { - if (_mode==kHIDRemoteModeExclusive) + if ((_mode == kHIDRemoteModeNone) && _waitForReturnByPID) { - if ([action isEqual:kHIDRemoteDNStatusActionStart]) + NSNumber *pidNumber, *returnToPIDNumber; + + if ((pidNumber = [[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey]) != nil) { - NSNumber *originPID = [[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey]; + returnToPIDNumber = [[notification userInfo] objectForKey:kHIDRemoteDNStatusReturnToPIDKey]; - if ([originPID intValue] != getpid()) + if ([action isEqual:kHIDRemoteDNStatusActionStart]) { - if (([self delegate] != nil) && - ([[self delegate] respondsToSelector:@selector(hidRemote:lendExclusiveLockToApplicationWithInfo:)])) + if ([pidNumber isEqual:_waitForReturnByPID]) { - if ([[self delegate] hidRemote:self lendExclusiveLockToApplicationWithInfo:[notification userInfo]]) + NSNumber *startMode; + + if ((startMode = [[notification userInfo] objectForKey:kHIDRemoteDNStatusModeKey]) != nil) + { + if ([startMode intValue] == kHIDRemoteModeShared) + { + returnToPIDNumber = [NSNumber numberWithInt:getpid()]; + action = kHIDRemoteDNStatusActionNoNeed; + } + } + } + } + + if (returnToPIDNumber != nil) + { + if ([action isEqual:kHIDRemoteDNStatusActionStop] || [action isEqual:kHIDRemoteDNStatusActionNoNeed]) + { + if ([pidNumber isEqual:_waitForReturnByPID] && ([returnToPIDNumber intValue] == getpid())) { [_waitForReturnByPID release]; - _waitForReturnByPID = [originPID retain]; - - if (_waitForReturnByPID != nil) + _waitForReturnByPID = nil; + + if (([self delegate] != nil) && + ([[self delegate] respondsToSelector:@selector(hidRemote:exclusiveLockReleasedByApplicationWithInfo:)])) { - BOOL cachedStatusSecureEventInputWorkAroundEnabled; - - // Workaround for what seems to be a missing lock on the counter in the EnableSecureEventInput() / DisableSecureEventInput() API - cachedStatusSecureEventInputWorkAroundEnabled = _statusSecureEventInputWorkAroundEnabled; - _statusSecureEventInputWorkAroundEnabled = NO; - - [self stopRemoteControl]; - - _statusSecureEventInputWorkAroundEnabled = cachedStatusSecureEventInputWorkAroundEnabled; - - [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kHIDRemoteDNHIDRemoteRetry - object:[NSString stringWithFormat:@"%d", [_waitForReturnByPID intValue]] - userInfo:[NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithUnsignedInt:(unsigned int)getpid()], kHIDRemoteDNStatusPIDKey, - [[NSBundle mainBundle] bundleIdentifier], (NSString *)kCFBundleIdentifierKey, - nil] - deliverImmediately:YES]; + [[self delegate] hidRemote:self exclusiveLockReleasedByApplicationWithInfo:[notification userInfo]]; + } + else + { + [self startRemoteControl:kHIDRemoteModeExclusive]; } } } } } } - - if ((_mode == kHIDRemoteModeNone) && _waitForReturnByPID) + + if (_mode==kHIDRemoteModeExclusive) { - if ([action isEqual:kHIDRemoteDNStatusActionStop]) + if ([action isEqual:kHIDRemoteDNStatusActionStart]) { - NSNumber *pidNumber, *returnToPIDNumber; - - if (((pidNumber = [[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey]) != nil) && - ((returnToPIDNumber = [[notification userInfo] objectForKey:kHIDRemoteDNStatusReturnToPIDKey]) != nil)) + NSNumber *originPID = [[notification userInfo] objectForKey:kHIDRemoteDNStatusPIDKey]; + BOOL lendLock = YES; + + if ([originPID intValue] != getpid()) { - if ([pidNumber isEqual:_waitForReturnByPID] && ([returnToPIDNumber intValue] == getpid())) + if (([self delegate] != nil) && + ([[self delegate] respondsToSelector:@selector(hidRemote:lendExclusiveLockToApplicationWithInfo:)])) { - [_waitForReturnByPID release]; - _waitForReturnByPID = nil; + lendLock = [[self delegate] hidRemote:self lendExclusiveLockToApplicationWithInfo:[notification userInfo]]; + } - if (([self delegate] != nil) && - ([[self delegate] respondsToSelector:@selector(hidRemote:exclusiveLockReleasedByApplicationWithInfo:)])) - { - [[self delegate] hidRemote:self exclusiveLockReleasedByApplicationWithInfo:[notification userInfo]]; - } - else + if (lendLock) + { + [_waitForReturnByPID release]; + _waitForReturnByPID = [originPID retain]; + + if (_waitForReturnByPID != nil) { - [self startRemoteControl:kHIDRemoteModeExclusive]; + BOOL cachedStatusSecureEventInputWorkAroundEnabled; + + // Workaround for what seems to be a missing lock on the counter in the EnableSecureEventInput() / DisableSecureEventInput() API + cachedStatusSecureEventInputWorkAroundEnabled = _statusSecureEventInputWorkAroundEnabled; + _statusSecureEventInputWorkAroundEnabled = NO; + + [self stopRemoteControl]; + + _statusSecureEventInputWorkAroundEnabled = cachedStatusSecureEventInputWorkAroundEnabled; + + [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kHIDRemoteDNHIDRemoteRetry + object:[NSString stringWithFormat:@"%d", [_waitForReturnByPID intValue]] + userInfo:[NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithUnsignedInt:(unsigned int)getpid()], kHIDRemoteDNStatusPIDKey, + [[NSBundle mainBundle] bundleIdentifier], (NSString *)kCFBundleIdentifierKey, + nil] + deliverImmediately:YES]; } } } @@ -1542,3 +1594,5 @@ NSString *kHIDRemoteDNStatusReturnToPIDKey = @"ReturnToPID"; NSString *kHIDRemoteDNStatusActionStart = @"start"; NSString *kHIDRemoteDNStatusActionStop = @"stop"; NSString *kHIDRemoteDNStatusActionUpdate = @"update"; +NSString *kHIDRemoteDNStatusActionNoNeed = @"noneed"; + |