Skip to content
Browse files

Give KSPerformOnThreadOperation its own file

  • Loading branch information...
1 parent 03ae387 commit 2a5850a3be3d0e23ed43207b35254569ea8a5aaf @mikeabdullah mikeabdullah committed Jul 2, 2011
Showing with 115 additions and 103 deletions.
  1. +27 −0 KSPerformOnThreadOperation.h
  2. +88 −0 KSPerformOnThreadOperation.m
  3. +0 −21 KSThreadProxy.h
  4. +0 −82 KSThreadProxy.m
View
27 KSPerformOnThreadOperation.h
@@ -0,0 +1,27 @@
+//
+// KSPerformOnThreadOperation.h
+// Sandvox
+//
+// Created by Mike on 02/07/2011.
+// Copyright 2011 Karelia Software. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface KSPerformOnThreadOperation : NSOperation
+{
+@private
+ NSOperation *_operation;
+ NSThread *_thread;
+}
+
+// Thread may be nil to signify main
+- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
+
+@property(nonatomic, retain, readonly) NSOperation *targetOperation;
+
+// A KSPerformOnThreadOperation is only ready once the operation it contains is
+- (BOOL)isReady;
+
+@end
View
88 KSPerformOnThreadOperation.m
@@ -0,0 +1,88 @@
+//
+// KSPerformOnThreadOperation.m
+// Sandvox
+//
+// Created by Mike on 02/07/2011.
+// Copyright 2011 Karelia Software. All rights reserved.
+//
+
+#import "KSPerformOnThreadOperation.h"
+
+
+@implementation KSPerformOnThreadOperation
+
+static void *sIsReadyObservationContext = &sIsReadyObservationContext;
+
+- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
+{
+ OBPRECONDITION(operation);
+
+ if (self = [self init])
+ {
+ _operation = [operation retain];
+ _thread = [_thread retain];
+
+ [_operation addObserver:self
+ forKeyPath:@"isReady"
+ options:NSKeyValueObservingOptionPrior
+ context:sIsReadyObservationContext];
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [_operation removeObserver:self forKeyPath:@"isReady"];
+
+ [_operation release];
+ [_thread release];
+
+ [super dealloc];
+}
+
+@synthesize targetOperation = _operation;
+
+- (void)main
+{
+ [(NSOperation *)[_operation ks_proxyOnThread:_thread waitUntilDone:NO] start];
+}
+
+#pragma mark Readiness
+
+- (BOOL)isReady
+{
+ return [super isReady] && [_operation isReady];
+}
++ (NSSet *)keyPathsForValuesAffectingIsReady;
+{
+ NSSet *result = [NSSet setWithObject:@"targetOperation.isReady"];
+
+ if ([NSOperation respondsToSelector:_cmd])
+ {
+ result = [result setByAddingObjectsFromSet:[NSOperation performSelector:_cmd]];
+ }
+
+ return result;
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
+{
+ if (context == sIsReadyObservationContext)
+ {
+ if ([[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
+ {
+ [self willChangeValueForKey:@"isReady"];
+ }
+ else
+ {
+ [self didChangeValueForKey:@"isReady"];
+ }
+ }
+ else
+ {
+ [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+ }
+}
+
+@end
View
21 KSThreadProxy.h
@@ -47,24 +47,3 @@
@end
-#pragma mark -
-
-
-@interface KSPerformOnThreadOperation : NSOperation
-{
- @private
- NSOperation *_operation;
- NSThread *_thread;
-}
-
-// Thread may be nil to signify main
-- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
-
-@property(nonatomic, retain, readonly) NSOperation *targetOperation;
-
-// A KSPerformOnThreadOperation is only ready once the operation it contains is
-- (BOOL)isReady;
-
-@end
-
-
View
82 KSThreadProxy.m
@@ -144,85 +144,3 @@ - (id)ks_proxyOnThread:(NSThread *)thread waitUntilDone:(BOOL)waitUntilDone;
@end
-#pragma mark -
-
-
-@implementation KSPerformOnThreadOperation
-
-static void *sIsReadyObservationContext = &sIsReadyObservationContext;
-
-- (id)initWithOperation:(NSOperation *)operation thread:(NSThread *)thread;
-{
- OBPRECONDITION(operation);
-
- if (self = [self init])
- {
- _operation = [operation retain];
- _thread = [_thread retain];
-
- [_operation addObserver:self
- forKeyPath:@"isReady"
- options:NSKeyValueObservingOptionPrior
- context:sIsReadyObservationContext];
- }
-
- return self;
-}
-
-- (void)dealloc
-{
- [_operation removeObserver:self forKeyPath:@"isReady"];
-
- [_operation release];
- [_thread release];
-
- [super dealloc];
-}
-
-@synthesize targetOperation = _operation;
-
-- (void)main
-{
- [(NSOperation *)[_operation ks_proxyOnThread:_thread waitUntilDone:NO] start];
-}
-
-#pragma mark Readiness
-
-- (BOOL)isReady
-{
- return [super isReady] && [_operation isReady];
-}
-+ (NSSet *)keyPathsForValuesAffectingIsReady;
-{
- NSSet *result = [NSSet setWithObject:@"targetOperation.isReady"];
-
- if ([NSOperation respondsToSelector:_cmd])
- {
- result = [result setByAddingObjectsFromSet:[NSOperation performSelector:_cmd]];
- }
-
- return result;
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
-{
- if (context == sIsReadyObservationContext)
- {
- if ([[change objectForKey:NSKeyValueChangeNotificationIsPriorKey] boolValue])
- {
- [self willChangeValueForKey:@"isReady"];
- }
- else
- {
- [self didChangeValueForKey:@"isReady"];
- }
- }
- else
- {
- [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
- }
-}
-
-@end
-
-

0 comments on commit 2a5850a

Please sign in to comment.
Something went wrong with that request. Please try again.