From fb780593799014faf609388b479c405ae125b5f4 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Thu, 21 Mar 2013 13:15:21 +0100 Subject: [PATCH] Tweak some names in HIDManager. --- Classes/NJHIDManager.h | 41 ++++++++++++++---------------- Classes/NJHIDManager.m | 39 ++++++++++++++-------------- Classes/NJInputController.m | 20 +++++++-------- Info.plist | 2 +- Other Sources/Enjoyable_Prefix.pch | 25 +++++++++--------- 5 files changed, 61 insertions(+), 66 deletions(-) diff --git a/Classes/NJHIDManager.h b/Classes/NJHIDManager.h index 752a6e5..af86b3b 100644 --- a/Classes/NJHIDManager.h +++ b/Classes/NJHIDManager.h @@ -1,26 +1,22 @@ -// -// NJHIDManager.h -// Enjoyable -// -// Created by Joe Wreschnig on 3/13/13. -// -// - #import +#import @protocol NJHIDManagerDelegate; @interface NJHIDManager : NSObject + // Light OO wrapper around IOKit callbacks. -@property (nonatomic, copy) NSArray *criteria; - // Changing the criteria may trigger a stop and restart. If this happens, - // messages will be sent to the delegate as usual. +- (id)initWithCriteria:(NSArray *)criteria + delegate:(id )delegate; -@property (nonatomic, assign) BOOL running; @property (nonatomic, weak) id delegate; -- (id)initWithCriteria:(NSArray *)criteria - delegate:(id )delegate; +@property (nonatomic, copy) NSArray *criteria; + // Changing the criteria may trigger a stop and restart. If this + // happens, messages will be sent to the delegate as usual. + +@property (nonatomic, assign) BOOL running; + // Assigning YES is like sending start; NO like stop. - (void)start; - (void)stop; @@ -29,17 +25,18 @@ @protocol NJHIDManagerDelegate -- (void)hidManagerDidStart:(NJHIDManager *)manager; -- (void)hidManagerDidStop:(NJHIDManager *)manager; - // Stopping the device will not trigger any removal events, so any +- (void)HIDManagerDidStart:(NJHIDManager *)manager; +- (void)HIDManagerDidStop:(NJHIDManager *)manager; + // Stopping the device will not trigger any removal messages, so any // cleanup in the delegate must be done here. -- (void)hidManager:(NJHIDManager *)manager didError:(NSError *)error; +- (void)HIDManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device; +- (void)HIDManager:(NJHIDManager *)manager deviceRemoved:(IOHIDDeviceRef)device; -- (void)hidManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device; -- (void)hidManager:(NJHIDManager *)manager deviceRemoved:(IOHIDDeviceRef)device; - -- (void)hidManager:(NJHIDManager *)manager +- (void)HIDManager:(NJHIDManager *)manager valueChanged:(IOHIDValueRef)value fromDevice:(IOHIDDeviceRef)device; + +- (void)HIDManager:(NJHIDManager *)manager didError:(NSError *)error; + @end diff --git a/Classes/NJHIDManager.m b/Classes/NJHIDManager.m index 5245bf5..3dbaec3 100644 --- a/Classes/NJHIDManager.m +++ b/Classes/NJHIDManager.m @@ -1,11 +1,3 @@ -// -// NJHIDManager.m -// Enjoyable -// -// Created by Joe Wreschnig on 3/13/13. -// -// - #import "NJHIDManager.h" @implementation NJHIDManager { @@ -27,21 +19,21 @@ [self stop]; } -static void input_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) { +static void _input(void *ctx, IOReturn inResult, void *inSender, IOHIDValueRef value) { NJHIDManager *self = (__bridge NJHIDManager *)ctx; IOHIDDeviceRef device = IOHIDQueueGetDevice(inSender); - [self.delegate hidManager:self valueChanged:value fromDevice:device]; + [self.delegate HIDManager:self valueChanged:value fromDevice:device]; } -static void add_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { +static void _add(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { NJHIDManager *self = (__bridge NJHIDManager *)ctx; - [self.delegate hidManager:self deviceAdded:device]; - IOHIDDeviceRegisterInputValueCallback(device, input_callback, ctx); + [self.delegate HIDManager:self deviceAdded:device]; + IOHIDDeviceRegisterInputValueCallback(device, _input, ctx); } -static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { +static void _remove(void *ctx, IOReturn inResult, void *inSender, IOHIDDeviceRef device) { NJHIDManager *self = (__bridge NJHIDManager *)ctx; - [self.delegate hidManager:self deviceRemoved:device]; + [self.delegate HIDManager:self deviceRemoved:device]; } - (void)start { @@ -54,14 +46,14 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD NSError *error = [NSError errorWithDomain:NSMachErrorDomain code:ret userInfo:nil]; IOHIDManagerClose(manager, kIOHIDOptionsTypeNone); CFRelease(manager); - [self.delegate hidManager:self didError:error]; + [self.delegate HIDManager:self didError:error]; NSLog(@"Error starting HID manager: %@.", error); } else { _manager = manager; IOHIDManagerScheduleWithRunLoop(_manager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - IOHIDManagerRegisterDeviceMatchingCallback(_manager, add_callback, (__bridge void *)self); - IOHIDManagerRegisterDeviceRemovalCallback(_manager, remove_callback, (__bridge void *)self); - [self.delegate hidManagerDidStart:self]; + IOHIDManagerRegisterDeviceMatchingCallback(_manager, _add, (__bridge void *)self); + IOHIDManagerRegisterDeviceRemovalCallback(_manager, _remove, (__bridge void *)self); + [self.delegate HIDManagerDidStart:self]; NSLog(@"Started HID manager."); } } @@ -73,7 +65,7 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD IOHIDManagerClose(_manager, kIOHIDOptionsTypeNone); CFRelease(_manager); _manager = NULL; - [self.delegate hidManagerDidStop:self]; + [self.delegate HIDManagerDidStop:self]; NSLog(@"Stopped HID manager."); } @@ -81,6 +73,13 @@ static void remove_callback(void *ctx, IOReturn inResult, void *inSender, IOHIDD return !!_manager; } +- (void)setRunning:(BOOL)running { + if (running) + [self start]; + else + [self stop]; +} + - (NSArray *)criteria { return _criteria; } diff --git a/Classes/NJInputController.m b/Classes/NJInputController.m index 9ff9d26..cd665de 100644 --- a/Classes/NJInputController.m +++ b/Classes/NJInputController.m @@ -12,7 +12,7 @@ #import "NJEvents.h" @implementation NJInputController { - NJHIDManager *_hidManager; + NJHIDManager *_HIDManager; NSTimer *_continuousOutputsTick; NSMutableArray *_continousOutputs; NSMutableArray *_devices; @@ -28,7 +28,7 @@ _devices = [[NSMutableArray alloc] initWithCapacity:16]; _continousOutputs = [[NSMutableArray alloc] initWithCapacity:32]; - _hidManager = [[NJHIDManager alloc] initWithCriteria:@[ + _HIDManager = [[NJHIDManager alloc] initWithCriteria:@[ @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), NSSTR(kIOHIDDeviceUsageKey) : @(kHIDUsage_GD_Joystick) }, @{ NSSTR(kIOHIDDeviceUsagePageKey) : @(kHIDPage_GenericDesktop), @@ -109,7 +109,7 @@ [self.delegate inputController:self didInput:handler]; } -- (void)hidManager:(NJHIDManager *)manager +- (void)HIDManager:(NJHIDManager *)manager valueChanged:(IOHIDValueRef)value fromDevice:(IOHIDDeviceRef)device { if (self.simulatingEvents @@ -135,7 +135,7 @@ [_devices addObject:device]; } -- (void)hidManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device { +- (void)HIDManager:(NJHIDManager *)manager deviceAdded:(IOHIDDeviceRef)device { NJDevice *match = [[NJDevice alloc] initWithDevice:device]; [self addDevice:match]; [self.delegate inputController:self didAddDevice:match]; @@ -148,7 +148,7 @@ return nil; } -- (void)hidManager:(NJHIDManager *)manager deviceRemoved:(IOHIDDeviceRef)device { +- (void)HIDManager:(NJHIDManager *)manager deviceRemoved:(IOHIDDeviceRef)device { NJDevice *match = [self findDeviceByRef:device]; if (match) { NSInteger idx = [_devices indexOfObjectIdenticalTo:match]; @@ -170,26 +170,26 @@ } } -- (void)hidManager:(NJHIDManager *)manager didError:(NSError *)error { +- (void)HIDManager:(NJHIDManager *)manager didError:(NSError *)error { [self.delegate inputController:self didError:error]; self.simulatingEvents = NO; } -- (void)hidManagerDidStart:(NJHIDManager *)manager { +- (void)HIDManagerDidStart:(NJHIDManager *)manager { [self.delegate inputControllerDidStartHID:self]; } -- (void)hidManagerDidStop:(NJHIDManager *)manager { +- (void)HIDManagerDidStop:(NJHIDManager *)manager { [_devices removeAllObjects]; [self.delegate inputControllerDidStopHID:self]; } - (void)startHid { - [_hidManager start]; + [_HIDManager start]; } - (void)stopHid { - [_hidManager stop]; + [_HIDManager stop]; } - (void)setSimulatingEvents:(BOOL)simulatingEvents { diff --git a/Info.plist b/Info.plist index d1e308d..4c6333a 100644 --- a/Info.plist +++ b/Info.plist @@ -46,7 +46,7 @@ CFBundleSignature ???? CFBundleVersion - 575 + 578 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Other Sources/Enjoyable_Prefix.pch b/Other Sources/Enjoyable_Prefix.pch index a873aec..0261743 100644 --- a/Other Sources/Enjoyable_Prefix.pch +++ b/Other Sources/Enjoyable_Prefix.pch @@ -4,17 +4,16 @@ #ifdef __OBJC__ #import -#endif - -#import + #import -#import "NSError+Description.h" -#import "NSMenu+RepresentedObjectAccessors.h" -#import "NSView+FirstResponder.h" -#import "NSMutableArray+MoveObject.h" -#import "NSFileManager+UniqueNames.h" -#import "NSString+FixFilename.h" -#import "NSRunningApplication+NJPossibleNames.h" -#import "NSRunningApplication+LoginItem.h" -#import "NSOutlineView+ItemAccessors.h" -#import "NSProcessInfo+Debugging.h" + #import "NSError+Description.h" + #import "NSMenu+RepresentedObjectAccessors.h" + #import "NSView+FirstResponder.h" + #import "NSMutableArray+MoveObject.h" + #import "NSFileManager+UniqueNames.h" + #import "NSString+FixFilename.h" + #import "NSRunningApplication+NJPossibleNames.h" + #import "NSRunningApplication+LoginItem.h" + #import "NSOutlineView+ItemAccessors.h" + #import "NSProcessInfo+Debugging.h" +#endif -- 2.20.1