mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
* Headers/Foundation/Foundation.h
* Headers/Foundation/NSOperation.h * Source/GNUmakefile * Source/NSOperation.m: Initial implementation of NSOperation class. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28393 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2e2d640c4d
commit
8ee18b36c7
5 changed files with 240 additions and 0 deletions
|
@ -231,6 +231,7 @@ NSNumberFormatter.m \
|
|||
NSObjCRuntime.m \
|
||||
NSObject.m \
|
||||
NSObject+NSComparisonMethods.m \
|
||||
NSOperation.m \
|
||||
NSPage.m \
|
||||
NSPathUtilities.m \
|
||||
NSPipe.m \
|
||||
|
@ -378,6 +379,7 @@ NSNull.h \
|
|||
NSNumberFormatter.h \
|
||||
NSObjCRuntime.h \
|
||||
NSObject.h \
|
||||
NSOperation.h \
|
||||
NSPathUtilities.h \
|
||||
NSPointerArray.h \
|
||||
NSPointerFunctions.h \
|
||||
|
|
147
Source/NSOperation.m
Normal file
147
Source/NSOperation.m
Normal file
|
@ -0,0 +1,147 @@
|
|||
/**Interface for NSOperation for GNUStep
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Gregory Casamento <greg.casamento@gmail.com>
|
||||
Date: 2009
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
AutogsdocSource: NSOperation.m
|
||||
*/
|
||||
|
||||
#import <Foundation/NSOperation.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSException.h>
|
||||
|
||||
@implementation NSOperation : NSObject
|
||||
// Initialization
|
||||
- (id) init
|
||||
{
|
||||
if((self = [super init]) != nil)
|
||||
{
|
||||
priority = NSOperationQueuePriorityNormal;
|
||||
|
||||
cancelled = NO;
|
||||
concurrent = NO;
|
||||
executing = NO;
|
||||
finished = NO;
|
||||
ready = NO;
|
||||
|
||||
dependencies = [[NSMutableArray alloc] initWithCapacity: 5];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(dependencies);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// Executing the operation
|
||||
- (void) start
|
||||
{
|
||||
executing = YES;
|
||||
finished = NO;
|
||||
|
||||
if([self isConcurrent])
|
||||
{
|
||||
[self main];
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
[self main];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"%@",[localException reason]);
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
executing = NO;
|
||||
finished = YES;
|
||||
}
|
||||
|
||||
- (void) main;
|
||||
{
|
||||
// subclass responsibility...
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
// Cancelling the operation
|
||||
- (void) cancel
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
// Getting the operation status
|
||||
- (BOOL) isCancelled
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isExecuting
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isFinished
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isConcurrent
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isReady
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Managing dependencies
|
||||
- (void) addDependency: (NSOperation *)op
|
||||
{
|
||||
[dependencies addObject: op];
|
||||
}
|
||||
|
||||
- (void) removeDependency: (NSOperation *)op
|
||||
{
|
||||
[dependencies removeObject: op];
|
||||
}
|
||||
|
||||
- (NSArray *)dependencies
|
||||
{
|
||||
return [[NSArray alloc] initWithArray: dependencies];
|
||||
}
|
||||
|
||||
// Prioritization
|
||||
- (NSOperationQueuePriority) queuePriority
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
|
||||
- (void) setQueuePriority: (NSOperationQueuePriority)pri
|
||||
{
|
||||
priority = pri;
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue