Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PPipeChannel Class Reference

#include <pipechan.h>

Inheritance diagram for PPipeChannel:

PChannel PObject

List of all members.


Detailed Description

A channel that uses a operating system pipe between the current process and a sub-process. On platforms that support { multi-processing}, the sub-program is executed concurrently with the calling process.

Where full multi-processing is not supported then the sub-program is run with its input supplied from, or output captured to, a disk file. The current process is then suspended during the execution of the sub-program. In the latter case the semantics of the Execute()# and Close()# functions change from the usual for channels.

Note that for platforms that do not support multi-processing, the current process is suspended until the sub-program terminates. The input and output of the sub-program is transferred via a temporary file. The exact moment of execution of the sub-program depends on the mode. If mode is ReadOnly# then it is executed immediately and its output captured. In WriteOnly# mode the sub-program is run when the Close()# function is called, or when the pipe channel is destroyed. In ReadWrite# mode the sub-program is run when the Execute()# function is called indicating that the output from the current process to the sub-program has completed and input is now desired.

The CanReadAndWrite()# function effectively determines whether full multi-processing is supported by the platform. Note that this is different to whether { multi-threading} is supported.

Definition at line 138 of file pipechan.h.


Comparison functions

enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
bool operator!= (const PObject &obj) const
bool operator< (const PObject &obj) const
bool operator<= (const PObject &obj) const
bool operator== (const PObject &obj) const
bool operator> (const PObject &obj) const
bool operator>= (const PObject &obj) const

Error functions

enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
}
Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
static PString GetErrorText (Errors lastError, int osError=0)

Construction

enum  OpenMode { ReadOnly, WriteOnly, ReadWrite, ReadWriteStd }
 Channel mode for the pipe to the sub-process. More...
 PPipeChannel (const PString &subProgram, const PStringArray &argumentList, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 PPipeChannel (const PString &subProgram, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 PPipeChannel (const PString &subProgram, const PStringArray &argumentList, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 PPipeChannel (const PString &subProgram, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 PPipeChannel ()
 ~PPipeChannel ()
 Close the pipe channel, killing the sub-process.

Miscellaneous functions

enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }
void AbortCommandString ()
BOOL SendCommandString (const PString &command)
BOOL SetBufferSize (PINDEX newSize)
virtual BOOL Shutdown (ShutdownValue option)

Scattered read/write functions

typedef std::vector< SliceVectorOfSlice
virtual BOOL Read (const VectorOfSlice &slices)
virtual BOOL Write (const VectorOfSlice &slices)

New member functions

BOOL Execute ()
int GetReturnCode () const
const PFilePathGetSubProgram () const
BOOL IsRunning () const
BOOL Kill (int signal=9)
BOOL Open (const PString &subProgram, const PStringArray &argumentList, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
BOOL Open (const PString &subProgram, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
BOOL Open (const PString &subProgram, const PStringArray &argumentList, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
BOOL Open (const PString &subProgram, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
BOOL ReadStandardError (PString &errors, BOOL wait=FALSE)
int WaitForTermination (const PTimeInterval &timeout)
int WaitForTermination ()
static BOOL CanReadAndWrite ()

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
virtual BOOL InternalIsDescendant (const char *clsName) const
BOOL IsClass (const char *cls) const
static const char * Class ()

I/O functions

virtual void PrintOn (ostream &strm) const
virtual void ReadFrom (istream &strm)
ostream & operator<< (ostream &strm, const PObject &obj)
istream & operator>> (istream &strm, PObject &obj)

Public Types

enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }

Public Member Functions

Miscellaneous functions
virtual PObjectClone () const
Overrides from class PChannel
virtual BOOL Close ()
virtual PString GetName () const
virtual BOOL Read (void *buf, PINDEX len)
virtual BOOL Write (const void *buf, PINDEX len)
Overrides from class PObject
Comparison Compare (const PObject &obj) const
Information functions
virtual PChannelGetBaseReadChannel () const
virtual PChannelGetBaseWriteChannel () const
int GetHandle () const
virtual BOOL IsOpen () const
Reading functions
virtual PINDEX GetLastReadCount () const
PTimeInterval GetReadTimeout () const
virtual void OnReadComplete (void *buf, PINDEX len)
virtual BOOL ReadAsync (void *buf, PINDEX len)
BOOL ReadBlock (void *buf, PINDEX len)
virtual int ReadChar ()
PString ReadString (PINDEX len)
void SetReadTimeout (const PTimeInterval &time)
Writing functions
virtual PINDEX GetLastWriteCount () const
PTimeInterval GetWriteTimeout () const
virtual void OnWriteComplete (const void *buf, PINDEX len)
void SetWriteTimeout (const PTimeInterval &time)
virtual BOOL WriteAsync (const void *buf, PINDEX len)
BOOL WriteChar (int c)
BOOL WriteString (const PString &str)
Overrides from class PObject
virtual PINDEX HashFunction () const

Static Public Member Functions

static BOOL ConvertOSError (int libcReturnValue, Errors &lastError, int &osError)

Protected Member Functions

virtual BOOL ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError)
int PXClose ()
BOOL PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
int ReadCharWithTimeout (PTimeInterval &timeout)
BOOL ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
BOOL SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)

Protected Attributes

PString channelName
int childPid
int fromChildPipe [2]
Errors lastErrorCode [NumErrorGroups+1]
 The platform independant error code.
int lastErrorNumber [NumErrorGroups+1]
 The operating system error number (eg as returned by errno).
PINDEX lastReadCount
 Number of byte last read by the Read() function.
PINDEX lastWriteCount
 Number of byte last written by the Write() function.
int os_handle
 The operating system file handle return by standard open() function.
PXBlockType px_lastBlockType
PThreadpx_readThread
PMutex px_selectMutex
PThreadpx_selectThread
PMutex px_threadMutex
PMutex px_writeMutex
PThreadpx_writeThread
PTimeInterval readTimeout
 Timeout for read operations.
int retVal
int stderrChildPipe [2]
PFilePath subProgName
 The fully qualified path name for the sub-program executable.
int toChildPipe [2]
PTimeInterval writeTimeout
 Timeout for write operations.

Private Member Functions

 PCLASSINFO (PPipeChannel, PChannel)
BOOL PlatformOpen (const PString &subProgram, const PStringArray &arguments, OpenMode mode, BOOL searchPath, BOOL stderrSeparate, const PStringToString *environment)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index