summaryrefslogtreecommitdiff
path: root/apple_remote
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-02-20 14:01:08 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-02-21 09:14:14 +0100
commit6333dcf6f18c5d5a03e5daa267f89c06a528b698 (patch)
treee5d5246bd595e0a647b6cac436aba5d4f4351259 /apple_remote
parent07f24df0e8dbc035f2f9a24c12879848a1f318f1 (diff)
loplugin:indentation (macOS)
* Some .m/.mm files that still contained tabs instead of spaces have been cleaned up with Emacs' untabify (and apple_remote/source/HIDRemoteControlDevice.m needed further manual adaptions): apple_remote/source/GlobalKeyboardDevice.m apple_remote/source/HIDRemoteControlDevice.m apple_remote/source/KeyspanFrontRowControl.m apple_remote/source/RemoteControl.m vcl/osx/a11yrolehelper.mm * Some of the changes predate 0626e66d761de18f62e4d00d427903032da9d517 "Avoid loplugin:indentation after preproc conditional inclusion lines" and would likely have no longer been flagged since. Change-Id: Ibf5faffa743c7f79b36109d9879eb79d63c8c40f Reviewed-on: https://gerrit.libreoffice.org/68090 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'apple_remote')
-rw-r--r--apple_remote/source/GlobalKeyboardDevice.m232
-rw-r--r--apple_remote/source/HIDRemoteControlDevice.m658
-rw-r--r--apple_remote/source/KeyspanFrontRowControl.m66
-rw-r--r--apple_remote/source/RemoteControl.m6
4 files changed, 481 insertions, 481 deletions
diff --git a/apple_remote/source/GlobalKeyboardDevice.m b/apple_remote/source/GlobalKeyboardDevice.m
index c9e77097f9c1..cbd78f5b011c 100644
--- a/apple_remote/source/GlobalKeyboardDevice.m
+++ b/apple_remote/source/GlobalKeyboardDevice.m
@@ -64,166 +64,166 @@ static OSStatus hotKeyEventHandler(EventHandlerCallRef, EventRef, void*);
@implementation GlobalKeyboardDevice
- (id) initWithDelegate: (id) _remoteControlDelegate {
- if ( (self = [super initWithDelegate: _remoteControlDelegate]) ) {
- hotKeyRemoteEventMapping = [[NSMutableDictionary alloc] init];
-
- unsigned int modifiers = cmdKey + shiftKey /*+ optionKey*/ + controlKey;
-
- [self mapRemoteButton:kRemoteButtonPlus defaultKeycode:F1 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonMinus defaultKeycode:F2 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonPlay defaultKeycode:F3 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonLeft defaultKeycode:F4 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonRight defaultKeycode:F5 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonMenu defaultKeycode:F6 defaultModifiers:modifiers];
- [self mapRemoteButton:kRemoteButtonPlay_Hold defaultKeycode:F7 defaultModifiers:modifiers];
- }
- return self;
+ if ( (self = [super initWithDelegate: _remoteControlDelegate]) ) {
+ hotKeyRemoteEventMapping = [[NSMutableDictionary alloc] init];
+
+ unsigned int modifiers = cmdKey + shiftKey /*+ optionKey*/ + controlKey;
+
+ [self mapRemoteButton:kRemoteButtonPlus defaultKeycode:F1 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonMinus defaultKeycode:F2 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonPlay defaultKeycode:F3 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonLeft defaultKeycode:F4 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonRight defaultKeycode:F5 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonMenu defaultKeycode:F6 defaultModifiers:modifiers];
+ [self mapRemoteButton:kRemoteButtonPlay_Hold defaultKeycode:F7 defaultModifiers:modifiers];
+ }
+ return self;
}
- (void) dealloc {
- [hotKeyRemoteEventMapping release];
- [super dealloc];
+ [hotKeyRemoteEventMapping release];
+ [super dealloc];
}
- (void) mapRemoteButton: (RemoteControlEventIdentifier) remoteButtonIdentifier defaultKeycode: (unsigned int) defaultKeycode defaultModifiers: (unsigned int) defaultModifiers {
- NSString* defaultsKey = NULL;
-
- switch(remoteButtonIdentifier) {
- case kRemoteButtonPlus:
- defaultsKey = @"plus";
- break;
- case kRemoteButtonMinus:
- defaultsKey = @"minus";
- break;
- case kRemoteButtonMenu:
- defaultsKey = @"menu";
- break;
- case kRemoteButtonPlay:
- defaultsKey = @"play";
- break;
- case kRemoteButtonRight:
- defaultsKey = @"right";
- break;
- case kRemoteButtonLeft:
- defaultsKey = @"left";
- break;
- case kRemoteButtonPlay_Hold:
- defaultsKey = @"playhold";
- break;
- default:
+ NSString* defaultsKey = NULL;
+
+ switch(remoteButtonIdentifier) {
+ case kRemoteButtonPlus:
+ defaultsKey = @"plus";
+ break;
+ case kRemoteButtonMinus:
+ defaultsKey = @"minus";
+ break;
+ case kRemoteButtonMenu:
+ defaultsKey = @"menu";
+ break;
+ case kRemoteButtonPlay:
+ defaultsKey = @"play";
+ break;
+ case kRemoteButtonRight:
+ defaultsKey = @"right";
+ break;
+ case kRemoteButtonLeft:
+ defaultsKey = @"left";
+ break;
+ case kRemoteButtonPlay_Hold:
+ defaultsKey = @"playhold";
+ break;
+ default:
#ifdef DEBUG
- NSLog( @"Apple Remote: Unknown global keyboard defaults key for button identifier %d", remoteButtonIdentifier);
+ NSLog( @"Apple Remote: Unknown global keyboard defaults key for button identifier %d", remoteButtonIdentifier);
#endif
break;
- }
+ }
- NSNumber* modifiersCfg = [[NSUserDefaults standardUserDefaults] objectForKey: [NSString stringWithFormat: @"mac.remotecontrols.GlobalKeyboardDevice.%@_modifiers", defaultsKey]];
- NSNumber* keycodeCfg = [[NSUserDefaults standardUserDefaults] objectForKey: [NSString stringWithFormat: @"mac.remotecontrols.GlobalKeyboardDevice.%@_keycode", defaultsKey]];
+ NSNumber* modifiersCfg = [[NSUserDefaults standardUserDefaults] objectForKey: [NSString stringWithFormat: @"mac.remotecontrols.GlobalKeyboardDevice.%@_modifiers", defaultsKey]];
+ NSNumber* keycodeCfg = [[NSUserDefaults standardUserDefaults] objectForKey: [NSString stringWithFormat: @"mac.remotecontrols.GlobalKeyboardDevice.%@_keycode", defaultsKey]];
- unsigned int modifiers = defaultModifiers;
- if (modifiersCfg) modifiers = [modifiersCfg unsignedIntValue];
+ unsigned int modifiers = defaultModifiers;
+ if (modifiersCfg) modifiers = [modifiersCfg unsignedIntValue];
- unsigned int keycode = defaultKeycode;
- if (keycodeCfg) keycode = [keycodeCfg unsignedIntValue];
+ unsigned int keycode = defaultKeycode;
+ if (keycodeCfg) keycode = [keycodeCfg unsignedIntValue];
[self registerHotKeyCode: keycode modifiers: modifiers remoteEventIdentifier: remoteButtonIdentifier];
}
- (void) setListeningToRemote: (BOOL) value {
- if (value == [self isListeningToRemote]) return;
- if (value) {
- [self startListening: self];
- } else {
- [self stopListening: self];
- }
+ if (value == [self isListeningToRemote]) return;
+ if (value) {
+ [self startListening: self];
+ } else {
+ [self stopListening: self];
+ }
}
- (BOOL) isListeningToRemote {
- return (eventHandlerRef!=NULL);
+ return (eventHandlerRef!=NULL);
}
- (void) startListening: (id) sender {
- if (eventHandlerRef) return;
+ if (eventHandlerRef) return;
- EventTypeSpec const eventSpec[2] = {
- { kEventClassKeyboard, kEventHotKeyPressed },
- { kEventClassKeyboard, kEventHotKeyReleased }
- };
+ EventTypeSpec const eventSpec[2] = {
+ { kEventClassKeyboard, kEventHotKeyPressed },
+ { kEventClassKeyboard, kEventHotKeyReleased }
+ };
- InstallEventHandler( GetEventDispatcherTarget(),
- (EventHandlerProcPtr)hotKeyEventHandler,
- 2, eventSpec, self, &eventHandlerRef);
+ InstallEventHandler( GetEventDispatcherTarget(),
+ (EventHandlerProcPtr)hotKeyEventHandler,
+ 2, eventSpec, self, &eventHandlerRef);
(void)sender;
}
- (void) stopListening: (id) sender {
- RemoveEventHandler(eventHandlerRef);
- eventHandlerRef = NULL;
+ RemoveEventHandler(eventHandlerRef);
+ eventHandlerRef = NULL;
(void)sender;
}
- (BOOL) sendsEventForButtonIdentifier: (RemoteControlEventIdentifier) identifier {
- NSEnumerator* values = [hotKeyRemoteEventMapping objectEnumerator];
- NSNumber* remoteIdentifier;
- while( (remoteIdentifier = [values nextObject]) ) {
- if ([remoteIdentifier unsignedIntValue] == identifier) return YES;
- }
- return NO;
+ NSEnumerator* values = [hotKeyRemoteEventMapping objectEnumerator];
+ NSNumber* remoteIdentifier;
+ while( (remoteIdentifier = [values nextObject]) ) {
+ if ([remoteIdentifier unsignedIntValue] == identifier) return YES;
+ }
+ return NO;
}
+ (const char*) remoteControlDeviceName {
- return "Keyboard";
+ return "Keyboard";
}
- (BOOL)registerHotKeyCode: (unsigned int) keycode modifiers: (unsigned int) modifiers remoteEventIdentifier: (RemoteControlEventIdentifier) identifier {
- OSStatus err;
- EventHotKeyID hotKeyID;
- EventHotKeyRef carbonHotKey;
+ OSStatus err;
+ EventHotKeyID hotKeyID;
+ EventHotKeyRef carbonHotKey;
- hotKeyID.signature = 'PTHk';
- hotKeyID.id = (long)keycode;
+ hotKeyID.signature = 'PTHk';
+ hotKeyID.id = (long)keycode;
- err = RegisterEventHotKey(keycode, modifiers, hotKeyID, GetEventDispatcherTarget(), 0, &carbonHotKey );
+ err = RegisterEventHotKey(keycode, modifiers, hotKeyID, GetEventDispatcherTarget(), 0, &carbonHotKey );
- if( err )
- return NO;
+ if( err )
+ return NO;
- [hotKeyRemoteEventMapping setObject: [NSNumber numberWithInt:identifier] forKey: [NSNumber numberWithUnsignedInt: hotKeyID.id]];
+ [hotKeyRemoteEventMapping setObject: [NSNumber numberWithInt:identifier] forKey: [NSNumber numberWithUnsignedInt: hotKeyID.id]];
- return YES;
+ return YES;
}
/*
- (void)unregisterHotKey: (PTHotKey*)hotKey
{
- OSStatus err;
- EventHotKeyRef carbonHotKey;
- NSValue* key;
+ OSStatus err;
+ EventHotKeyRef carbonHotKey;
+ NSValue* key;
- if( [[self allHotKeys] containsObject: hotKey] == NO )
- return;
+ if( [[self allHotKeys] containsObject: hotKey] == NO )
+ return;
- carbonHotKey = [self _carbonHotKeyForHotKey: hotKey];
- NSAssert( carbonHotKey != nil, @"" );
+ carbonHotKey = [self _carbonHotKeyForHotKey: hotKey];
+ NSAssert( carbonHotKey != nil, @"" );
- err = UnregisterEventHotKey( carbonHotKey );
- //Watch as we ignore 'err':
+ err = UnregisterEventHotKey( carbonHotKey );
+ //Watch as we ignore 'err':
- key = [NSValue valueWithPointer: carbonHotKey];
- [mHotKeys removeObjectForKey: key];
+ key = [NSValue valueWithPointer: carbonHotKey];
+ [mHotKeys removeObjectForKey: key];
- [self _updateEventHandler];
+ [self _updateEventHandler];
- //See that? Completely ignored
+ //See that? Completely ignored
}
*/
- (RemoteControlEventIdentifier) remoteControlEventIdentifierForID: (unsigned int) id {
- NSNumber* remoteEventIdentifier = [hotKeyRemoteEventMapping objectForKey:[NSNumber numberWithUnsignedInt: id]];
- return [remoteEventIdentifier unsignedIntValue];
+ NSNumber* remoteEventIdentifier = [hotKeyRemoteEventMapping objectForKey:[NSNumber numberWithUnsignedInt: id]];
+ return [remoteEventIdentifier unsignedIntValue];
}
- (void) sendRemoteButtonEvent: (RemoteControlEventIdentifier) event pressedDown: (BOOL) pressedDown {
- [delegate sendRemoteButtonEvent: event pressedDown: pressedDown remoteControl:self];
+ [delegate sendRemoteButtonEvent: event pressedDown: pressedDown remoteControl:self];
}
static RemoteControlEventIdentifier lastEvent;
@@ -232,23 +232,23 @@ static RemoteControlEventIdentifier lastEvent;
static OSStatus hotKeyEventHandler(EventHandlerCallRef inHandlerRef, EventRef inEvent, void* userData )
{
(void)inHandlerRef;
- GlobalKeyboardDevice* keyboardDevice = (GlobalKeyboardDevice*) userData;
- EventHotKeyID hkCom;
- GetEventParameter(inEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
-
- RemoteControlEventIdentifier identifier = [keyboardDevice remoteControlEventIdentifierForID:hkCom.id];
- if (identifier == 0) return noErr;
-
- BOOL pressedDown = YES;
- if (identifier != lastEvent) {
- lastEvent = identifier;
- } else {
- lastEvent = 0;
- pressedDown = NO;
- }
- [keyboardDevice sendRemoteButtonEvent: identifier pressedDown: pressedDown];
-
- return noErr;
+ GlobalKeyboardDevice* keyboardDevice = (GlobalKeyboardDevice*) userData;
+ EventHotKeyID hkCom;
+ GetEventParameter(inEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom);
+
+ RemoteControlEventIdentifier identifier = [keyboardDevice remoteControlEventIdentifierForID:hkCom.id];
+ if (identifier == 0) return noErr;
+
+ BOOL pressedDown = YES;
+ if (identifier != lastEvent) {
+ lastEvent = identifier;
+ } else {
+ lastEvent = 0;
+ pressedDown = NO;
+ }
+ [keyboardDevice sendRemoteButtonEvent: identifier pressedDown: pressedDown];
+
+ return noErr;
}
@end
diff --git a/apple_remote/source/HIDRemoteControlDevice.m b/apple_remote/source/HIDRemoteControlDevice.m
index d7aaeaecb4e7..58f936d180cb 100644
--- a/apple_remote/source/HIDRemoteControlDevice.m
+++ b/apple_remote/source/HIDRemoteControlDevice.m
@@ -58,52 +58,52 @@
@implementation HIDRemoteControlDevice
+ (const char*) remoteControlDeviceName {
- return "";
+ return "";
}
+ (BOOL) isRemoteAvailable {
- io_object_t hidDevice = [self findRemoteDevice];
- if (hidDevice != 0) {
- IOObjectRelease(hidDevice);
- return YES;
- } else {
- return NO;
- }
+ io_object_t hidDevice = [self findRemoteDevice];
+ if (hidDevice != 0) {
+ IOObjectRelease(hidDevice);
+ return YES;
+ } else {
+ return NO;
+ }
}
- (id) initWithDelegate: (id) _remoteControlDelegate {
- if ([[self class] isRemoteAvailable] == NO) return nil;
+ if ([[self class] isRemoteAvailable] == NO) return nil;
- if ( (self = [super initWithDelegate: _remoteControlDelegate]) ) {
- openInExclusiveMode = YES;
- queue = NULL;
- hidDeviceInterface = NULL;
- cookieToButtonMapping = [[NSMutableDictionary alloc] init];
+ if ( (self = [super initWithDelegate: _remoteControlDelegate]) ) {
+ openInExclusiveMode = YES;
+ queue = NULL;
+ hidDeviceInterface = NULL;
+ cookieToButtonMapping = [[NSMutableDictionary alloc] init];
- [self setCookieMappingInDictionary: cookieToButtonMapping];
+ [self setCookieMappingInDictionary: cookieToButtonMapping];
- NSEnumerator* enumerator = [cookieToButtonMapping objectEnumerator];
- NSNumber* identifier;
- supportedButtonEvents = 0;
- while( (identifier = [enumerator nextObject]) ) {
- supportedButtonEvents |= [identifier intValue];
- }
+ NSEnumerator* enumerator = [cookieToButtonMapping objectEnumerator];
+ NSNumber* identifier;
+ supportedButtonEvents = 0;
+ while( (identifier = [enumerator nextObject]) ) {
+ supportedButtonEvents |= [identifier intValue];
+ }
- fixSecureEventInputBug = [[NSUserDefaults standardUserDefaults] boolForKey: @"remoteControlWrapperFixSecureEventInputBug"];
- }
+ fixSecureEventInputBug = [[NSUserDefaults standardUserDefaults] boolForKey: @"remoteControlWrapperFixSecureEventInputBug"];
+ }
- return self;
+ return self;
}
- (void) dealloc {
- [self removeNotificationObserver];
- [self stopListening:self];
- [cookieToButtonMapping release];
- [super dealloc];
+ [self removeNotificationObserver];
+ [self stopListening:self];
+ [cookieToButtonMapping release];
+ [super dealloc];
}
- (void) sendRemoteButtonEvent: (RemoteControlEventIdentifier) event pressedDown: (BOOL) pressedDown {
- [delegate sendRemoteButtonEvent: event pressedDown: pressedDown remoteControl:self];
+ [delegate sendRemoteButtonEvent: event pressedDown: pressedDown remoteControl:self];
}
- (void) setCookieMappingInDictionary: (NSMutableDictionary*) cookieToButtonMap {
@@ -111,140 +111,140 @@
}
- (int) remoteIdSwitchCookie {
- return 0;
+ return 0;
}
- (BOOL) sendsEventForButtonIdentifier: (RemoteControlEventIdentifier) identifier {
- return (supportedButtonEvents & identifier) == identifier;
+ return (supportedButtonEvents & identifier) == identifier;
}
- (BOOL) isListeningToRemote {
- return (hidDeviceInterface != NULL && allCookies != NULL && queue != NULL);
+ return (hidDeviceInterface != NULL && allCookies != NULL && queue != NULL);
}
- (void) setListeningToRemote: (BOOL) value {
- if (value == NO) {
- [self stopListening:self];
- } else {
- [self startListening:self];
- }
+ if (value == NO) {
+ [self stopListening:self];
+ } else {
+ [self startListening:self];
+ }
}
- (BOOL) isOpenInExclusiveMode {
- return openInExclusiveMode;
+ return openInExclusiveMode;
}
- (void) setOpenInExclusiveMode: (BOOL) value {
- openInExclusiveMode = value;
+ openInExclusiveMode = value;
}
- (BOOL) processesBacklog {
- return processesBacklog;
+ return processesBacklog;
}
- (void) setProcessesBacklog: (BOOL) value {
- processesBacklog = value;
+ processesBacklog = value;
}
- (void) startListening: (id) sender {
(void)sender;
- if ([self isListeningToRemote]) return;
+ if ([self isListeningToRemote]) return;
- // 4th July 2007
+ // 4th July 2007
- // A security update in february of 2007 introduced an odd behavior.
- // Whenever SecureEventInput is activated or deactivated the exclusive access
- // to the remote control device is lost. This leads to very strange behavior where
- // a press on the Menu button activates FrontRow while your app still gets the event.
- // A great number of people have complained about this.
+ // A security update in february of 2007 introduced an odd behavior.
+ // Whenever SecureEventInput is activated or deactivated the exclusive access
+ // to the remote control device is lost. This leads to very strange behavior where
+ // a press on the Menu button activates FrontRow while your app still gets the event.
+ // A great number of people have complained about this.
- // Enabling the SecureEventInput and keeping it enabled does the trick.
+ // Enabling the SecureEventInput and keeping it enabled does the trick.
- // I'm pretty sure this is a kind of bug at Apple and I'm in contact with the responsible
- // Apple Engineer. This solution is not a perfect one - I know.
- // One of the side effects is that applications that listen for special global keyboard shortcuts (like Quicksilver)
- // may get into problems as they no longer get the events.
- // As there is no official Apple Remote API from Apple I also failed to open a technical incident on this.
+ // I'm pretty sure this is a kind of bug at Apple and I'm in contact with the responsible
+ // Apple Engineer. This solution is not a perfect one - I know.
+ // One of the side effects is that applications that listen for special global keyboard shortcuts (like Quicksilver)
+ // may get into problems as they no longer get the events.
+ // As there is no official Apple Remote API from Apple I also failed to open a technical incident on this.
- // Note that there is a corresponding DisableSecureEventInput in the stopListening method below.
+ // Note that there is a corresponding DisableSecureEventInput in the stopListening method below.
- if ([self isOpenInExclusiveMode] && fixSecureEventInputBug) EnableSecureEventInput();
+ if ([self isOpenInExclusiveMode] && fixSecureEventInputBug) EnableSecureEventInput();
- [self removeNotificationObserver];
+ [self removeNotificationObserver];
- io_object_t hidDevice = [[self class] findRemoteDevice];
- if (hidDevice == 0) return;
+ io_object_t hidDevice = [[self class] findRemoteDevice];
+ if (hidDevice == 0) return;
- if ([self createInterfaceForDevice:hidDevice] == NULL) {
- goto error;
- }
+ if ([self createInterfaceForDevice:hidDevice] == NULL) {
+ goto error;
+ }
- if ([self initializeCookies]==NO) {
- goto error;
- }
+ if ([self initializeCookies]==NO) {
+ goto error;
+ }
- if ([self openDevice]==NO) {
- goto error;
- }
- // be KVO friendly
- [self willChangeValueForKey:@"listeningToRemote"];
- [self didChangeValueForKey:@"listeningToRemote"];
- goto cleanup;
+ if ([self openDevice]==NO) {
+ goto error;
+ }
+ // be KVO friendly
+ [self willChangeValueForKey:@"listeningToRemote"];
+ [self didChangeValueForKey:@"listeningToRemote"];
+ goto cleanup;
error:
- [self stopListening:self];
- DisableSecureEventInput();
+ [self stopListening:self];
+ DisableSecureEventInput();
cleanup:
- IOObjectRelease(hidDevice);
+ IOObjectRelease(hidDevice);
}
- (void) stopListening: (id) sender {
(void)sender;
- if ([self isListeningToRemote]==NO) return;
+ if ([self isListeningToRemote]==NO) return;
- BOOL sendNotification = NO;
+ BOOL sendNotification = NO;
- if (eventSource != NULL) {
- CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
- CFRelease(eventSource);
- eventSource = NULL;
- }
- if (queue != NULL) {
- (*queue)->stop(queue);
+ if (eventSource != NULL) {
+ CFRunLoopRemoveSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
+ CFRelease(eventSource);
+ eventSource = NULL;
+ }
+ if (queue != NULL) {
+ (*queue)->stop(queue);
- //dispose of queue
- (*queue)->dispose(queue);
+ //dispose of queue
+ (*queue)->dispose(queue);
- //release the queue we allocated
- (*queue)->Release(queue);
+ //release the queue we allocated
+ (*queue)->Release(queue);
- queue = NULL;
+ queue = NULL;
- sendNotification = YES;
- }
+ sendNotification = YES;
+ }
- if (allCookies != nil) {
- [allCookies autorelease];
- allCookies = nil;
- }
+ if (allCookies != nil) {
+ [allCookies autorelease];
+ allCookies = nil;
+ }
- if (hidDeviceInterface != NULL) {
- //close the device
- (*hidDeviceInterface)->close(hidDeviceInterface);
+ if (hidDeviceInterface != NULL) {
+ //close the device
+ (*hidDeviceInterface)->close(hidDeviceInterface);
- //release the interface
- (*hidDeviceInterface)->Release(hidDeviceInterface);
+ //release the interface
+ (*hidDeviceInterface)->Release(hidDeviceInterface);
- hidDeviceInterface = NULL;
- }
+ hidDeviceInterface = NULL;
+ }
- if ([self isOpenInExclusiveMode] && fixSecureEventInputBug) DisableSecureEventInput();
+ if ([self isOpenInExclusiveMode] && fixSecureEventInputBug) DisableSecureEventInput();
- if ([self isOpenInExclusiveMode] && sendNotification) {
- [[self class] sendFinishedNotificationForAppIdentifier: nil];
- }
- // be KVO friendly
- [self willChangeValueForKey:@"listeningToRemote"];
- [self didChangeValueForKey:@"listeningToRemote"];
+ if ([self isOpenInExclusiveMode] && sendNotification) {
+ [[self class] sendFinishedNotificationForAppIdentifier: nil];
+ }
+ // be KVO friendly
+ [self willChangeValueForKey:@"listeningToRemote"];
+ [self didChangeValueForKey:@"listeningToRemote"];
}
@end
@@ -252,40 +252,40 @@ cleanup:
@implementation HIDRemoteControlDevice (PrivateMethods)
- (IOHIDQueueInterface**) queue {
- return queue;
+ return queue;
}
- (IOHIDDeviceInterface**) hidDeviceInterface {
- return hidDeviceInterface;
+ return hidDeviceInterface;
}
- (NSDictionary*) cookieToButtonMapping {
- return cookieToButtonMapping;
+ return cookieToButtonMapping;
}
- (NSString*) validCookieSubstring: (NSString*) cookieString {
- if (cookieString == nil || [cookieString length] == 0) return nil;
- NSEnumerator* keyEnum = [[self cookieToButtonMapping] keyEnumerator];
- NSString* key;
- while( (key = [keyEnum nextObject]) ) {
- NSRange range = [cookieString rangeOfString:key];
- if (range.location == 0) return key;
- }
- return nil;
+ if (cookieString == nil || [cookieString length] == 0) return nil;
+ NSEnumerator* keyEnum = [[self cookieToButtonMapping] keyEnumerator];
+ NSString* key;
+ while( (key = [keyEnum nextObject]) ) {
+ NSRange range = [cookieString rangeOfString:key];
+ if (range.location == 0) return key;
+ }
+ return nil;
}
- (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues {
- /*
- if (previousRemainingCookieString) {
- cookieString = [previousRemainingCookieString stringByAppendingString: cookieString];
- NSLog( @"Apple Remote: New cookie string is %@", cookieString);
- [previousRemainingCookieString release], previousRemainingCookieString=nil;
- }*/
- if (cookieString == nil || [cookieString length] == 0) return;
-
- NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString];
- if (buttonId != nil) {
+ /*
+ if (previousRemainingCookieString) {
+ cookieString = [previousRemainingCookieString stringByAppendingString: cookieString];
+ NSLog( @"Apple Remote: New cookie string is %@", cookieString);
+ [previousRemainingCookieString release], previousRemainingCookieString=nil;
+ }*/
+ if (cookieString == nil || [cookieString length] == 0) return;
+
+ NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString];
+ if (buttonId != nil) {
switch ( (int)buttonId )
{
case kMetallicRemote2009ButtonPlay:
@@ -297,240 +297,240 @@ cleanup:
}
[self sendRemoteButtonEvent: [buttonId intValue] pressedDown: (sumOfValues>0)];
- } else {
- // let's see if a number of events are stored in the cookie string. this does
- // happen when the main thread is too busy to handle all incoming events in time.
- NSString* subCookieString;
- NSString* lastSubCookieString=nil;
- while( (subCookieString = [self validCookieSubstring: cookieString]) ) {
- cookieString = [cookieString substringFromIndex: [subCookieString length]];
- lastSubCookieString = subCookieString;
- if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
- }
- if (processesBacklog == NO && lastSubCookieString != nil) {
- // process the last event of the backlog and assume that the button is not pressed down any longer.
- // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be
- // a button pressed down event while in reality the user has released it.
- // NSLog(@"processing last event of backlog");
- [self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
- }
- if ([cookieString length] > 0) {
- NSLog( @"Apple Remote: Unknown button for cookiestring %@", cookieString);
- }
- }
+ } else {
+ // let's see if a number of events are stored in the cookie string. this does
+ // happen when the main thread is too busy to handle all incoming events in time.
+ NSString* subCookieString;
+ NSString* lastSubCookieString=nil;
+ while( (subCookieString = [self validCookieSubstring: cookieString]) ) {
+ cookieString = [cookieString substringFromIndex: [subCookieString length]];
+ lastSubCookieString = subCookieString;
+ if (processesBacklog) [self handleEventWithCookieString: subCookieString sumOfValues:sumOfValues];
+ }
+ if (processesBacklog == NO && lastSubCookieString != nil) {
+ // process the last event of the backlog and assume that the button is not pressed down any longer.
+ // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be
+ // a button pressed down event while in reality the user has released it.
+ // NSLog(@"processing last event of backlog");
+ [self handleEventWithCookieString: lastSubCookieString sumOfValues:0];
+ }
+ if ([cookieString length] > 0) {
+ NSLog( @"Apple Remote: Unknown button for cookiestring %@", cookieString);
+ }
+ }
}
- (void) removeNotificationObserver {
- [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil];
+ [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil];
}
- (void) remoteControlAvailable:(NSNotification *)notification {
(void)notification;
- [self removeNotificationObserver];
- [self startListening: self];
+ [self removeNotificationObserver];
+ [self startListening: self];
}
@end
-/* Callback method for the device queue
+/* Callback method for the device queue
Will be called for any event of any type (cookie) to which we subscribe
*/
static void QueueCallbackFunction(void* target, IOReturn result, void* refcon, void* sender) {
(void)refcon;
(void)sender;
- if ((intptr_t)target < 0) {
- NSLog( @"Apple Remote: QueueCallbackFunction called with invalid target!");
- return;
- }
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
-
- HIDRemoteControlDevice* remote = (HIDRemoteControlDevice*)target;
- IOHIDEventStruct event;
- AbsoluteTime const zeroTime = {0,0};
- NSMutableString* cookieString = [NSMutableString string];
- SInt32 sumOfValues = 0;
- while (result == kIOReturnSuccess)
- {
- result = (*[remote queue])->getNextEvent([remote queue], &event, zeroTime, 0);
- if ( result != kIOReturnSuccess )
- continue;
-
- //printf("%d %d %d\n", event.elementCookie, event.value, event.longValue);
-
- if (((int)event.elementCookie)!=5) {
- sumOfValues+=event.value;
- [cookieString appendString:[NSString stringWithFormat:@"%lld_", (long long) (intptr_t) event.elementCookie]];
- }
- }
- [remote handleEventWithCookieString: cookieString sumOfValues: sumOfValues];
-
- [pool release];
+ if ((intptr_t)target < 0) {
+ NSLog( @"Apple Remote: QueueCallbackFunction called with invalid target!");
+ return;
+ }
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ HIDRemoteControlDevice* remote = (HIDRemoteControlDevice*)target;
+ IOHIDEventStruct event;
+ AbsoluteTime const zeroTime = {0,0};
+ NSMutableString* cookieString = [NSMutableString string];
+ SInt32 sumOfValues = 0;
+ while (result == kIOReturnSuccess)
+ {
+ result = (*[remote queue])->getNextEvent([remote queue], &event, zeroTime, 0);
+ if ( result != kIOReturnSuccess )
+ continue;
+
+ //printf("%d %d %d\n", event.elementCookie, event.value, event.longValue);
+
+ if (((int)event.elementCookie)!=5) {
+ sumOfValues+=event.value;
+ [cookieString appendString:[NSString stringWithFormat:@"%lld_", (long long) (intptr_t) event.elementCookie]];
+ }
+ }
+ [remote handleEventWithCookieString: cookieString sumOfValues: sumOfValues];
+
+ [pool release];
}
@implementation HIDRemoteControlDevice (IOKitMethods)
- (IOHIDDeviceInterface**) createInterfaceForDevice: (io_object_t) hidDevice {
- io_name_t className;
- IOCFPlugInInterface** plugInInterface = NULL;
- HRESULT plugInResult = S_OK;
- SInt32 score = 0;
- IOReturn ioReturnValue = kIOReturnSuccess;
-
- hidDeviceInterface = NULL;
-
- ioReturnValue = IOObjectGetClass(hidDevice, className);
-
- if (ioReturnValue != kIOReturnSuccess) {
- NSLog( @"Apple Remote: Error: Failed to get RemoteControlDevice class name.");
- return NULL;
- }
-
- ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
- kIOHIDDeviceUserClientTypeID,
- kIOCFPlugInInterfaceID,
- &plugInInterface,
- &score);
- if (ioReturnValue == kIOReturnSuccess)
- {
- //Call a method of the intermediate plug-in to create the device interface
- plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface);
-
- if (plugInResult != S_OK) {
- NSLog( @"Apple Remote: Error: Couldn't create HID class device interface");
- }
- // Release
- if (plugInInterface) (*plugInInterface)->Release(plugInInterface);
- }
- return hidDeviceInterface;
+ io_name_t className;
+ IOCFPlugInInterface** plugInInterface = NULL;
+ HRESULT plugInResult = S_OK;
+ SInt32 score = 0;
+ IOReturn ioReturnValue = kIOReturnSuccess;
+
+ hidDeviceInterface = NULL;
+
+ ioReturnValue = IOObjectGetClass(hidDevice, className);
+
+ if (ioReturnValue != kIOReturnSuccess) {
+ NSLog( @"Apple Remote: Error: Failed to get RemoteControlDevice class name.");
+ return NULL;
+ }
+
+ ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice,
+ kIOHIDDeviceUserClientTypeID,
+ kIOCFPlugInInterfaceID,
+ &plugInInterface,
+ &score);
+ if (ioReturnValue == kIOReturnSuccess)
+ {
+ //Call a method of the intermediate plug-in to create the device interface
+ plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface);
+
+ if (plugInResult != S_OK) {
+ NSLog( @"Apple Remote: Error: Couldn't create HID class device interface");
+ }
+ // Release
+ if (plugInInterface) (*plugInInterface)->Release(plugInInterface);
+ }
+ return hidDeviceInterface;
}
- (BOOL) initializeCookies {
- IOHIDDeviceInterface122** handle = (IOHIDDeviceInterface122**)hidDeviceInterface;
- IOHIDElementCookie cookie;
- long usage;
- long usagePage;
- id object;
- NSArray* elements = nil;
- NSDictionary* element;
- IOReturn success;
-
- if (!handle || !(*handle)) return NO;
-
- // Copy all elements, since we're grabbing most of the elements
- // for this device anyway, and thus, it's faster to iterate them
- // ourselves. When grabbing only one or two elements, a matching
- // dictionary should be passed in here instead of NULL.
- success = (*handle)->copyMatchingElements(handle, NULL, (CFArrayRef*)&elements);
-
- if (success == kIOReturnSuccess) {
-
- /*
- cookies = calloc(NUMBER_OF_APPLE_REMOTE_ACTIONS, sizeof(IOHIDElementCookie));
- memset(cookies, 0, sizeof(IOHIDElementCookie) * NUMBER_OF_APPLE_REMOTE_ACTIONS);
- */
- allCookies = [[NSMutableArray alloc] init];
-
- NSEnumerator *elementsEnumerator = [elements objectEnumerator];
-
- while ( (element = [elementsEnumerator nextObject]) ) {
- //Get cookie
- object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementCookieKey) ];
- if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
- if (object == NULL || CFGetTypeID(object) != CFNumberGetTypeID()) continue;
- cookie = (IOHIDElementCookie) [object longValue];
-
- //Get usage
- object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsageKey) ];
- if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
- usage = [object longValue];
-
- //Get usage page
- object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsagePageKey) ];
- if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
- usagePage = [object longValue];
-
- [allCookies addObject: [NSNumber numberWithInt:(int)cookie]];
- }
- CFRelease(elements);
- elements=nil;
- } else {
- return NO;
- }
-
- return YES;
+ IOHIDDeviceInterface122** handle = (IOHIDDeviceInterface122**)hidDeviceInterface;
+ IOHIDElementCookie cookie;
+ long usage;
+ long usagePage;
+ id object;
+ NSArray* elements = nil;
+ NSDictionary* element;
+ IOReturn success;
+
+ if (!handle || !(*handle)) return NO;
+
+ // Copy all elements, since we're grabbing most of the elements
+ // for this device anyway, and thus, it's faster to iterate them
+ // ourselves. When grabbing only one or two elements, a matching
+ // dictionary should be passed in here instead of NULL.
+ success = (*handle)->copyMatchingElements(handle, NULL, (CFArrayRef*)&elements);
+
+ if (success == kIOReturnSuccess) {
+
+ /*
+ cookies = calloc(NUMBER_OF_APPLE_REMOTE_ACTIONS, sizeof(IOHIDElementCookie));
+ memset(cookies, 0, sizeof(IOHIDElementCookie) * NUMBER_OF_APPLE_REMOTE_ACTIONS);
+ */
+ allCookies = [[NSMutableArray alloc] init];
+
+ NSEnumerator *elementsEnumerator = [elements objectEnumerator];
+
+ while ( (element = [elementsEnumerator nextObject]) ) {
+ //Get cookie
+ object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementCookieKey) ];
+ if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
+ if (object == NULL || CFGetTypeID(object) != CFNumberGetTypeID()) continue;
+ cookie = (IOHIDElementCookie) [object longValue];
+
+ //Get usage
+ object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsageKey) ];
+ if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
+ usage = [object longValue];
+
+ //Get usage page
+ object = [element valueForKey: (NSString*)CFSTR(kIOHIDElementUsagePageKey) ];
+ if (object == nil || ![object isKindOfClass:[NSNumber class]]) continue;
+ usagePage = [object longValue];
+
+ [allCookies addObject: [NSNumber numberWithInt:(int)cookie]];
+ }
+ CFRelease(elements);
+ elements=nil;
+ } else {
+ return NO;
+ }
+
+ return YES;
}
- (BOOL) openDevice {
- HRESULT result;
-
- IOHIDOptionsType openMode = kIOHIDOptionsTypeNone;
- if ([self isOpenInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
- IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, openMode);
-
- if (ioReturnValue == KERN_SUCCESS) {
- queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
- if (queue) {
- result = (*queue)->create(queue, 0, 12); //depth: maximum number of elements in queue before oldest elements in queue begin to be lost.
-
- IOHIDElementCookie cookie;
- NSEnumerator *allCookiesEnumerator = [allCookies objectEnumerator];
-
- while ( (cookie = (IOHIDElementCookie)[[allCookiesEnumerator nextObject] intValue]) ) {
- (*queue)->addElement(queue, cookie, 0);
- }
-
- // add callback for async events
- ioReturnValue = (*queue)->createAsyncEventSource(queue, &eventSource);
- if (ioReturnValue == KERN_SUCCESS) {
- ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL);
- if (ioReturnValue == KERN_SUCCESS) {
- CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
-
- //start data delivery to queue
- (*queue)->start(queue);
- return YES;
- } else {
- NSLog( @"Apple Remote: Error when setting event callback");
- }
- } else {
- NSLog( @"Apple Remote: Error when creating async event source");
- }
- } else {
- NSLog( @"Apple Remote: Error when opening device");
- }
- } else if (ioReturnValue == kIOReturnExclusiveAccess) {
- // the device is used exclusive by another application
-
- // 1. we register for the FINISHED_USING_REMOTE_CONTROL_NOTIFICATION notification
- [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteControlAvailable:) name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil];
-
- // 2. send a distributed notification that we wanted to use the remote control
- [[self class] sendRequestForRemoteControlNotification];
- }
- return NO;
+ HRESULT result;
+
+ IOHIDOptionsType openMode = kIOHIDOptionsTypeNone;
+ if ([self isOpenInExclusiveMode]) openMode = kIOHIDOptionsTypeSeizeDevice;
+ IOReturn ioReturnValue = (*hidDeviceInterface)->open(hidDeviceInterface, openMode);
+
+ if (ioReturnValue == KERN_SUCCESS) {
+ queue = (*hidDeviceInterface)->allocQueue(hidDeviceInterface);
+ if (queue) {
+ result = (*queue)->create(queue, 0, 12); //depth: maximum number of elements in queue before oldest elements in queue begin to be lost.
+
+ IOHIDElementCookie cookie;
+ NSEnumerator *allCookiesEnumerator = [allCookies objectEnumerator];
+
+ while ( (cookie = (IOHIDElementCookie)[[allCookiesEnumerator nextObject] intValue]) ) {
+ (*queue)->addElement(queue, cookie, 0);
+ }
+
+ // add callback for async events
+ ioReturnValue = (*queue)->createAsyncEventSource(queue, &eventSource);
+ if (ioReturnValue == KERN_SUCCESS) {
+ ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL);
+ if (ioReturnValue == KERN_SUCCESS) {
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
+
+ //start data delivery to queue
+ (*queue)->start(queue);
+ return YES;
+ } else {
+ NSLog( @"Apple Remote: Error when setting event callback");
+ }
+ } else {
+ NSLog( @"Apple Remote: Error when creating async event source");
+ }
+ } else {
+ NSLog( @"Apple Remote: Error when opening device");
+ }
+ } else if (ioReturnValue == kIOReturnExclusiveAccess) {
+ // the device is used exclusive by another application
+
+ // 1. we register for the FINISHED_USING_REMOTE_CONTROL_NOTIFICATION notification
+ [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteControlAvailable:) name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil];
+
+ // 2. send a distributed notification that we wanted to use the remote control
+ [[self class] sendRequestForRemoteControlNotification];
+ }
+ return NO;
}
+ (io_object_t) findRemoteDevice {
- CFMutableDictionaryRef hidMatchDictionary = NULL;
- IOReturn ioReturnValue = kIOReturnSuccess;
- io_iterator_t hidObjectIterator = 0;
- io_object_t hidDevice = 0;
+ CFMutableDictionaryRef hidMatchDictionary = NULL;
+ IOReturn ioReturnValue = kIOReturnSuccess;
+ io_iterator_t hidObjectIterator = 0;
+ io_object_t hidDevice = 0;
- // Set up a matching dictionary to search the I/O Registry by class
- // name for all HID class devices
- hidMatchDictionary = IOServiceMatching([self remoteControlDeviceName]);
+ // Set up a matching dictionary to search the I/O Registry by class
+ // name for all HID class devices
+ hidMatchDictionary = IOServiceMatching([self remoteControlDeviceName]);
- // Now search I/O Registry for matching devices.
- ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
+ // Now search I/O Registry for matching devices.
+ ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
- if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
- hidDevice = IOIteratorNext(hidObjectIterator);
- }
+ if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
+ hidDevice = IOIteratorNext(hidObjectIterator);
+ }
- // release the iterator
- IOObjectRelease(hidObjectIterator);
+ // release the iterator
+ IOObjectRelease(hidObjectIterator);
- return hidDevice;
+ return hidDevice;
}
@end
diff --git a/apple_remote/source/KeyspanFrontRowControl.m b/apple_remote/source/KeyspanFrontRowControl.m
index c637aa9cf9c7..ed0cd106869c 100644
--- a/apple_remote/source/KeyspanFrontRowControl.m
+++ b/apple_remote/source/KeyspanFrontRowControl.m
@@ -38,60 +38,60 @@
@implementation KeyspanFrontRowControl
-- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping {
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus] forKey:@"11_18_99_10_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus] forKey:@"11_18_98_10_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu] forKey:@"11_18_58_10_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay] forKey:@"11_18_61_10_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight] forKey:@"11_18_96_10_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft] forKey:@"11_18_97_10_"];
- /* hold events are not being send by this device
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold] forKey:@"14_6_4_2_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold] forKey:@"14_6_3_2_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold] forKey:@"14_6_14_6_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Sleep] forKey:@"18_14_6_18_14_6_"];
- [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched] forKey:@"19_"];
- */
+- (void) setCookieMappingInDictionary: (NSMutableDictionary*) _cookieToButtonMapping {
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlus] forKey:@"11_18_99_10_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMinus] forKey:@"11_18_98_10_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu] forKey:@"11_18_58_10_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay] forKey:@"11_18_61_10_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight] forKey:@"11_18_96_10_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft] forKey:@"11_18_97_10_"];
+ /* hold events are not being send by this device
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonRight_Hold] forKey:@"14_6_4_2_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonLeft_Hold] forKey:@"14_6_3_2_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonMenu_Hold] forKey:@"14_6_14_6_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteButtonPlay_Sleep] forKey:@"18_14_6_18_14_6_"];
+ [_cookieToButtonMapping setObject:[NSNumber numberWithInt:kRemoteControl_Switched] forKey:@"19_"];
+ */
}
+ (io_object_t) findRemoteDevice {
- CFMutableDictionaryRef hidMatchDictionary = NULL;
- IOReturn ioReturnValue = kIOReturnSuccess;
- io_iterator_t hidObjectIterator = 0;
- io_object_t hidDevice = 0;
- SInt32 idVendor = 1741;
- SInt32 idProduct = 0x420;
+ CFMutableDictionaryRef hidMatchDictionary = NULL;
+ IOReturn ioReturnValue = kIOReturnSuccess;
+ io_iterator_t hidObjectIterator = 0;
+ io_object_t hidDevice = 0;
+ SInt32 idVendor = 1741;
+ SInt32 idProduct = 0x420;
- // Set up a matching dictionary to search the I/O Registry by class
- // name for all HID class devices
- hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
+ // Set up a matching dictionary to search the I/O Registry by class
+ // name for all HID class devices
+ hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey);
- CFNumberRef numberRefVendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor);
+ CFNumberRef numberRefVendor = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idVendor);
if ( numberRefVendor )
{
CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDVendorIDKey), numberRefVendor);
CFRelease(numberRefVendor);
- }
+ }
CFNumberRef numberRefProduct = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &idProduct);
if ( numberRefProduct )
{
CFDictionaryAddValue(hidMatchDictionary, CFSTR(kIOHIDProductIDKey), numberRefProduct);
CFRelease(numberRefProduct);
- }
+ }
- // Now search I/O Registry for matching devices.
- ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
+ // Now search I/O Registry for matching devices.
+ ioReturnValue = IOServiceGetMatchingServices(kIOMasterPortDefault, hidMatchDictionary, &hidObjectIterator);
- if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
- hidDevice = IOIteratorNext(hidObjectIterator);
- }
+ if ((ioReturnValue == kIOReturnSuccess) && (hidObjectIterator != 0)) {
+ hidDevice = IOIteratorNext(hidObjectIterator);
+ }
- // release the iterator
+ // release the iterator
if ( hidObjectIterator )
IOObjectRelease(hidObjectIterator);
- return hidDevice;
+ return hidDevice;
}
diff --git a/apple_remote/source/RemoteControl.m b/apple_remote/source/RemoteControl.m
index 9cf840527bd3..2d4021a910b1 100644
--- a/apple_remote/source/RemoteControl.m
+++ b/apple_remote/source/RemoteControl.m
@@ -49,7 +49,7 @@ NSString* kTargetApplicationIdentifier = @"TargetBundleIdentifier";
// returns nil if the remote control device is not available
- (id) initWithDelegate: (id) _remoteControlDelegate {
- if ( (self = [super init]) ) {
+ if ( (self = [super init]) ) {
delegate = [_remoteControlDelegate retain];
#ifdef DEBUG
NSLog( @"Apple RemoteControl initWithDelegate ok");
@@ -59,8 +59,8 @@ NSString* kTargetApplicationIdentifier = @"TargetBundleIdentifier";
}
- (void) dealloc {
- [delegate release];
- [super dealloc];
+ [delegate release];
+ [super dealloc];
}
- (void) setListeningToRemote: (BOOL) value {