aboutsummaryrefslogtreecommitdiffstats
path: root/browser
diff options
context:
space:
mode:
authorDominik Pich2013-03-17 13:33:20 +0100
committerDominik Pich2013-03-17 13:33:20 +0100
commitd4ffd217288cfc0d2798b3df67ab20bc867a7f7e (patch)
treeab40c6fb784fbe578713381ea5cf1159934a9c34 /browser
parent77d2a9f99a289d247c5a8561879489c8f8162055 (diff)
downloadDDHidLib-d4ffd217288cfc0d2798b3df67ab20bc867a7f7e.tar.bz2
DDHIDLib 1.1.1
Diffstat (limited to 'browser')
-rw-r--r--browser/English.lproj/EventWatcher.nib/classes.nib13
-rw-r--r--browser/English.lproj/EventWatcher.nib/info.nib16
-rw-r--r--browser/English.lproj/EventWatcher.nib/keyedobjects.nibbin0 -> 9260 bytes
-rw-r--r--browser/English.lproj/InfoPlist.stringsbin0 -> 190 bytes
-rw-r--r--browser/English.lproj/MainMenu.nib/classes.nib19
-rw-r--r--browser/English.lproj/MainMenu.nib/info.nib22
-rw-r--r--browser/English.lproj/MainMenu.nib/keyedobjects.nibbin0 -> 31311 bytes
-rw-r--r--browser/HIDBrowser_Prefix.pch7
-rw-r--r--browser/HexFormatter.h34
-rw-r--r--browser/HexFormatter.m49
-rw-r--r--browser/HidBrowserController.h42
-rw-r--r--browser/HidBrowserController.m144
-rw-r--r--browser/Info.plist30
-rw-r--r--browser/WatcherWindowController.h57
-rw-r--r--browser/WatcherWindowController.m269
-rw-r--r--browser/main.m30
16 files changed, 732 insertions, 0 deletions
diff --git a/browser/English.lproj/EventWatcher.nib/classes.nib b/browser/English.lproj/EventWatcher.nib/classes.nib
new file mode 100644
index 0000000..8f04df5
--- /dev/null
+++ b/browser/English.lproj/EventWatcher.nib/classes.nib
@@ -0,0 +1,13 @@
+{
+ IBClasses = (
+ {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
+ {
+ ACTIONS = {clearHistory = id; };
+ CLASS = WatcherWindowController;
+ LANGUAGE = ObjC;
+ OUTLETS = {mEventHistoryController = NSArrayController; };
+ SUPERCLASS = NSWindowController;
+ }
+ );
+ IBVersion = 1;
+} \ No newline at end of file
diff --git a/browser/English.lproj/EventWatcher.nib/info.nib b/browser/English.lproj/EventWatcher.nib/info.nib
new file mode 100644
index 0000000..1c52771
--- /dev/null
+++ b/browser/English.lproj/EventWatcher.nib/info.nib
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IBDocumentLocation</key>
+ <string>69 14 356 240 0 0 1440 878 </string>
+ <key>IBFramework Version</key>
+ <string>446.1</string>
+ <key>IBOpenObjects</key>
+ <array>
+ <integer>5</integer>
+ </array>
+ <key>IBSystem Version</key>
+ <string>8N1037</string>
+</dict>
+</plist>
diff --git a/browser/English.lproj/EventWatcher.nib/keyedobjects.nib b/browser/English.lproj/EventWatcher.nib/keyedobjects.nib
new file mode 100644
index 0000000..61ebe6c
--- /dev/null
+++ b/browser/English.lproj/EventWatcher.nib/keyedobjects.nib
Binary files differ
diff --git a/browser/English.lproj/InfoPlist.strings b/browser/English.lproj/InfoPlist.strings
new file mode 100644
index 0000000..30cfd96
--- /dev/null
+++ b/browser/English.lproj/InfoPlist.strings
Binary files differ
diff --git a/browser/English.lproj/MainMenu.nib/classes.nib b/browser/English.lproj/MainMenu.nib/classes.nib
new file mode 100644
index 0000000..910a1c9
--- /dev/null
+++ b/browser/English.lproj/MainMenu.nib/classes.nib
@@ -0,0 +1,19 @@
+{
+ IBClasses = (
+ {CLASS = DDHidElement; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
+ {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
+ {CLASS = HexFormatter; LANGUAGE = ObjC; SUPERCLASS = NSFormatter; },
+ {
+ ACTIONS = {exportPlist = id; watchSelected = id; };
+ CLASS = HidBrowserController;
+ LANGUAGE = ObjC;
+ OUTLETS = {
+ mDevicesController = NSArrayController;
+ mElementsController = NSTreeController;
+ mWindow = NSWindow;
+ };
+ SUPERCLASS = NSObject;
+ }
+ );
+ IBVersion = 1;
+} \ No newline at end of file
diff --git a/browser/English.lproj/MainMenu.nib/info.nib b/browser/English.lproj/MainMenu.nib/info.nib
new file mode 100644
index 0000000..d20a5cf
--- /dev/null
+++ b/browser/English.lproj/MainMenu.nib/info.nib
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IBDocumentLocation</key>
+ <string>110 86 356 240 0 0 1440 878 </string>
+ <key>IBEditorPositions</key>
+ <dict>
+ <key>29</key>
+ <string>95 721 310 44 0 0 1440 878 </string>
+ </dict>
+ <key>IBFramework Version</key>
+ <string>446.1</string>
+ <key>IBOpenObjects</key>
+ <array>
+ <integer>21</integer>
+ <integer>29</integer>
+ </array>
+ <key>IBSystem Version</key>
+ <string>8N1037</string>
+</dict>
+</plist>
diff --git a/browser/English.lproj/MainMenu.nib/keyedobjects.nib b/browser/English.lproj/MainMenu.nib/keyedobjects.nib
new file mode 100644
index 0000000..904f45d
--- /dev/null
+++ b/browser/English.lproj/MainMenu.nib/keyedobjects.nib
Binary files differ
diff --git a/browser/HIDBrowser_Prefix.pch b/browser/HIDBrowser_Prefix.pch
new file mode 100644
index 0000000..5d5ed48
--- /dev/null
+++ b/browser/HIDBrowser_Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'HIDBrowser' target in the 'HIDBrowser' project
+//
+
+#ifdef __OBJC__
+ #import <Cocoa/Cocoa.h>
+#endif
diff --git a/browser/HexFormatter.h b/browser/HexFormatter.h
new file mode 100644
index 0000000..e3b28c2
--- /dev/null
+++ b/browser/HexFormatter.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface HexFormatter : NSFormatter {
+
+}
+
++ (NSString*)format:(long)number;
+
+@end
diff --git a/browser/HexFormatter.m b/browser/HexFormatter.m
new file mode 100644
index 0000000..5ac3f6f
--- /dev/null
+++ b/browser/HexFormatter.m
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import "HexFormatter.h"
+
+
+@implementation HexFormatter
+
++ (NSString*)format:(long)number;
+{
+ return [NSString stringWithFormat: @"0x%02X", number];
+}
+
+
+- (NSString *)stringForObjectValue:(id)anObject {
+ return [HexFormatter format:[anObject longValue]];
+}
+
+- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error {
+ return NO;
+}
+
+- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes {
+ return [[[NSAttributedString alloc] initWithString:[self stringForObjectValue:anObject]] autorelease];
+}
+
+
+@end
diff --git a/browser/HidBrowserController.h b/browser/HidBrowserController.h
new file mode 100644
index 0000000..3e7e116
--- /dev/null
+++ b/browser/HidBrowserController.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface HidBrowserController : NSObject
+{
+ IBOutlet NSWindow * mWindow;
+ IBOutlet NSArrayController * mDevicesController;
+ IBOutlet NSTreeController * mElementsController;
+ NSArray * mDevices;
+}
+
+- (NSArray *) devices;
+
+- (IBAction) watchSelected: (id) sender;
+
+- (IBAction) exportPlist: (id) sender;
+
+@end
diff --git a/browser/HidBrowserController.m b/browser/HidBrowserController.m
new file mode 100644
index 0000000..4b12267
--- /dev/null
+++ b/browser/HidBrowserController.m
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import "HidBrowserController.h"
+#import "DDHidUsageTables.h"
+#import "DDHidDevice.h"
+#import "DDHidElement.h"
+#import "WatcherWindowController.h"
+
+@implementation HidBrowserController
+
+static BOOL sSleepAtExit = NO;
+
+static void exit_sleeper()
+{
+ while (sSleepAtExit) sleep(60);
+}
+
+- (void) awakeFromNib
+{
+ sSleepAtExit = [[NSUserDefaults standardUserDefaults] boolForKey: @"SleepAtExit"];
+ atexit(exit_sleeper);
+
+ [self willChangeValueForKey: @"devices"];
+ mDevices = [[DDHidDevice allDevices] retain];
+ [self didChangeValueForKey: @"devices"];
+
+ [mWindow center];
+ [mWindow makeKeyAndOrderFront: self];
+}
+
+//===========================================================
+// dealloc
+//===========================================================
+- (void) dealloc
+{
+ [mDevices release];
+
+ mDevices = nil;
+ [super dealloc];
+}
+
+//===========================================================
+// - devices
+//===========================================================
+- (NSArray *) devices
+{
+ return mDevices;
+}
+
+- (DDHidDevice *) selectedDevice;
+{
+ NSArray * selectedDevices = [mDevicesController selectedObjects];
+ if ([selectedDevices count] > 0)
+ return [selectedDevices objectAtIndex: 0];
+ else
+ return nil;
+}
+
+- (IBAction) watchSelected: (id) sender;
+{
+ NSArray * selectedElements = [mElementsController selectedObjects];
+ if ([selectedElements count] == 0)
+ return;
+
+ WatcherWindowController * controller =
+ [[WatcherWindowController alloc] init];
+ [controller setDevice: [self selectedDevice]];
+ [controller setElements: selectedElements];
+ [controller showWindow: self];
+}
+
+- (IBAction) exportPlist: (id) sender;
+{
+ DDHidDevice * selectedDevice = [self selectedDevice];
+ if (selectedDevice == nil)
+ return;
+
+ NSSavePanel * panel = [NSSavePanel savePanel];
+
+ /* set up new attributes */
+ [panel setRequiredFileType: @"plist"];
+ [panel setAllowsOtherFileTypes: NO];
+ [panel setCanSelectHiddenExtension: YES];
+
+ /* display the NSSavePanel */
+ [panel beginSheetForDirectory: NSHomeDirectory()
+ file: @""
+ modalForWindow: [NSApp mainWindow]
+ modalDelegate: self
+ didEndSelector: @selector(exportPlistPanelDidEnd:returnCode:contextInfo:)
+ contextInfo: selectedDevice];
+}
+
+- (void) exportPlistPanelDidEnd: (NSSavePanel *) panel
+ returnCode: (int) returnCode
+ contextInfo: (void *) contextInfo;
+{
+ DDHidDevice * selectedDevice = contextInfo;
+
+ /* if successful, save file under designated name */
+ if (returnCode != NSOKButton)
+ return;
+
+ NSDictionary * deviceProperties = [selectedDevice properties];
+ if (![deviceProperties writeToFile: [panel filename] atomically: YES])
+ NSBeep();
+}
+
+- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
+{
+ return YES;
+}
+
+- (void)applicationWillTerminate:(NSNotification *)aNotification
+{
+ [self willChangeValueForKey: @"devices"];
+ [mDevices release];
+ mDevices = nil;
+ [self didChangeValueForKey: @"devices"];
+}
+
+@end
diff --git a/browser/Info.plist b/browser/Info.plist
new file mode 100644
index 0000000..feff01c
--- /dev/null
+++ b/browser/Info.plist
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>org.dribin.dave.ddhidlib.HIDBrowser</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${CURRENT_PROJECT_VERSION}</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${CURRENT_MARKETING_VERSION}</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>
diff --git a/browser/WatcherWindowController.h b/browser/WatcherWindowController.h
new file mode 100644
index 0000000..5cc447a
--- /dev/null
+++ b/browser/WatcherWindowController.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import "DDHidDevice.h"
+#import "DDHidElement.h"
+
+@class DDHidQueue;
+
+@interface WatcherWindowController : NSWindowController
+{
+ IBOutlet NSArrayController * mEventHistoryController;
+ DDHidDevice * mDevice;
+ NSArray * mElements;
+ DDHidQueue * mQueue;
+ NSMutableArray * mEventHistory;
+ int mNextIndex;
+}
+
+- (DDHidDevice *) device;
+- (void) setDevice: (DDHidDevice *) newDevice;
+
+- (NSArray *) elements;
+- (void) setElements: (NSArray *) newElements;
+
+- (NSMutableArray *) eventHistory;
+- (void) setEventHistory: (NSMutableArray *) anEventHistory;
+- (void) addToEventHistory: (id)mEventHistoryObject;
+- (void) removeFromEventHistory: (id)mEventHistoryObject;
+
+- (BOOL) isWatching;
+- (void) setWatching: (BOOL) watching;
+
+- (IBAction) clearHistory: (id) sender;
+
+@end
diff --git a/browser/WatcherWindowController.m b/browser/WatcherWindowController.m
new file mode 100644
index 0000000..a13c986
--- /dev/null
+++ b/browser/WatcherWindowController.m
@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import "WatcherWindowController.h"
+#import "DDHidQueue.h"
+#import "DDHidEvent.h"
+#import "DDHidUsage.h"
+
+@interface WatcherEvent : NSObject
+{
+ NSString * mUsageDescription;
+ DDHidEvent * mEvent;
+ int mIndex;
+}
+
+- (id) initWithUsageDescription: (NSString *) anUsageDecription
+ event: (DDHidEvent *) anEvent
+ index: (int) index;
+
+- (NSString *) usageDescription;
+- (DDHidEvent *) event;
+- (int) index;
+
+@end
+
+@implementation WatcherEvent : NSObject
+
+- (id) initWithUsageDescription: (NSString *) anUsageDescription
+ event: (DDHidEvent *) anEvent
+ index: (int) index
+{
+ if (self = [super init])
+ {
+ mUsageDescription = [anUsageDescription retain];
+ mEvent = [anEvent retain];
+ mIndex = index;
+ }
+ return self;
+}
+
+//===========================================================
+// dealloc
+//===========================================================
+- (void) dealloc
+{
+ [mUsageDescription release];
+ [mEvent release];
+
+ mUsageDescription = nil;
+ mEvent = nil;
+ [super dealloc];
+}
+
+//===========================================================
+// - usageDescription
+//===========================================================
+- (NSString *) usageDescription
+{
+ return mUsageDescription;
+}
+
+//===========================================================
+// - event
+//===========================================================
+- (DDHidEvent *) event
+{
+ return mEvent;
+}
+
+//===========================================================
+// - index
+//===========================================================
+- (int) index
+{
+ return mIndex;
+}
+
+@end
+
+@implementation WatcherWindowController
+
+- (id) init
+{
+ self = [super initWithWindowNibName: @"EventWatcher" owner: self];
+ if (self == nil)
+ return nil;
+
+ mEventHistory = [[NSMutableArray alloc] init];
+ mNextIndex = 1;
+
+ return self;
+}
+
+
+//===========================================================
+// dealloc
+//===========================================================
+- (void) dealloc
+{
+ [mQueue release];
+ [mDevice release];
+ [mElements release];
+ [mEventHistory release];
+
+ mQueue = nil;
+ mDevice = nil;
+ mElements = nil;
+ mEventHistory = nil;
+ [super dealloc];
+}
+
+- (void)windowWillClose:(NSNotification *)notification
+{
+ [mQueue release];
+ mQueue = nil;
+ [mDevice close];
+ [self autorelease];
+}
+
+- (IBAction)showWindow:(id)sender
+{
+ [super showWindow: sender];
+}
+
+- (void) ddhidQueueHasEvents: (DDHidQueue *) hidQueue;
+{
+ WatcherEvent * watcherEvent;
+ watcherEvent =
+ [[WatcherEvent alloc] initWithUsageDescription: @"-----------------------------"
+ event: nil
+ index: mNextIndex++];
+ [watcherEvent autorelease];
+ [mEventHistoryController addObject: watcherEvent];
+
+ NSMutableArray * newEvents = [NSMutableArray array];
+ DDHidEvent * event;
+ while (event = [hidQueue nextEvent])
+ {
+ DDHidElement * element = [mDevice elementForCookie: [event elementCookie]];
+ watcherEvent =
+ [[WatcherEvent alloc] initWithUsageDescription: [[element usage] usageNameWithIds]
+ event: event
+ index: mNextIndex++];
+ [watcherEvent autorelease];
+ [newEvents addObject: watcherEvent];
+ }
+
+ [mEventHistoryController addObjects: newEvents];
+}
+
+- (void) windowDidLoad;
+{
+ [mDevice open];
+ mQueue = [[mDevice createQueueWithSize: 30] retain];
+ [mQueue setDelegate: self];
+ [mQueue addElements: mElements];
+ [self willChangeValueForKey: @"watching"];
+ [mQueue startOnCurrentRunLoop];
+ [self didChangeValueForKey: @"watching"];
+}
+
+//===========================================================
+// device
+//===========================================================
+- (DDHidDevice *) device
+{
+ return [[mDevice retain] autorelease];
+}
+
+- (void) setDevice: (DDHidDevice *) newDevice
+{
+ if (mDevice != newDevice)
+ {
+ [mDevice release];
+ mDevice = [newDevice retain];
+ }
+}
+
+//===========================================================
+// elements
+//===========================================================
+- (NSArray *) elements
+{
+ return [[mElements retain] autorelease];
+}
+
+- (void) setElements: (NSArray *) newElements
+{
+ if (mElements != newElements)
+ {
+ [mElements release];
+ mElements = [newElements retain];
+ }
+}
+
+//===========================================================
+// eventHistory
+//===========================================================
+- (NSMutableArray *) eventHistory
+{
+ return mEventHistory;
+}
+
+- (void) setEventHistory: (NSMutableArray *) anEventHistory
+{
+ if (mEventHistory != anEventHistory)
+ {
+ [mEventHistory release];
+ mEventHistory = [anEventHistory retain];
+ }
+}
+- (void) addToEventHistory: (id)mEventHistoryObject
+{
+ [[self eventHistory] addObject: mEventHistoryObject];
+}
+- (void) removeFromEventHistory: (id)mEventHistoryObject
+{
+ [[self eventHistory] removeObject: mEventHistoryObject];
+}
+
+- (BOOL) isWatching;
+{
+ if (mQueue == nil)
+ return NO;
+ return [mQueue isStarted];
+}
+
+- (void) setWatching: (BOOL) watching;
+{
+ BOOL isStarted = [mQueue isStarted];
+ if (isStarted == watching)
+ return;
+
+ if (watching)
+ [mQueue startOnCurrentRunLoop];
+ else
+ [mQueue stop];
+}
+
+- (IBAction) clearHistory: (id) sender;
+{
+ [self willChangeValueForKey: @"eventHistory"];
+ [mEventHistory removeAllObjects];
+ mNextIndex = 1;
+ [self didChangeValueForKey: @"eventHistory"];
+}
+
+@end
diff --git a/browser/main.m b/browser/main.m
new file mode 100644
index 0000000..f05b99f
--- /dev/null
+++ b/browser/main.m
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2007 Dave Dribin
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+int main(int argc, char *argv[])
+{
+ return NSApplicationMain(argc, (const char **) argv);
+}