home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / SourceCode / MiscKit / Headers / misckit / MiscSubprocess.h < prev    next >
Encoding:
Text File  |  1994-03-23  |  3.5 KB  |  141 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. //                Version 1.0.  All rights reserved.
  7. //        This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the author
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14.  
  15. /*----------------------------------------------------------------------------
  16.     $Source$
  17.  
  18.   This subprocess object sends/receives data to/from any UNIX
  19.   subprocess asynchronously (via vfork/pipe).
  20.   Its delegate, if any, will receive the following messages:
  21.  
  22.     - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  23.         Sent when the subprocess exits.  If code indicates what status
  24.         will be:
  25.         
  26.             Misc_Exited
  27.                 status is the exit code returned by the process.
  28.                 
  29.             Misc_Stopped
  30.                 status is the signal that caused the subprocess
  31.                 to stop.
  32.                 
  33.             Misc_Signaled
  34.                 status is the signal that caused the subprocess to
  35.                 terminate
  36.                 
  37.             Misc_UnknownEndCode
  38.                 status == 0.
  39.   
  40.     - subprocess:sender output:(char *)buffer;
  41.         sent whenever there is data on the standard output pipe;
  42.         buffer is only valid until next call
  43.  
  44.     - subprocess:sender stderrOutput:(char *)buffer;
  45.         sent whenever there is data on the standard error pipe;
  46.         buffer is only valid until next call.
  47.  
  48.     - subprocess:sender error:(const char *)errorString;
  49.         sent when an error occurs;
  50.         if it ever happens, it's usually only at startup time
  51.  
  52.     The object keeps a MiscStringArray of strings to be used as the
  53.     environment for the exec'd subprocess.  It is accessible through
  54.     the environment method.
  55.     
  56.     REVISIONS
  57.     $Log$
  58. ----------------------------------------------------------------------------*/
  59. # import <stdio.h>
  60. # import <objc/Object.h>
  61. # import <misckit/MiscStringArray.h>
  62.  
  63. typedef enum
  64. {    Misc_Exited,
  65.     Misc_Stopped,
  66.     Misc_Signaled,
  67.     Misc_UnknownEndCode
  68. } MiscSubprocessEndCode;
  69.  
  70. @interface MiscSubprocess:Object
  71. {    /*
  72.      * Outlets
  73.      */
  74.     id        delegate;
  75.  
  76.     /*
  77.      * Other instance variables
  78.      */
  79.     id        environment;
  80.     FILE    *fpToChild;
  81.     FILE    *fpFromChild;
  82.     int        stdoutFromChild;
  83.     int        stderrFromChild;
  84.     int        childPid;
  85.     id        stdoutBuffer;
  86.     id        stderrBuffer;
  87.     BOOL    paused;
  88.     BOOL    running;
  89. }
  90.  
  91. - init;
  92. - init:(const char *)aString;
  93.  
  94. /*
  95.  * Designated initializer for MiscSubprocess.  If aString is NULL
  96.  * then nothing is executed.
  97.  */
  98. - init:(const char *)aString withDelegate:theDelegate;
  99.  
  100. /*
  101.  * Externally callable routine to initiate the execution of
  102.  * the command aString.
  103.  */
  104. - execute:(const char *)aString;
  105.  
  106. /*
  107.  * Called by execute: to perform the exec function.
  108.  * Override to call something other than the default execle().
  109.  */
  110. - execChild:(const char *)aString;
  111.  
  112. - setDelegate:anObject;
  113. - delegate;
  114.  
  115. - environment;
  116.  
  117. - (SEL)outputMethodForBuffer:aBuffer;
  118. - flushBuffer:aString as:aBuffer;
  119. - flushBuffer:aString;
  120.  
  121. - send:(const char *)string withNewline:(BOOL)wantNewline;
  122. - send:(const char *)string;
  123. - (int)pid;
  124. - pause:sender;
  125. - resume:sender;
  126. - (BOOL)isPaused;
  127. - (BOOL)isRunning;
  128. - terminate:sender;
  129. - terminateInput;
  130.  
  131. @end
  132.  
  133. @interface Object(MiscSubprocessDelegate)
  134.  
  135. - subprocess:sender done:(int)status :(MiscSubprocessEndCode)code;
  136. - subprocess:sender output:(const char *) buffer;
  137. - subprocess:sender stderrOutput:(const char *)buffer;
  138. - subprocess:sender error:(const char *)errorString;
  139.  
  140. @end
  141.