mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +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
974a65cb15
commit
ee3edf222b
5 changed files with 240 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2009-07-13 14:15-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
|
|
||||||
|
* Headers/Foundation/Foundation.h
|
||||||
|
* Headers/Foundation/NSOperation.h
|
||||||
|
* Source/GNUmakefile
|
||||||
|
* Source/NSOperation.m: Initial implementation of NSOperation
|
||||||
|
class.
|
||||||
|
|
||||||
2009-07-11 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-07-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSConcreteMapTable.m: Add some comments.
|
* Source/NSConcreteMapTable.m: Add some comments.
|
||||||
|
|
|
@ -84,6 +84,7 @@
|
||||||
#import <Foundation/NSNetServices.h>
|
#import <Foundation/NSNetServices.h>
|
||||||
#import <Foundation/NSNull.h>
|
#import <Foundation/NSNull.h>
|
||||||
#import <Foundation/NSNumberFormatter.h>
|
#import <Foundation/NSNumberFormatter.h>
|
||||||
|
#import <Foundation/NSOperation.h>
|
||||||
#import <Foundation/NSPathUtilities.h>
|
#import <Foundation/NSPathUtilities.h>
|
||||||
#import <Foundation/NSPointerArray.h>
|
#import <Foundation/NSPointerArray.h>
|
||||||
#import <Foundation/NSPointerFunctions.h>
|
#import <Foundation/NSPointerFunctions.h>
|
||||||
|
|
82
Headers/Foundation/NSOperation.h
Normal file
82
Headers/Foundation/NSOperation.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/**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/NSObject.h>
|
||||||
|
|
||||||
|
@class NSMutableArray;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NSOperationQueuePriorityVeryLow = -8,
|
||||||
|
NSOperationQueuePriorityLow = -4,
|
||||||
|
NSOperationQueuePriorityNormal = 0,
|
||||||
|
NSOperationQueuePriorityHigh = 4,
|
||||||
|
NSOperationQueuePriorityVeryHigh = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef NSInteger NSOperationQueuePriority;
|
||||||
|
|
||||||
|
@interface NSOperation : NSObject
|
||||||
|
{
|
||||||
|
// Priority...
|
||||||
|
NSOperationQueuePriority priority;
|
||||||
|
|
||||||
|
// Status...
|
||||||
|
BOOL cancelled;
|
||||||
|
BOOL concurrent;
|
||||||
|
BOOL executing;
|
||||||
|
BOOL finished;
|
||||||
|
BOOL ready;
|
||||||
|
|
||||||
|
// Dependencies
|
||||||
|
NSMutableArray *dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
- (id) init;
|
||||||
|
|
||||||
|
// Executing the operation
|
||||||
|
- (void) start;
|
||||||
|
- (void) main;
|
||||||
|
|
||||||
|
// Cancelling the operation
|
||||||
|
- (void) cancel;
|
||||||
|
|
||||||
|
// Getting the operation status
|
||||||
|
- (BOOL) isCancelled;
|
||||||
|
- (BOOL) isExecuting;
|
||||||
|
- (BOOL) isFinished;
|
||||||
|
- (BOOL) isConcurrent;
|
||||||
|
- (BOOL) isReady;
|
||||||
|
|
||||||
|
// Managing dependencies
|
||||||
|
- (void) addDependency: (NSOperation *)op;
|
||||||
|
- (void) removeDependency: (NSOperation *)op;
|
||||||
|
- (NSArray *)dependencies;
|
||||||
|
|
||||||
|
// Prioritization
|
||||||
|
- (NSOperationQueuePriority) queuePriority;
|
||||||
|
- (void) setQueuePriority: (NSOperationQueuePriority)priority;
|
||||||
|
@end
|
|
@ -231,6 +231,7 @@ NSNumberFormatter.m \
|
||||||
NSObjCRuntime.m \
|
NSObjCRuntime.m \
|
||||||
NSObject.m \
|
NSObject.m \
|
||||||
NSObject+NSComparisonMethods.m \
|
NSObject+NSComparisonMethods.m \
|
||||||
|
NSOperation.m \
|
||||||
NSPage.m \
|
NSPage.m \
|
||||||
NSPathUtilities.m \
|
NSPathUtilities.m \
|
||||||
NSPipe.m \
|
NSPipe.m \
|
||||||
|
@ -378,6 +379,7 @@ NSNull.h \
|
||||||
NSNumberFormatter.h \
|
NSNumberFormatter.h \
|
||||||
NSObjCRuntime.h \
|
NSObjCRuntime.h \
|
||||||
NSObject.h \
|
NSObject.h \
|
||||||
|
NSOperation.h \
|
||||||
NSPathUtilities.h \
|
NSPathUtilities.h \
|
||||||
NSPointerArray.h \
|
NSPointerArray.h \
|
||||||
NSPointerFunctions.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