Skip to content

Commit

Permalink
Newer version of UKMainThreadProxy (to match iMedia as it happens)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeabdullah committed Nov 25, 2010
1 parent 4581ae0 commit f875d10
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions UKMainThreadProxy.h
Expand Up @@ -23,7 +23,6 @@

#import <Cocoa/Cocoa.h>


// -----------------------------------------------------------------------------
// Categories:
// -----------------------------------------------------------------------------
Expand All @@ -35,7 +34,6 @@

@end


// -----------------------------------------------------------------------------
// Classes:
// -----------------------------------------------------------------------------
Expand All @@ -49,8 +47,11 @@
@interface UKMainThreadProxy : NSObject
{
IBOutlet id target;
BOOL waitForCompletion;
}

-(id) initWithTarget: (id)targ;

-(void) setWaitForCompletion: (BOOL)state;

@end
19 changes: 10 additions & 9 deletions UKMainThreadProxy.m
Expand Up @@ -23,18 +23,24 @@

#import "UKMainThreadProxy.h"


@implementation UKMainThreadProxy

-(id) initWithTarget: (id)targ
{
self = [super init];
if( self )
{
target = targ;
waitForCompletion = YES;
}

return self;
}

-(void) setWaitForCompletion: (BOOL)state
{
waitForCompletion = state;
}

// -----------------------------------------------------------------------------
// Introspection overrides:
Expand All @@ -47,7 +53,6 @@ -(BOOL) respondsToSelector: (SEL)itemAction
return( does || [target respondsToSelector: itemAction] );
}


-(id) performSelector: (SEL)itemAction
{
BOOL does = [super respondsToSelector: itemAction];
Expand All @@ -58,13 +63,12 @@ -(id) performSelector: (SEL)itemAction
[self doesNotRecognizeSelector: itemAction];

[target retain];
[target performSelectorOnMainThread: itemAction withObject: nil waitUntilDone: YES];
[target performSelectorOnMainThread: itemAction withObject: nil waitUntilDone: waitForCompletion];
[target release];

return nil;
}


-(id) performSelector: (SEL)itemAction withObject: (id)obj
{
BOOL does = [super respondsToSelector: itemAction];
Expand All @@ -76,14 +80,13 @@ -(id) performSelector: (SEL)itemAction withObject: (id)obj

[target retain];
[obj retain];
[target performSelectorOnMainThread: itemAction withObject: obj waitUntilDone: YES];
[target performSelectorOnMainThread: itemAction withObject: obj waitUntilDone: waitForCompletion];
[obj release];
[target release];

return nil;
}


// -----------------------------------------------------------------------------
// Forwarding unknown methods to the target:
// -----------------------------------------------------------------------------
Expand All @@ -106,14 +109,13 @@ -(void) forwardInvocation: (NSInvocation*)invocation
{
[invocation retainArguments];
[target retain];
[invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: target waitUntilDone: YES];
[invocation performSelectorOnMainThread: @selector(invokeWithTarget:) withObject: target waitUntilDone: waitForCompletion];
[target release];
}
else
[self doesNotRecognizeSelector: itemAction];
}


// -----------------------------------------------------------------------------
// Safety net:
// -----------------------------------------------------------------------------
Expand All @@ -130,7 +132,6 @@ -(id) copyMainThreadProxy // Just in case someone accidentally sends this messag

@end


// -----------------------------------------------------------------------------
// Shorthand notation for getting a main thread proxy:
// -----------------------------------------------------------------------------
Expand Down

0 comments on commit f875d10

Please sign in to comment.