/*
Copyright (C) 2002-2003, Jeffrey D. Argast.
The authors make NO WARRANTY or representation, either express or implied,
with respect to this software, its quality, accuracy, merchantability, or
fitness for a particular purpose. This software is provided "AS IS", and you,
its user, assume the entire risk as to its quality and accuracy.
Permission is hereby granted to use, copy, modify, and distribute this
software or portions thereof for any purpose, without fee, subject to these
conditions:
(1) If any part of the source code is distributed, then this
statement must be included, with this copyright and no-warranty notice
unaltered.
(2) Permission for use of this software is granted only if the user accepts
full responsibility for any undesirable consequences; the authors accept
NO LIABILITY for damages of any kind.
*/
#import <Foundation/Foundation.h>
#import "PerforceClient.h"
@interface PerforceAction : NSObject
{
NSString* fClientName;
NSString* fUserName;
id fOwner;
SEL fSelector;
NSTask* fPerforceTask;
int fTerminationReturnCode;
BOOL fWasAborted;
BOOL fWasError;
NSString* fStandardOutput;
NSString* fStandardError;
NSString* fStandardInput;
NSString* fActionDescription;
}
+ (NSTask*) runCommand: (NSArray*) commandAndArgs
stdInString: (NSString*) stdInString
owner: (id) owner
readSelector: (SEL) readSelector
readToEOF:(BOOL)readToEOF
sendStdInToConsole:(BOOL)sendStdInToConsole;
// run p4 with the arguments, and optionally stdInString.
// If readToEOF is YES then readSelector will be called once at
// the end, otherwise readSelector will be called along the way.
// When the data passed to readSelector is empty, the task is complete.
+ (NSArray*) runningActions;
// returns a list of the currently running actions
+ (void) addAction: (PerforceAction*) action;
// called by the perforce actions only
+ (void) removeAction: (PerforceAction*) action;
// called by the perforce actions only
+ (void) abortAllActions;
// abort every action
+ (void) abortAllOwnersActions: (id) owner;
// abort all actions associated with sender
+ (BOOL) isCriticalActionRunning;
// returns YES if a sync, edit, delete, or revert is currently running
- (id) init;
// Initialize using the environment defined user and client
- (id) initWithClient:(NSString*)client user:(NSString*) user;
// Initialize with the given user and client
- (void) runAction:(NSArray*)commandAndArgs
stdInString:(NSString*)stdInString
readToEOF:(BOOL)readToEOF;
// calls the function below with sendStdInToConsole=YES
- (void) runAction:(NSArray*)commandAndArgs
stdInString:(NSString*)stdInString
readToEOF:(BOOL)readToEOF
sendStdInToConsole:(BOOL)sendStdInToConsole;
// implemented in the base class, called by the derived classes to execute the
// command. Puts the action in the action list
- (void) abort;
// called when you no longer want this action to complete. Note that the task
// may have completed but not yet returned.
- (BOOL) isCriticalAction;
// Returns YES if this action is a critical action. The base classs
// returns NO
- (NSString*) getActionDescription;
// returns a string of the command, e.g. p4 sync //...
- (BOOL) wasError;
// returns whether or not there was an error
- (BOOL) wasAborted;
// returns whether or not the task was aborted
- (BOOL) wasSuccess;
// returns YES if not aborted or error
- (NSString*) getOutput;
// returns the output string. may be empty for aborted or errored tasks
- (NSString*) getError;
// will be emtpy if no error
- (NSString*) getInput;
// returns the standard input string the action was created with
- (id) getOwner;
// returns the object that created and spawned the action
- (void) processOutput: (NSString*) perforceOutput;
// called by the base class to process the output
// The base class implementation sends to the console
- (void) processError: (NSString*) perforceError;
// called by the base class if there is an error
// The base class implementation sends to the console
- (void) taskDidComplete;
// called by the notification system when the underlying task
// completed. Removes the action from the action list.
- (void) notifyOwnerTaskIsComplete;
// The base class calls fOwner and fSelector with self.
@end