HIDRemoteControlDevice.m (eace47cd) | HIDRemoteControlDevice.m (53e04a5d) |
---|---|
1/***************************************************************************** 2 * HIDRemoteControlDevice.m 3 * RemoteControlWrapper 4 * 5 * Created by Martin Kahr on 11.03.06 under a MIT-style license. 6 * Copyright (c) 2006 martinkahr.com. All rights reserved. 7 * 8 * Code modified and adapted to OpenOffice.org --- 260 unchanged lines hidden (view full) --- 269 } 270 return nil; 271} 272 273- (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues { 274 /* 275 if (previousRemainingCookieString) { 276 cookieString = [previousRemainingCookieString stringByAppendingString: cookieString]; | 1/***************************************************************************** 2 * HIDRemoteControlDevice.m 3 * RemoteControlWrapper 4 * 5 * Created by Martin Kahr on 11.03.06 under a MIT-style license. 6 * Copyright (c) 2006 martinkahr.com. All rights reserved. 7 * 8 * Code modified and adapted to OpenOffice.org --- 260 unchanged lines hidden (view full) --- 269 } 270 return nil; 271} 272 273- (void) handleEventWithCookieString: (NSString*) cookieString sumOfValues: (SInt32) sumOfValues { 274 /* 275 if (previousRemainingCookieString) { 276 cookieString = [previousRemainingCookieString stringByAppendingString: cookieString]; |
277 NSLog(@"New cookie string is %@", cookieString); | 277 NSLog( @"Apple Remote: New cookie string is %@", cookieString); |
278 [previousRemainingCookieString release], previousRemainingCookieString=nil; 279 }*/ 280 if (cookieString == nil || [cookieString length] == 0) return; 281 282 NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString]; 283 if (buttonId != nil) { 284 switch ( (int)buttonId ) 285 { --- 19 unchanged lines hidden (view full) --- 305 if (processesBacklog == NO && lastSubCookieString != nil) { 306 // process the last event of the backlog and assume that the button is not pressed down any longer. 307 // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be 308 // a button pressed down event while in reality the user has released it. 309 // NSLog(@"processing last event of backlog"); 310 [self handleEventWithCookieString: lastSubCookieString sumOfValues:0]; 311 } 312 if ([cookieString length] > 0) { | 278 [previousRemainingCookieString release], previousRemainingCookieString=nil; 279 }*/ 280 if (cookieString == nil || [cookieString length] == 0) return; 281 282 NSNumber* buttonId = [[self cookieToButtonMapping] objectForKey: cookieString]; 283 if (buttonId != nil) { 284 switch ( (int)buttonId ) 285 { --- 19 unchanged lines hidden (view full) --- 305 if (processesBacklog == NO && lastSubCookieString != nil) { 306 // process the last event of the backlog and assume that the button is not pressed down any longer. 307 // The events in the backlog do not seem to be in order and therefore (in rare cases) the last event might be 308 // a button pressed down event while in reality the user has released it. 309 // NSLog(@"processing last event of backlog"); 310 [self handleEventWithCookieString: lastSubCookieString sumOfValues:0]; 311 } 312 if ([cookieString length] > 0) { |
313 NSLog(@"Unknown button for cookiestring %@", cookieString); | 313 NSLog( @"Apple Remote: Unknown button for cookiestring %@", cookieString); |
314 } 315 } 316} 317 318- (void) removeNotifcationObserver { 319 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil]; 320} 321 --- 4 unchanged lines hidden (view full) --- 326 327@end 328 329/* Callback method for the device queue 330Will be called for any event of any type (cookie) to which we subscribe 331*/ 332static void QueueCallbackFunction(void* target, IOReturn result, void* refcon, void* sender) { 333 if (target < 0) { | 314 } 315 } 316} 317 318- (void) removeNotifcationObserver { 319 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil]; 320} 321 --- 4 unchanged lines hidden (view full) --- 326 327@end 328 329/* Callback method for the device queue 330Will be called for any event of any type (cookie) to which we subscribe 331*/ 332static void QueueCallbackFunction(void* target, IOReturn result, void* refcon, void* sender) { 333 if (target < 0) { |
334 NSLog(@"QueueCallbackFunction called with invalid target!"); | 334 NSLog( @"Apple Remote: QueueCallbackFunction called with invalid target!"); |
335 return; 336 } 337 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 338 339 HIDRemoteControlDevice* remote = (HIDRemoteControlDevice*)target; 340 IOHIDEventStruct event; 341 AbsoluteTime zeroTime = {0,0}; 342 NSMutableString* cookieString = [NSMutableString string]; --- 25 unchanged lines hidden (view full) --- 368 SInt32 score = 0; 369 IOReturn ioReturnValue = kIOReturnSuccess; 370 371 hidDeviceInterface = NULL; 372 373 ioReturnValue = IOObjectGetClass(hidDevice, className); 374 375 if (ioReturnValue != kIOReturnSuccess) { | 335 return; 336 } 337 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 338 339 HIDRemoteControlDevice* remote = (HIDRemoteControlDevice*)target; 340 IOHIDEventStruct event; 341 AbsoluteTime zeroTime = {0,0}; 342 NSMutableString* cookieString = [NSMutableString string]; --- 25 unchanged lines hidden (view full) --- 368 SInt32 score = 0; 369 IOReturn ioReturnValue = kIOReturnSuccess; 370 371 hidDeviceInterface = NULL; 372 373 ioReturnValue = IOObjectGetClass(hidDevice, className); 374 375 if (ioReturnValue != kIOReturnSuccess) { |
376 NSLog(@"Error: Failed to get class name."); | 376 NSLog( @"Apple Remote: Error: Failed to get RemoteControlDevice class name."); |
377 return NULL; 378 } 379 380 ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice, 381 kIOHIDDeviceUserClientTypeID, 382 kIOCFPlugInInterfaceID, 383 &plugInInterface, 384 &score); 385 if (ioReturnValue == kIOReturnSuccess) 386 { 387 //Call a method of the intermediate plug-in to create the device interface 388 plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface); 389 390 if (plugInResult != S_OK) { | 377 return NULL; 378 } 379 380 ioReturnValue = IOCreatePlugInInterfaceForService(hidDevice, 381 kIOHIDDeviceUserClientTypeID, 382 kIOCFPlugInInterfaceID, 383 &plugInInterface, 384 &score); 385 if (ioReturnValue == kIOReturnSuccess) 386 { 387 //Call a method of the intermediate plug-in to create the device interface 388 plugInResult = (*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (LPVOID) &hidDeviceInterface); 389 390 if (plugInResult != S_OK) { |
391 NSLog(@"Error: Couldn't create HID class device interface"); | 391 NSLog( @"Apple Remote: Error: Couldn't create HID class device interface"); |
392 } 393 // Release 394 if (plugInInterface) (*plugInInterface)->Release(plugInInterface); 395 } 396 return hidDeviceInterface; 397} 398 399- (BOOL) initializeCookies { --- 76 unchanged lines hidden (view full) --- 476 ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL); 477 if (ioReturnValue == KERN_SUCCESS) { 478 CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode); 479 480 //start data delivery to queue 481 (*queue)->start(queue); 482 return YES; 483 } else { | 392 } 393 // Release 394 if (plugInInterface) (*plugInInterface)->Release(plugInInterface); 395 } 396 return hidDeviceInterface; 397} 398 399- (BOOL) initializeCookies { --- 76 unchanged lines hidden (view full) --- 476 ioReturnValue = (*queue)->setEventCallout(queue,QueueCallbackFunction, self, NULL); 477 if (ioReturnValue == KERN_SUCCESS) { 478 CFRunLoopAddSource(CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode); 479 480 //start data delivery to queue 481 (*queue)->start(queue); 482 return YES; 483 } else { |
484 NSLog(@"Error when setting event callback"); | 484 NSLog( @"Apple Remote: Error when setting event callback"); |
485 } 486 } else { | 485 } 486 } else { |
487 NSLog(@"Error when creating async event source"); | 487 NSLog( @"Apple Remote: Error when creating async event source"); |
488 } 489 } else { | 488 } 489 } else { |
490 NSLog(@"Error when opening device"); | 490 NSLog( @"Apple Remote: Error when opening device"); |
491 } 492 } else if (ioReturnValue == kIOReturnExclusiveAccess) { 493 // the device is used exclusive by another application 494 495 // 1. we register for the FINISHED_USING_REMOTE_CONTROL_NOTIFICATION notification 496 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteControlAvailable:) name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil]; 497 498 // 2. send a distributed notification that we wanted to use the remote control --- 30 unchanged lines hidden --- | 491 } 492 } else if (ioReturnValue == kIOReturnExclusiveAccess) { 493 // the device is used exclusive by another application 494 495 // 1. we register for the FINISHED_USING_REMOTE_CONTROL_NOTIFICATION notification 496 [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(remoteControlAvailable:) name:FINISHED_USING_REMOTE_CONTROL_NOTIFICATION object:nil]; 497 498 // 2. send a distributed notification that we wanted to use the remote control --- 30 unchanged lines hidden --- |