home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.bin / SourceCode / MiscKit1.2.6 / Headers / misckit / MiscSubprocess.h < prev    next >
Encoding:
Text File  |  1994-05-30  |  4.0 KB  |  151 lines

  1. //
  2. //    MiscSubprocess.h -- a Obj-C wrapper around Unix child processes
  3. //        Originally written by Drew Davidson
  4. //        Copyright (c) 1994 by Drew Davidson.
  5. //        Modified by Don Yacktman for inclusion into the MiscKit.
  6. //        Fixed up by Carl Lindberg and Don Yacktman.
  7. //                Version 1.2.  All rights reserved.
  8. //        This notice may not be removed from this source code.
  9. //
  10. //    This object is included in the MiscKit by permission from the author
  11. //    and its use is governed by the MiscKit license, found in the file
  12. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  13. //    for a list of all applicable permissions and restrictions.
  14. //    
  15.  
  16. /*----------------------------------------------------------------------------
  17.     $Source$
  18.  
  19.   This subprocess object sends/receives data to/from any UNIX
  20.   subprocess asynchronously (via vfork/pipe).
  21.   Its delegate, if any, will receive the following messages:
  22.  
  23.     - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  24.         Sent when the subprocess exits.  If code indicates what status
  25.         will be:
  26.         
  27.             Misc_Exited
  28.                 status is the exit code returned by the process.
  29.                 
  30.             Misc_Stopped
  31.                 status is the signal that caused the subprocess
  32.                 to stop.
  33.                 
  34.             Misc_Signaled
  35.                 status is the signal that caused the subprocess to
  36.                 terminate
  37.                 
  38.             Misc_UnknownEndCode
  39.                 status == 0.
  40.   
  41.     - subprocess:sender output:(char *)buffer;
  42.         sent whenever there is data on the standard output pipe;
  43.         buffer is only valid until next call
  44.  
  45.     - subprocess:sender stderrOutput:(char *)buffer;
  46.         sent whenever there is data on the standard error pipe;
  47.         buffer is only valid until next call.
  48.  
  49.     - subprocess:sender error:(const char *)errorString;
  50.         sent when an error occurs;
  51.         if it ever happens, it's usually only at startup time
  52.         (has nothing to do with errors in the subprocess, but
  53.         rather in starting/stopping/etc. the process)
  54.  
  55.     The object keeps a MiscStringArray of strings to be used as the
  56.     environment for the exec'd subprocess.  It is accessible through
  57.     the environment method.
  58.     
  59.     REVISIONS
  60.     $Log$
  61. ----------------------------------------------------------------------------*/
  62. # import <stdio.h>
  63. # import <objc/Object.h>
  64. # import <misckit/MiscStringArray.h>
  65.  
  66. typedef enum
  67. {    Misc_Exited,
  68.     Misc_Stopped,
  69.     Misc_Signaled,
  70.     Misc_UnknownEndCode
  71. } MiscSubprocessEndCode;
  72.  
  73. @interface MiscSubprocess:Object
  74. {    /*
  75.      * Outlets
  76.      */
  77.     id        delegate;
  78.  
  79.     /*
  80.      * Other instance variables
  81.      */
  82.     id        environment;
  83.     FILE    *fpToChild;
  84.     FILE    *fpFromChild;
  85.     int        stdoutFromChild;
  86.     int        stderrFromChild;
  87.     int        childPid;
  88.     id        stdoutBuffer;
  89.     id        stderrBuffer;
  90.     int        masterPty;
  91.     int        slavePty;
  92.     BOOL    paused;
  93.     BOOL    running;
  94. }
  95.  
  96. - init;
  97. - init:(const char *)aString;
  98. - init:(const char *)aString withDelegate:theDelegate;
  99. - init:(const char *)aString withDelegate:theDelegate
  100.         keepEnvironment:(BOOL)flag;
  101. /*
  102.  * Designated initializer for MiscSubprocess.  If aString is NULL
  103.  * then nothing is executed.  Normally you will want flag==YES, but
  104.  * we leave you the option, Just In Case(TM).
  105.  */
  106. - init:(const char *)aString withDelegate:theDelegate
  107.         keepEnvironment:(BOOL)flag withPtys:(BOOL)ptyFlag;
  108.  
  109. /*
  110.  * Externally callable routine to initiate the execution of
  111.  * the command aString.
  112.  */
  113. - execute:(const char *)aString;
  114. - execute:(const char *)aString withPtys:(BOOL)ptyFlag;
  115.  
  116. /*
  117.  * Called by execute: to perform the exec function.
  118.  * Override to call something other than the default execle().
  119.  */
  120. - execChild:(const char *)aString;
  121.  
  122. - setDelegate:anObject;
  123. - delegate;
  124.  
  125. - environment;
  126.  
  127. - (SEL)outputMethodForBuffer:aBuffer;
  128. - flushBuffer:aString as:aBuffer;
  129. - flushBuffer:aString;
  130.  
  131. - send:(const char *)string withNewline:(BOOL)wantNewline;
  132. - send:(const char *)string;
  133. - (int)pid;
  134. - pause:sender;
  135. - resume:sender;
  136. - (BOOL)isPaused;
  137. - (BOOL)isRunning;
  138. - terminate:sender;
  139. - terminateInput;
  140.  
  141. @end
  142.  
  143. @interface Object(MiscSubprocessDelegate)
  144.  
  145. - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  146. - subprocess:sender output:(const char *) buffer;
  147. - subprocess:sender stderrOutput:(const char *)buffer;
  148. - subprocess:sender error:(const char *)errorString;
  149.  
  150. @end
  151.