PWLib
1.10.10
|
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.23 2005/11/25 03:43:47 csoutheren 00031 * Fixed function argument comments to be compatible with Doxygen 00032 * 00033 * Revision 1.22 2003/09/17 05:41:59 csoutheren 00034 * Removed recursive includes 00035 * 00036 * Revision 1.21 2003/09/17 01:18:02 csoutheren 00037 * Removed recursive include file system and removed all references 00038 * to deprecated coooperative threading support 00039 * 00040 * Revision 1.20 2002/09/16 01:08:59 robertj 00041 * Added #define so can select if #pragma interface/implementation is used on 00042 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00043 * 00044 * Revision 1.19 2001/05/22 12:49:32 robertj 00045 * Did some seriously wierd rewrite of platform headers to eliminate the 00046 * stupid GNU compiler warning about braces not matching. 00047 * 00048 * Revision 1.18 1999/03/09 02:59:50 robertj 00049 * Changed comments to doc++ compatible documentation. 00050 * 00051 * Revision 1.17 1999/02/16 08:11:09 robertj 00052 * MSVC 6.0 compatibility changes. 00053 * 00054 * Revision 1.16 1998/11/02 10:06:39 robertj 00055 * Added capability of pip output to go to stdout/stderr. 00056 * 00057 * Revision 1.15 1998/10/30 10:42:29 robertj 00058 * Better function arrangement for multi platforming. 00059 * 00060 * Revision 1.14 1998/10/29 11:29:17 robertj 00061 * Added ability to set environment in sub-process. 00062 * 00063 * Revision 1.13 1998/10/26 09:11:05 robertj 00064 * Added ability to separate out stdout from stderr on pipe channels. 00065 * 00066 * Revision 1.12 1998/09/23 06:21:08 robertj 00067 * Added open source copyright license. 00068 * 00069 * Revision 1.11 1997/01/03 05:25:05 robertj 00070 * Added Wait and Kill functions. 00071 * 00072 * Revision 1.10 1996/03/31 08:50:51 robertj 00073 * Changed string list to array. 00074 * Added function to idicate if sub-process is running. 00075 * 00076 * Revision 1.9 1995/07/31 12:15:45 robertj 00077 * Removed PContainer from PChannel ancestor. 00078 * 00079 * Revision 1.8 1995/06/17 11:12:53 robertj 00080 * Documentation update. 00081 * 00082 * Revision 1.7 1995/03/14 12:42:02 robertj 00083 * Updated documentation to use HTML codes. 00084 * 00085 * Revision 1.6 1995/01/09 12:39:01 robertj 00086 * Documentation. 00087 * 00088 * Revision 1.5 1994/10/23 04:50:55 robertj 00089 * Further refinement of semantics after implementation. 00090 * 00091 * Revision 1.4 1994/09/25 10:43:19 robertj 00092 * Added more implementation. 00093 * 00094 * Revision 1.3 1994/08/23 11:32:52 robertj 00095 * Oops 00096 * 00097 * Revision 1.2 1994/08/22 00:46:48 robertj 00098 * Added pragma fro GNU C++ compiler. 00099 * 00100 * Revision 1.1 1994/04/20 12:17:44 robertj 00101 * Initial revision 00102 * 00103 */ 00104 00105 #ifndef _PPIPECHANNEL 00106 #define _PPIPECHANNEL 00107 00108 #ifdef P_USE_PRAGMA 00109 #pragma interface 00110 #endif 00111 00112 00138 class PPipeChannel : public PChannel 00139 { 00140 PCLASSINFO(PPipeChannel, PChannel); 00141 00142 public: 00145 00146 enum OpenMode { 00148 ReadOnly, 00150 WriteOnly, 00152 ReadWrite, 00155 ReadWriteStd 00156 }; 00157 00160 PPipeChannel(); 00166 PPipeChannel( 00167 const PString & subProgram, 00168 OpenMode mode = ReadWrite, 00169 BOOL searchPath = TRUE, 00170 BOOL stderrSeparate = FALSE 00171 ); 00177 PPipeChannel( 00178 const PString & subProgram, 00179 const PStringArray & argumentList, 00180 OpenMode mode = ReadWrite, 00181 BOOL searchPath = TRUE, 00182 BOOL stderrSeparate = FALSE 00183 ); 00189 PPipeChannel( 00190 const PString & subProgram, 00191 const PStringToString & environment, 00192 OpenMode mode = ReadWrite, 00193 BOOL searchPath = TRUE, 00194 BOOL stderrSeparate = FALSE 00195 ); 00201 PPipeChannel( 00202 const PString & subProgram, 00203 const PStringArray & argumentList, 00204 const PStringToString & environment, 00205 OpenMode mode = ReadWrite, 00206 BOOL searchPath = TRUE, 00207 BOOL stderrSeparate = FALSE 00208 ); 00209 00211 ~PPipeChannel(); 00213 00223 Comparison Compare( 00224 const PObject & obj 00225 ) const; 00227 00228 00236 virtual PString GetName() const; 00237 00254 virtual BOOL Read( 00255 void * buf, 00256 PINDEX len 00257 ); 00258 00273 virtual BOOL Write( 00274 const void * buf, 00275 PINDEX len 00276 ); 00277 00286 virtual BOOL Close(); 00288 00292 BOOL Open( 00293 const PString & subProgram, 00294 OpenMode mode = ReadWrite, 00295 BOOL searchPath = TRUE, 00296 BOOL stderrSeparate = FALSE 00297 ); 00299 BOOL Open( 00300 const PString & subProgram, 00301 const PStringArray & argumentList, 00302 OpenMode mode = ReadWrite, 00303 BOOL searchPath = TRUE, 00304 BOOL stderrSeparate = FALSE 00305 ); 00307 BOOL Open( 00308 const PString & subProgram, 00309 const PStringToString & environment, 00310 OpenMode mode = ReadWrite, 00311 BOOL searchPath = TRUE, 00312 BOOL stderrSeparate = FALSE 00313 ); 00351 BOOL Open( 00352 const PString & subProgram, 00353 const PStringArray & argumentList, 00354 const PStringToString & environment, 00355 OpenMode mode = ReadWrite, 00356 BOOL searchPath = TRUE, 00357 BOOL stderrSeparate = FALSE 00358 ); 00359 00365 const PFilePath & GetSubProgram() const; 00366 00380 BOOL Execute(); 00381 00390 BOOL IsRunning() const; 00391 00397 int GetReturnCode() const; 00398 00404 int WaitForTermination(); 00405 00412 int WaitForTermination( 00413 const PTimeInterval & timeout 00414 ); 00415 00423 BOOL Kill( 00424 int signal = 9 00425 ); 00426 00436 BOOL ReadStandardError( 00437 PString & errors, 00438 BOOL wait = FALSE 00439 ); 00440 00447 static BOOL CanReadAndWrite(); 00449 00450 00451 protected: 00452 // Member variables 00454 PFilePath subProgName; 00455 00456 00457 private: 00458 BOOL PlatformOpen(const PString & subProgram, 00459 const PStringArray & arguments, 00460 OpenMode mode, 00461 BOOL searchPath, 00462 BOOL stderrSeparate, 00463 const PStringToString * environment); 00464 00465 00466 // Include platform dependent part of class 00467 #ifdef _WIN32 00468 #include "msos/ptlib/pipechan.h" 00469 #else 00470 #include "unix/ptlib/pipechan.h" 00471 #endif 00472 }; 00473 00474 #endif 00475 00476 // End Of File ///////////////////////////////////////////////////////////////