Switch controller/HID bridging to non-retained since the controller lives as long...
[enjoyable.git] / Joystick.m
index d6c4362..2d50fa4 100644 (file)
@@ -5,36 +5,26 @@
 //  Created by Sam McCall on 4/05/09.
 //
 
-@implementation Joystick
-
+@implementation Joystick {
+       NSMutableArray *children;
+}
 
-@synthesize    vendorId, productId, productName, name, index, device, children;
+@synthesize    vendorId, productId, productName, index, device, children;
 
--(id)initWithDevice: (IOHIDDeviceRef) newDevice {
-       if(self=[super init]) {
-               children = [[NSMutableArray alloc]init];
-               
-               device = newDevice;
-               productName = (__bridge NSString*)IOHIDDeviceGetProperty( device, CFSTR(kIOHIDProductKey) );
-               vendorId = [(__bridge NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue];
-               productId = [(__bridge NSNumber*)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue];
+- (id)initWithDevice: (IOHIDDeviceRef) newDevice {
+       if ((self = [super init])) {
+               children = [[NSMutableArray alloc] init];
                
-               name = productName;
+               self.device = newDevice;
+               self.productName = (__bridge NSString *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDProductKey));
+               self.vendorId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue];
+               self.productId = [(__bridge NSNumber *)IOHIDDeviceGetProperty(device, CFSTR(kIOHIDVendorIDKey)) intValue];
        }
        return self;
 }
 
--(void) setIndex: (int) newIndex {
-       index = newIndex;
-       name = [[NSString alloc] initWithFormat: @"%@ #%d", productName, (index+1)];
-}
--(int) index {
-       return index;
-}
-
--(void) invalidate {
-       IOHIDDeviceClose(device, kIOHIDOptionsTypeNone);
-       NSLog(@"Removed a device: %@", [self name]);
+- (NSString *)name {
+       return [[NSString alloc] initWithFormat: @"%@ #%d", productName, index + 1];
 }
 
 -(id) base {