00001 #ifndef CLASSLIB_SUB_PROCESS_H
00002 # define CLASSLIB_SUB_PROCESS_H
00003
00004
00005
00006 # include "classlib/sysapi/system.h"
00007
00008 namespace lat {
00009
00010
00011
00012
00013 class IOChannel;
00014 class Pipe;
00015
00016
00017
00018
00019
00106 class SubProcess
00107 {
00108
00109
00110
00111
00112
00113
00114 public:
00115
00116 enum Flags {
00117 Read = 1,
00118 Write = 2,
00119 First = 4,
00120 Last = 8,
00121 One = First | Last,
00122 Synchronous = 16,
00123 Search = 32,
00124 NoCloseInput = 64,
00125 NoCloseOutput = 128
00126
00127
00128 };
00129
00130 SubProcess (void);
00131 SubProcess (const char **argz, unsigned flags = One);
00132 SubProcess (const char **argz, unsigned flags,
00133 Pipe *pipe, IOChannel *other = 0);
00134 SubProcess (const char **argz, unsigned flags,
00135 SubProcess *input, IOChannel *output = 0);
00136 SubProcess (const char **argz, unsigned flags,
00137 IOChannel *input, IOChannel *output = 0);
00138 virtual ~SubProcess (void);
00139
00140 virtual pid_t run (const char **argz, unsigned flags = One);
00141 virtual pid_t run (const char **argz, unsigned flags,
00142 Pipe *pipe, IOChannel *other = 0);
00143 virtual pid_t run (const char **argz, unsigned flags,
00144 SubProcess *input, IOChannel *output = 0);
00145 virtual pid_t run (const char **argz, unsigned flags,
00146 IOChannel *input, IOChannel *output = 0);
00147
00148 virtual IOChannel * input (void) const;
00149 virtual IOChannel * output (void) const;
00150 virtual Pipe * pipe (void) const;
00151 virtual pid_t pid (void) const;
00152
00153 virtual void detach (void);
00154 virtual void terminate (void);
00155 virtual bool done (void);
00156 virtual int wait (void);
00157
00158 static bool exitNormal (int waitcode);
00159 static bool exitBySignal (int waitcode);
00160 static int exitStatus (int waitcode);
00161 static int exitSignal (int waitcode);
00162
00163 private:
00164 pid_t dorun (const char **argz, unsigned flags,
00165 IOChannel *input, IOChannel *output,
00166 IOChannel *cleanup);
00167 pid_t sysrun (const char **argz, unsigned flags,
00168 IOChannel *input, IOChannel *output,
00169 IOChannel *cleanup);
00170 void sysdetach (void);
00171
00172 int m_status;
00173 IOChannel *m_input;
00174 IOChannel *m_output;
00175 Pipe *m_pipe;
00176 # ifdef _WIN32
00177 void *m_sub;
00178 unsigned long m_pid;
00179 # else
00180 pid_t m_sub;
00181 # endif
00182
00183
00184 SubProcess (const SubProcess &x);
00185 SubProcess &operator= (const SubProcess &x);
00186 };
00187
00188
00189
00190
00191 }
00192 #endif // CLASSLIB_SUB_PROCESS_H