MYTask.h
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
parent 20 5a71993a1a70
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
     1 //
     2 //  MYTask.h
     3 //  Murky
     4 //
     5 //  Copyright 2008 Jens Alfke. All rights reserved.
     6 //
     7 
     8 #import <Cocoa/Cocoa.h>
     9 
    10 
    11 extern NSString* const MYTaskErrorDomain;
    12 extern NSString* const MYTaskExitCodeKey;
    13 extern NSString* const MYTaskObjectKey;
    14 enum {
    15     kMYTaskError = 2
    16 };
    17 
    18 
    19 
    20 @interface MYTask : NSObject 
    21 {
    22     @private
    23     NSString *_command;
    24     NSMutableArray *_arguments;
    25     NSString *_currentDirectoryPath;
    26     NSTask *_task;
    27     int _resultCode;
    28     NSError *_error;
    29     BOOL _ignoreOutput;
    30     NSFileHandle *_outHandle, *_errHandle;
    31     NSMutableData *_outputData, *_errorData;
    32     NSString *_output;
    33     NSMutableArray *_modes;
    34     BOOL _isRunning, _taskRunning;
    35 }
    36 
    37 - (id) initWithCommand: (NSString*)subcommand, ... NS_REQUIRES_NIL_TERMINATION;
    38 
    39 /* designated initializer (subclasses can override) */
    40 - (id) initWithCommand: (NSString*)subcommand
    41              arguments: (NSArray*)arguments;
    42 
    43 - (id) initWithError: (NSError*)error;
    44 
    45 - (void) addArgument: (id)argument;
    46 - (void) addArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;
    47 - (void) addArgumentsFromArray: (NSArray*)arguments;
    48 - (void) prependArguments: (id)arg1, ... NS_REQUIRES_NIL_TERMINATION;
    49 
    50 - (void) ignoreOutput;
    51 
    52 @property (copy) NSString* currentDirectoryPath;
    53 
    54 /** Prettified description of command string. Doesn't do full shell-style quoting, though. */
    55 - (NSString*) commandLine;
    56 
    57 - (BOOL) run;
    58 - (BOOL) run: (NSError**)outError;
    59 
    60 - (BOOL) start;
    61 - (void) stop;
    62 - (BOOL) waitTillFinished;
    63 
    64 @property (readonly,nonatomic) BOOL isRunning;
    65 @property (readonly,retain,nonatomic) NSError* error;
    66 @property (readonly,nonatomic) NSString *output, *outputAndError;
    67 @property (readonly,nonatomic) NSData *outputData;
    68 
    69 // protected:
    70 
    71 /** Subclasses can override this to add arguments or customize the task */
    72 - (NSTask*) createTask;
    73 
    74 /** Sets the error based on the message and parameters. Always returns NO. */
    75 - (BOOL) makeError: (NSString*)fmt, ...;
    76 
    77 /** Called when the task finishes, just before the isRunning property changes back to NO.
    78     You can override this to do your own post-processing. */
    79 - (void) finished;
    80 
    81 @end