Tweak some names in HIDManager.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 21 Mar 2013 12:15:21 +0000 (13:15 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 21 Mar 2013 12:15:21 +0000 (13:15 +0100)
Classes/NJHIDManager.h
Classes/NJHIDManager.m
Classes/NJInputController.m
Info.plist
Other Sources/Enjoyable_Prefix.pch

index 752a6e58bf65d17f7ed8df4bc4714f622dd0f21c..af86b3bd1b594f09420f4d07b940de44998d3193 100644 (file)
@@ -1,26 +1,22 @@
-//
-//  NJHIDManager.h
-//  Enjoyable
-//
-//  Created by Joe Wreschnig on 3/13/13.
-//
-//
-
 #import <Foundation/Foundation.h>
+#import <IOKit/hid/IOHIDLib.h>
 
 @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 <NJHIDManagerDelegate>)delegate;
 
-@property (nonatomic, assign) BOOL running;
 @property (nonatomic, weak) id <NJHIDManagerDelegate> delegate;
 
-- (id)initWithCriteria:(NSArray *)criteria
-              delegate:(id <NJHIDManagerDelegate>)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;
 
 @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
index 5245bf562c41bf749dd30ea269bf5f644d95c8fc..3dbaec3a6cb87335402790f48a54f5bde99b9a71 100644 (file)
@@ -1,11 +1,3 @@
-//
-//  NJHIDManager.m
-//  Enjoyable
-//
-//  Created by Joe Wreschnig on 3/13/13.
-//
-//
-
 #import "NJHIDManager.h"
 
 @implementation NJHIDManager {
     [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;
 }
index 9ff9d2679cdce9c2dca18934d680213d1e08edb7..cd665de54b1f78718e669bbb77e4f24b96661eeb 100644 (file)
@@ -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),
     [self.delegate inputController:self didInput:handler];
 }
 
-- (void)hidManager:(NJHIDManager *)manager
+- (void)HIDManager:(NJHIDManager *)manager
       valueChanged:(IOHIDValueRef)value
         fromDevice:(IOHIDDeviceRef)device {
     if (self.simulatingEvents
     [_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];
     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];
     }
 }
 
-- (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 {
index d1e308d72dfa94e5dac23be1a88d4f0afa6b8571..4c6333a98b4a281fe819dcf1cee9e3de4b10c37c 100644 (file)
@@ -46,7 +46,7 @@
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>575</string>
+       <string>578</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
index a873aec786b339e3de1b3f34c629f8cf7aacfb62..0261743e6945b3f783c8be0332f60718390d3178 100644 (file)
@@ -4,17 +4,16 @@
 
 #ifdef __OBJC__
     #import <Cocoa/Cocoa.h>
-#endif
-
-#import <IOKit/hid/IOHIDLib.h>
+    #import <IOKit/hid/IOHIDLib.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"
+    #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