-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial roughed out API, using a target/selector event listener style.
Perhaps NSNotification propagation could come later?
- Loading branch information
0 parents
commit 3c0eb03
Showing
16 changed files
with
977 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.pbxproj -crlf -diff -merge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# xcode noise | ||
build/* | ||
*.pbxuser | ||
*.mode1v3 | ||
*.mode* | ||
|
||
# osx noise | ||
.DS_Store | ||
profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// PTEventListener.h | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright 2010 LJR Software Limited. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface PTEventListener : NSObject { | ||
id target; | ||
SEL selector; | ||
} | ||
- (id)initWithTarget:(id)_target selector:(SEL)_selector; | ||
- (void)dispatch:(id)eventData; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// PTEventListener.m | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright 2010 LJR Software Limited. All rights reserved. | ||
// | ||
|
||
#import "PTEventListener.h" | ||
|
||
|
||
@implementation PTEventListener | ||
|
||
- (id)initWithTarget:(id)_target selector:(SEL)_selector; | ||
{ | ||
if (self = [super init]) { | ||
target = [_target retain]; | ||
selector = selector; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc; | ||
{ | ||
[target release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (void)dispatch:(id)eventData; | ||
{ | ||
[target performSelectorOnMainThread:selector withObject:eventData waitUntilDone:NO]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// PTPusher.h | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright 2010 LJR Software Limited. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface PTPusher : NSObject { | ||
NSString *APIKey; | ||
NSString *channel; | ||
NSMutableDictionary *eventListeners; | ||
} | ||
@property (nonatomic, readonly) NSString *APIKey; | ||
@property (nonatomic, readonly) NSString *channel; | ||
|
||
- (id)initWithKey:(NSString *)key channel:(NSString *)channelName; | ||
- (void)addEventListener:(NSString *)event target:(id)target selector:(SEL)selector; | ||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// PTPusher.m | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright 2010 LJR Software Limited. All rights reserved. | ||
// | ||
|
||
#import "PTPusher.h" | ||
#import "PTEventListener.h" | ||
|
||
@implementation PTPusher | ||
|
||
@synthesize APIKey; | ||
@synthesize channel; | ||
|
||
- (id)initWithKey:(NSString *)key channel:(NSString *)channelName; | ||
{ | ||
if (self = [super init]) { | ||
APIKey = [key copy]; | ||
channel = [channelName copy]; | ||
eventListeners = [[NSMutableDictionary alloc] init]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)dealloc; | ||
{ | ||
[eventListeners release]; | ||
[APIKey release]; | ||
[channel release]; | ||
[super dealloc]; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Event listening | ||
|
||
- (void)addEventListener:(NSString *)eventName target:(id)target selector:(SEL)selector; | ||
{ | ||
PTEventListener *listener = [[PTEventListener alloc] initWithTarget:target selector:selector]; | ||
|
||
NSMutableArray *listeners = [eventListeners objectForKey:eventName]; | ||
if (listeners == nil) { | ||
listeners = [[[NSMutableArray alloc] init] autorelease]; | ||
} | ||
[listeners addObject:listener]; | ||
[listener release]; | ||
} | ||
|
||
#pragma mark - | ||
#pragma mark Event handling | ||
|
||
- (void)handleEvent:(NSString *)eventName eventData:(id)data; | ||
{ | ||
NSArray *listenersForEvent = [eventListeners objectForKey:eventName]; | ||
for (PTEventListener *listener in listenersForEvent) { | ||
[listener dispatch:data]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// PusherEventsAppDelegate.h | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright LJR Software Limited 2010. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class PusherEventsViewController; | ||
|
||
@interface PusherEventsAppDelegate : NSObject <UIApplicationDelegate> { | ||
UIWindow *window; | ||
PusherEventsViewController *viewController; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UIWindow *window; | ||
@property (nonatomic, retain) IBOutlet PusherEventsViewController *viewController; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// PusherEventsAppDelegate.m | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright LJR Software Limited 2010. All rights reserved. | ||
// | ||
|
||
#import "PusherEventsAppDelegate.h" | ||
#import "PusherEventsViewController.h" | ||
|
||
@implementation PusherEventsAppDelegate | ||
|
||
@synthesize window; | ||
@synthesize viewController; | ||
|
||
|
||
- (void)applicationDidFinishLaunching:(UIApplication *)application { | ||
|
||
// Override point for customization after app launch | ||
[window addSubview:viewController.view]; | ||
[window makeKeyAndVisible]; | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[viewController release]; | ||
[window release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// PusherEventsViewController.h | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright LJR Software Limited 2010. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface PusherEventsViewController : UIViewController { | ||
|
||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// | ||
// PusherEventsViewController.m | ||
// PusherEvents | ||
// | ||
// Created by Luke Redpath on 22/03/2010. | ||
// Copyright LJR Software Limited 2010. All rights reserved. | ||
// | ||
|
||
#import "PusherEventsViewController.h" | ||
|
||
@implementation PusherEventsViewController | ||
|
||
|
||
|
||
/* | ||
// The designated initializer. Override to perform setup that is required before the view is loaded. | ||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { | ||
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { | ||
// Custom initialization | ||
} | ||
return self; | ||
} | ||
*/ | ||
|
||
/* | ||
// Implement loadView to create a view hierarchy programmatically, without using a nib. | ||
- (void)loadView { | ||
} | ||
*/ | ||
|
||
|
||
/* | ||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. | ||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
} | ||
*/ | ||
|
||
|
||
/* | ||
// Override to allow orientations other than the default portrait orientation. | ||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | ||
// Return YES for supported orientations | ||
return (interfaceOrientation == UIInterfaceOrientationPortrait); | ||
} | ||
*/ | ||
|
||
- (void)didReceiveMemoryWarning { | ||
// Releases the view if it doesn't have a superview. | ||
[super didReceiveMemoryWarning]; | ||
|
||
// Release any cached data, images, etc that aren't in use. | ||
} | ||
|
||
- (void)viewDidUnload { | ||
// Release any retained subviews of the main view. | ||
// e.g. self.myOutlet = nil; | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[super dealloc]; | ||
} | ||
|
||
@end |
Oops, something went wrong.