From 575500fdf2c9b71213a9509e8007579fc1824b4e Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 15 Jul 2009 00:02:34 +0000 Subject: [PATCH] * Headers/Foundation/NSOperation.h * Source/NSOperation.m: Added initial implementation of NSOperationQueue. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28395 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 6 ++++ Headers/Foundation/NSOperation.h | 32 +++++++++++++++++ Source/NSOperation.m | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/ChangeLog b/ChangeLog index ecc1bfc31..1310e87ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2009-07-14 20:02-EDT Gregory John Casamento + + * Headers/Foundation/NSOperation.h + * Source/NSOperation.m: Added initial implementation of + NSOperationQueue. + 2009-07-13 14:15-EDT Gregory John Casamento * Headers/Foundation/Foundation.h diff --git a/Headers/Foundation/NSOperation.h b/Headers/Foundation/NSOperation.h index 3f8afc8f7..b333b1cb9 100644 --- a/Headers/Foundation/NSOperation.h +++ b/Headers/Foundation/NSOperation.h @@ -22,6 +22,7 @@ Boston, MA 02111 USA. AutogsdocSource: NSOperation.m + AutogsdocSource: NSOperationQueue.m */ #import @@ -80,3 +81,34 @@ typedef NSInteger NSOperationQueuePriority; - (NSOperationQueuePriority) queuePriority; - (void) setQueuePriority: (NSOperationQueuePriority)priority; @end + + +/** + * NSOperationQueue + */ + +// Enumerated type for default operation count. +enum { + NSOperationQueueDefaultMaxConcurrentOperationCount = -1 +}; + +// NSOperationQueue +@interface NSOperationQueue : NSObject +{ + NSMutableArray *operations; + BOOL suspended; + NSInteger count; +} + +// status +- (BOOL) isSuspended; +- (void) setSuspended: (BOOL)flag; +- (NSInteger) maxConcurrentOperationCount; +- (void) setMaxConcurrentOperationCount: (NSInteger)cnt; + +// operations +- (void) addOperation: (NSOperation *) op; +- (NSArray *) operations; +- (void) cancelAllOperations; +- (void) waitUntilAllOperationsAreFinished; +@end diff --git a/Source/NSOperation.m b/Source/NSOperation.m index c99609668..7ed95e47b 100644 --- a/Source/NSOperation.m +++ b/Source/NSOperation.m @@ -26,6 +26,7 @@ #import #import +#import #import @implementation NSOperation : NSObject @@ -145,3 +146,63 @@ priority = pri; } @end + +@implementation NSOperationQueue + +- (id) init +{ + if((self = [super init]) != nil) + { + suspended = NO; + count = NSOperationQueueDefaultMaxConcurrentOperationCount; + } + return self; +} + +// status +- (BOOL) isSuspended +{ + return suspended; +} + +- (void) setSuspended: (BOOL)flag +{ + suspended = flag; +} + +- (NSInteger) maxConcurrentOperationCount +{ + return count; +} + +- (void) setMaxConcurrentOperationCount: (NSInteger)cnt +{ + count = cnt; +} + +// operations +- (void) addOperation: (NSOperation *) op +{ + [operations addObject: op]; +} + +- (NSArray *) operations +{ + return [[NSArray alloc] initWithArray: operations]; +} + +- (void) cancelAllOperations +{ + NSEnumerator *en = [operations objectEnumerator]; + id o = nil; + while( (o = [en nextObject]) != nil ) + { + [o cancel]; + } +} + +- (void) waitUntilAllOperationsAreFinished +{ + // not yet implemented... +} +@end