Skip to content

Commit

Permalink
Initial roughed out API, using a target/selector event listener style.
Browse files Browse the repository at this point in the history
Perhaps NSNotification propagation could come later?
  • Loading branch information
lukeredpath committed Mar 22, 2010
0 parents commit 3c0eb03
Show file tree
Hide file tree
Showing 16 changed files with 977 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pbxproj -crlf -diff -merge
9 changes: 9 additions & 0 deletions .gitignore
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
18 changes: 18 additions & 0 deletions Classes/Pusher/PTEventListener.h
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
34 changes: 34 additions & 0 deletions Classes/Pusher/PTEventListener.m
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
24 changes: 24 additions & 0 deletions Classes/Pusher/PTPusher.h
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


61 changes: 61 additions & 0 deletions Classes/Pusher/PTPusher.m
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
22 changes: 22 additions & 0 deletions Classes/PusherEventsAppDelegate.h
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

33 changes: 33 additions & 0 deletions Classes/PusherEventsAppDelegate.m
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
16 changes: 16 additions & 0 deletions Classes/PusherEventsViewController.h
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

65 changes: 65 additions & 0 deletions Classes/PusherEventsViewController.m
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
Loading

0 comments on commit 3c0eb03

Please sign in to comment.