PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pipechan.h
Go to the documentation of this file.
1 /*
2  * pipechan.h
3  *
4  * Sub-process with communications using pipe I/O channel class.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  *
29  * $Revision: 28207 $
30  * $Author: rjongbloed $
31  * $Date: 2012-08-17 10:09:54 +1000 (Fri, 17 Aug 2012) $
32  */
33 
34 #ifndef PTLIB_PIPECHANNEL_H
35 #define PTLIB_PIPECHANNEL_H
36 
37 #ifdef P_USE_PRAGMA
38 #pragma interface
39 #endif
40 
41 #if P_PIPECHAN
42 
43 #include <ptlib/channel.h>
44 
45 
72 class PChannel;
73 
74 
75 class PPipeChannel : public PChannel
76 {
77  PCLASSINFO(PPipeChannel, PChannel);
78 
79  public:
82 
83  enum OpenMode {
85  ReadOnly,
87  WriteOnly,
89  ReadWrite,
93  ReadWriteStd
94  };
95 
98  PPipeChannel();
104  PPipeChannel(
105  const PString & subProgram,
106  OpenMode mode = ReadWrite,
107  PBoolean searchPath = true,
108  PBoolean stderrSeparate = false
109  );
115  PPipeChannel(
116  const PString & subProgram,
117  const PStringArray & argumentList,
118  OpenMode mode = ReadWrite,
119  PBoolean searchPath = true,
120  PBoolean stderrSeparate = false
121  );
127  PPipeChannel(
128  const PString & subProgram,
129  const PStringToString & environment,
130  OpenMode mode = ReadWrite,
131  PBoolean searchPath = true,
132  PBoolean stderrSeparate = false
133  );
139  PPipeChannel(
140  const PString & subProgram,
141  const PStringArray & argumentList,
142  const PStringToString & environment,
143  OpenMode mode = ReadWrite,
144  PBoolean searchPath = true,
145  PBoolean stderrSeparate = false
146  );
147 
149  ~PPipeChannel();
151 
161  Comparison Compare(
162  const PObject & obj
163  ) const;
165 
166 
174  virtual PString GetName() const;
175 
192  virtual PBoolean Read(
193  void * buf,
194  PINDEX len
195  );
196 
211  virtual PBoolean Write(
212  const void * buf,
213  PINDEX len
214  );
215 
224  virtual PBoolean Close();
226 
230  PBoolean Open(
231  const PString & subProgram,
232  OpenMode mode = ReadWrite,
233  PBoolean searchPath = true,
234  PBoolean stderrSeparate = false
235  );
237  PBoolean Open(
238  const PString & subProgram,
239  const PStringArray & argumentList,
240  OpenMode mode = ReadWrite,
241  PBoolean searchPath = true,
242  PBoolean stderrSeparate = false
243  );
245  PBoolean Open(
246  const PString & subProgram,
247  const PStringToString & environment,
248  OpenMode mode = ReadWrite,
249  PBoolean searchPath = true,
250  PBoolean stderrSeparate = false
251  );
289  PBoolean Open(
290  const PString & subProgram,
291  const PStringArray & argumentList,
292  const PStringToString & environment,
293  OpenMode mode = ReadWrite,
294  PBoolean searchPath = true,
295  PBoolean stderrSeparate = false
296  );
297 
303  const PFilePath & GetSubProgram() const;
304 
318  PBoolean Execute();
319 
328  PBoolean IsRunning() const;
329 
337  int GetReturnCode() const;
338 
344  int WaitForTermination();
345 
352  int WaitForTermination(
353  const PTimeInterval & timeout
354  );
355 
363  PBoolean Kill(
364  int signal = 9
365  );
366 
376  PBoolean ReadStandardError(
377  PString & errors,
378  PBoolean wait = false
379  );
380 
387  static PBoolean CanReadAndWrite();
389 
390 
391  protected:
392  // Member variables
394  PFilePath subProgName;
395 
396 
397  private:
398  PBoolean PlatformOpen(const PString & subProgram,
399  const PStringArray & arguments,
400  OpenMode mode,
401  PBoolean searchPath,
402  PBoolean stderrSeparate,
403  const PStringToString * environment);
404 
405 
406 // Include platform dependent part of class
407 #ifdef _WIN32
408 #include "msos/ptlib/pipechan.h"
409 #else
410 #include "unix/ptlib/pipechan.h"
411 #endif
412 };
413 
414 
415 #endif // P_PIPECHAN
416 
417 #endif // PTLIB_PIPECHANNEL_H
418 
419 
420 // End Of File ///////////////////////////////////////////////////////////////