1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/MYTask.h Wed Apr 08 16:31:19 2009 -0700
1.3 @@ -0,0 +1,78 @@
1.4 +//
1.5 +// MYTask.h
1.6 +// Murky
1.7 +//
1.8 +// Copyright 2008 Jens Alfke. All rights reserved.
1.9 +//
1.10 +
1.11 +#import <Cocoa/Cocoa.h>
1.12 +
1.13 +
1.14 +extern NSString* const MYTaskErrorDomain;
1.15 +extern NSString* const MYTaskExitCodeKey;
1.16 +extern NSString* const MYTaskObjectKey;
1.17 +enum {
1.18 + kMYTaskError = 2
1.19 +};
1.20 +
1.21 +
1.22 +
1.23 +@interface MYTask : NSObject
1.24 +{
1.25 + @private
1.26 + NSString *_command;
1.27 + NSMutableArray *_arguments;
1.28 + NSString *_currentDirectoryPath;
1.29 + NSTask *_task;
1.30 + int _resultCode;
1.31 + NSError *_error;
1.32 + BOOL _ignoreOutput;
1.33 + NSFileHandle *_outHandle, *_errHandle;
1.34 + NSMutableData *_outputData, *_errorData;
1.35 + NSString *_output;
1.36 + NSMutableArray *_modes;
1.37 + BOOL _isRunning, _taskRunning;
1.38 +}
1.39 +
1.40 +- (id) initWithCommand: (NSString*)subcommand, ... NS_REQUIRES_NIL_TERMINATION;
1.41 +
1.42 +/* designated initializer (subclasses can override) */
1.43 +- (id) initWithCommand: (NSString*)subcommand
1.44 + arguments: (NSArray*)arguments;
1.45 +
1.46 +- (id) initWithError: (NSError*)error;
1.47 +
1.48 +- (void) addArgument: (id)argument;
1.49 +- (void) addArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;
1.50 +- (void) addArgumentsFromArray: (NSArray*)arguments;
1.51 +- (void) prependArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;
1.52 +
1.53 +- (void) ignoreOutput;
1.54 +
1.55 +@property (copy) NSString* currentDirectoryPath;
1.56 +
1.57 +- (BOOL) run;
1.58 +- (BOOL) run: (NSError**)outError;
1.59 +
1.60 +- (BOOL) start;
1.61 +- (void) stop;
1.62 +- (BOOL) waitTillFinished;
1.63 +
1.64 +@property (readonly,nonatomic) BOOL isRunning;
1.65 +@property (readonly,retain,nonatomic) NSError* error;
1.66 +@property (readonly,nonatomic) NSString *output, *outputAndError;
1.67 +@property (readonly,nonatomic) NSData *outputData;
1.68 +
1.69 +// protected:
1.70 +
1.71 +/** Subclasses can override this to add arguments or customize the task */
1.72 +- (NSTask*) createTask;
1.73 +
1.74 +/** Sets the error based on the message and parameters. Always returns NO. */
1.75 +- (BOOL) makeError: (NSString*)fmt, ...;
1.76 +
1.77 +/** Called when the task finishes, just before the isRunning property changes back to NO.
1.78 + You can override this to do your own post-processing. */
1.79 +- (void) finished;
1.80 +
1.81 +@end