pipechan.h

Go to the documentation of this file.
00001 /*
00002  * pipechan.h
00003  *
00004  * Sub-process with communications using pipe I/O channel class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: pipechan.h,v $
00030  * Revision 1.24  2006/06/21 03:28:41  csoutheren
00031  * Various cleanups thanks for Frederic Heem
00032  *
00033  * Revision 1.23  2005/11/25 03:43:47  csoutheren
00034  * Fixed function argument comments to be compatible with Doxygen
00035  *
00036  * Revision 1.22  2003/09/17 05:41:59  csoutheren
00037  * Removed recursive includes
00038  *
00039  * Revision 1.21  2003/09/17 01:18:02  csoutheren
00040  * Removed recursive include file system and removed all references
00041  * to deprecated coooperative threading support
00042  *
00043  * Revision 1.20  2002/09/16 01:08:59  robertj
00044  * Added #define so can select if #pragma interface/implementation is used on
00045  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00046  *
00047  * Revision 1.19  2001/05/22 12:49:32  robertj
00048  * Did some seriously wierd rewrite of platform headers to eliminate the
00049  *   stupid GNU compiler warning about braces not matching.
00050  *
00051  * Revision 1.18  1999/03/09 02:59:50  robertj
00052  * Changed comments to doc++ compatible documentation.
00053  *
00054  * Revision 1.17  1999/02/16 08:11:09  robertj
00055  * MSVC 6.0 compatibility changes.
00056  *
00057  * Revision 1.16  1998/11/02 10:06:39  robertj
00058  * Added capability of pip output to go to stdout/stderr.
00059  *
00060  * Revision 1.15  1998/10/30 10:42:29  robertj
00061  * Better function arrangement for multi platforming.
00062  *
00063  * Revision 1.14  1998/10/29 11:29:17  robertj
00064  * Added ability to set environment in sub-process.
00065  *
00066  * Revision 1.13  1998/10/26 09:11:05  robertj
00067  * Added ability to separate out stdout from stderr on pipe channels.
00068  *
00069  * Revision 1.12  1998/09/23 06:21:08  robertj
00070  * Added open source copyright license.
00071  *
00072  * Revision 1.11  1997/01/03 05:25:05  robertj
00073  * Added Wait and Kill functions.
00074  *
00075  * Revision 1.10  1996/03/31 08:50:51  robertj
00076  * Changed string list to array.
00077  * Added function to idicate if sub-process is running.
00078  *
00079  * Revision 1.9  1995/07/31 12:15:45  robertj
00080  * Removed PContainer from PChannel ancestor.
00081  *
00082  * Revision 1.8  1995/06/17 11:12:53  robertj
00083  * Documentation update.
00084  *
00085  * Revision 1.7  1995/03/14 12:42:02  robertj
00086  * Updated documentation to use HTML codes.
00087  *
00088  * Revision 1.6  1995/01/09  12:39:01  robertj
00089  * Documentation.
00090  *
00091  * Revision 1.5  1994/10/23  04:50:55  robertj
00092  * Further refinement of semantics after implementation.
00093  *
00094  * Revision 1.4  1994/09/25  10:43:19  robertj
00095  * Added more implementation.
00096  *
00097  * Revision 1.3  1994/08/23  11:32:52  robertj
00098  * Oops
00099  *
00100  * Revision 1.2  1994/08/22  00:46:48  robertj
00101  * Added pragma fro GNU C++ compiler.
00102  *
00103  * Revision 1.1  1994/04/20  12:17:44  robertj
00104  * Initial revision
00105  *
00106  */
00107 
00108 #ifndef _PPIPECHANNEL
00109 #define _PPIPECHANNEL
00110 
00111 #ifdef P_USE_PRAGMA
00112 #pragma interface
00113 #endif
00114 
00115 #include <ptlib/channel.h>
00116 
00117 
00144 class PChannel;
00145 
00146 
00147 class PPipeChannel : public PChannel
00148 {
00149   PCLASSINFO(PPipeChannel, PChannel);
00150 
00151   public:
00154 
00155     enum OpenMode {
00157       ReadOnly,   
00159       WriteOnly,  
00161       ReadWrite,  
00164       ReadWriteStd
00165     };
00166 
00169     PPipeChannel();
00175     PPipeChannel(
00176       const PString & subProgram,  
00177       OpenMode mode = ReadWrite,   
00178       BOOL searchPath = TRUE,      
00179       BOOL stderrSeparate = FALSE  
00180     );
00186     PPipeChannel(
00187       const PString & subProgram,  
00188       const PStringArray & argumentList, 
00189       OpenMode mode = ReadWrite,   
00190       BOOL searchPath = TRUE,      
00191       BOOL stderrSeparate = FALSE  
00192     );
00198     PPipeChannel(
00199       const PString & subProgram,  
00200       const PStringToString & environment, 
00201       OpenMode mode = ReadWrite,   
00202       BOOL searchPath = TRUE,      
00203       BOOL stderrSeparate = FALSE  
00204     );
00210     PPipeChannel(
00211       const PString & subProgram,  
00212       const PStringArray & argumentList, 
00213       const PStringToString & environment, 
00214       OpenMode mode = ReadWrite,   
00215       BOOL searchPath = TRUE,      
00216       BOOL stderrSeparate = FALSE  
00217     );
00218 
00220     ~PPipeChannel();
00222 
00232     Comparison Compare(
00233       const PObject & obj   
00234     ) const;
00236 
00237 
00245     virtual PString GetName() const;
00246 
00263     virtual BOOL Read(
00264       void * buf,   
00265       PINDEX len    
00266     );
00267 
00282     virtual BOOL Write(
00283       const void * buf, 
00284       PINDEX len        
00285     );
00286 
00295     virtual BOOL Close();
00297 
00301     BOOL Open(
00302       const PString & subProgram,  
00303       OpenMode mode = ReadWrite,   
00304       BOOL searchPath = TRUE,      
00305       BOOL stderrSeparate = FALSE  
00306     );
00308     BOOL Open(
00309       const PString & subProgram,  
00310       const PStringArray & argumentList, 
00311       OpenMode mode = ReadWrite,   
00312       BOOL searchPath = TRUE,      
00313       BOOL stderrSeparate = FALSE  
00314     );
00316     BOOL Open(
00317       const PString & subProgram,  
00318       const PStringToString & environment, 
00319       OpenMode mode = ReadWrite,   
00320       BOOL searchPath = TRUE,      
00321       BOOL stderrSeparate = FALSE  
00322     );
00360     BOOL Open(
00361       const PString & subProgram,  
00362       const PStringArray & argumentList, 
00363       const PStringToString & environment, 
00364       OpenMode mode = ReadWrite,   
00365       BOOL searchPath = TRUE,      
00366       BOOL stderrSeparate = FALSE  
00367     );
00368 
00374     const PFilePath & GetSubProgram() const;
00375 
00389     BOOL Execute();
00390 
00399     BOOL IsRunning() const;
00400 
00406     int GetReturnCode() const;
00407 
00413     int WaitForTermination();
00414     
00421     int WaitForTermination(
00422       const PTimeInterval & timeout  
00423     );
00424 
00432     BOOL Kill(
00433       int signal = 9  
00434     );
00435 
00445     BOOL ReadStandardError(
00446       PString & errors,   
00447       BOOL wait = FALSE   
00448     );
00449 
00456     static BOOL CanReadAndWrite();
00458 
00459 
00460   protected:
00461     // Member variables
00463     PFilePath subProgName;
00464 
00465 
00466   private:
00467     BOOL PlatformOpen(const PString & subProgram,
00468                       const PStringArray & arguments,
00469                       OpenMode mode,
00470                       BOOL searchPath,
00471                       BOOL stderrSeparate,
00472                       const PStringToString * environment);
00473 
00474 
00475 // Include platform dependent part of class
00476 #ifdef _WIN32
00477 #include "msos/ptlib/pipechan.h"
00478 #else
00479 #include "unix/ptlib/pipechan.h"
00480 #endif
00481 };
00482 
00483 #endif
00484 
00485 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1