CMS 3D CMS Logo

SubProcess.h

Go to the documentation of this file.
00001 #ifndef CLASSLIB_SUB_PROCESS_H
00002 # define CLASSLIB_SUB_PROCESS_H
00003 
00004 //<<<<<< INCLUDES                                                       >>>>>>
00005 
00006 # include "classlib/sysapi/system.h"
00007 
00008 namespace lat {
00009 //<<<<<< PUBLIC DEFINES                                                 >>>>>>
00010 //<<<<<< PUBLIC CONSTANTS                                               >>>>>>
00011 //<<<<<< PUBLIC TYPES                                                   >>>>>>
00012 
00013 class IOChannel;
00014 class Pipe;
00015 
00016 //<<<<<< PUBLIC VARIABLES                                               >>>>>>
00017 //<<<<<< PUBLIC FUNCTIONS                                               >>>>>>
00018 //<<<<<< CLASS DECLARATIONS                                             >>>>>>
00019 
00106 class SubProcess
00107 {
00108     // FIXME: block SIGPIPE -> EPIPE -> throw? (write only; read -> eof)
00109     // FIXME: Allow redirect of unpiped file descriptors (e.g. output to
00110     //   child -> allow redirect of stderr, stdout)
00111     // FIXME: set options on handle inheritance
00112     // FIXME: set options on env inheritance
00113     // FIXME: wait with timeout?
00114 public:
00115     // FIXME: Merge with/continue from IOFlags?
00116     enum Flags {
00117         Read            = 1,            //< Make a read subprocess chain
00118         Write           = 2,            //< Make a write subprocess chain
00119         First           = 4,            //< First subprocess in a chain
00120         Last            = 8,            //< Last subprocess in a chain
00121         One             = First | Last, //< Single-subprocess chain
00122         Synchronous     = 16,           //< Run synchronously
00123         Search          = 32,           //< Search path for command
00124         NoCloseInput    = 64,           //< Don't close input pipe in parent
00125         NoCloseOutput   = 128           //< Don't close output pipe in parent
00126         // CleanEnv     = 256           //< Clean up safe environment
00127         // CloseFds     = 512           //< Close all "other" file descriptors
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     // undefined, no semantics
00184     SubProcess (const SubProcess &x);
00185     SubProcess &operator= (const SubProcess &x);
00186 };
00187 
00188 //<<<<<< INLINE PUBLIC FUNCTIONS                                        >>>>>>
00189 //<<<<<< INLINE MEMBER FUNCTIONS                                        >>>>>>
00190 
00191 } // namespace lat
00192 #endif // CLASSLIB_SUB_PROCESS_H

Generated on Tue Jun 9 17:38:52 2009 for CMSSW by  doxygen 1.5.4