home *** CD-ROM | disk | FTP | other *** search
- //
- // MiscSubprocess.h -- a Obj-C wrapper around Unix child processes
- // Originally written by Drew Davidson
- // Copyright (c) 1994 by Drew Davidson.
- // Modified by Don Yacktman for inclusion into the MiscKit.
- // Version 1.0. All rights reserved.
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the author
- // and its use is governed by the MiscKit license, found in the file
- // "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
-
- /*----------------------------------------------------------------------------
- $Source$
-
- This subprocess object sends/receives data to/from any UNIX
- subprocess asynchronously (via vfork/pipe).
- Its delegate, if any, will receive the following messages:
-
- - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
- Sent when the subprocess exits. If code indicates what status
- will be:
-
- Misc_Exited
- status is the exit code returned by the process.
-
- Misc_Stopped
- status is the signal that caused the subprocess
- to stop.
-
- Misc_Signaled
- status is the signal that caused the subprocess to
- terminate
-
- Misc_UnknownEndCode
- status == 0.
-
- - subprocess:sender output:(char *)buffer;
- sent whenever there is data on the standard output pipe;
- buffer is only valid until next call
-
- - subprocess:sender stderrOutput:(char *)buffer;
- sent whenever there is data on the standard error pipe;
- buffer is only valid until next call.
-
- - subprocess:sender error:(const char *)errorString;
- sent when an error occurs;
- if it ever happens, it's usually only at startup time
-
- The object keeps a MiscStringArray of strings to be used as the
- environment for the exec'd subprocess. It is accessible through
- the environment method.
-
- REVISIONS
- $Log$
- ----------------------------------------------------------------------------*/
- # import <stdio.h>
- # import <objc/Object.h>
- # import <misckit/MiscStringArray.h>
-
- typedef enum
- { Misc_Exited,
- Misc_Stopped,
- Misc_Signaled,
- Misc_UnknownEndCode
- } MiscSubprocessEndCode;
-
- @interface MiscSubprocess:Object
- { /*
- * Outlets
- */
- id delegate;
-
- /*
- * Other instance variables
- */
- id environment;
- FILE *fpToChild;
- FILE *fpFromChild;
- int stdoutFromChild;
- int stderrFromChild;
- int childPid;
- id stdoutBuffer;
- id stderrBuffer;
- BOOL paused;
- BOOL running;
- }
-
- - init;
- - init:(const char *)aString;
-
- /*
- * Designated initializer for MiscSubprocess. If aString is NULL
- * then nothing is executed.
- */
- - init:(const char *)aString withDelegate:theDelegate;
-
- /*
- * Externally callable routine to initiate the execution of
- * the command aString.
- */
- - execute:(const char *)aString;
-
- /*
- * Called by execute: to perform the exec function.
- * Override to call something other than the default execle().
- */
- - execChild:(const char *)aString;
-
- - setDelegate:anObject;
- - delegate;
-
- - environment;
-
- - (SEL)outputMethodForBuffer:aBuffer;
- - flushBuffer:aString as:aBuffer;
- - flushBuffer:aString;
-
- - send:(const char *)string withNewline:(BOOL)wantNewline;
- - send:(const char *)string;
- - (int)pid;
- - pause:sender;
- - resume:sender;
- - (BOOL)isPaused;
- - (BOOL)isRunning;
- - terminate:sender;
- - terminateInput;
-
- @end
-
- @interface Object(MiscSubprocessDelegate)
-
- - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
- - subprocess:sender output:(const char *) buffer;
- - subprocess:sender stderrOutput:(const char *)buffer;
- - subprocess:sender error:(const char *)errorString;
-
- @end
-