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

Public Types | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions

PPipeChannel Class Reference

#include <pipechan.h>

Inheritance diagram for PPipeChannel:
Inheritance graph
[legend]
Collaboration diagram for PPipeChannel:
Collaboration graph
[legend]

List of all members.

Public Types

enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }

Public Member Functions

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

Construction

enum  OpenMode { ReadOnly, WriteOnly, ReadWrite, ReadWriteStd }
 

Channel mode for the pipe to the sub-process.

More...
 PPipeChannel ()
 PPipeChannel (const PString &subProgram, 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, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 PPipeChannel (const PString &subProgram, const PStringArray &argumentList, const PStringToString &environment, OpenMode mode=ReadWrite, BOOL searchPath=TRUE, BOOL stderrSeparate=FALSE)
 ~PPipeChannel ()
 Close the pipe channel, killing the sub-process.

Miscellaneous functions

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

Error functions

enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
}
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
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)

Scattered read/write functions

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

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

New member functions

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

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
BOOL IsClass (const char *cls) const
virtual BOOL InternalIsDescendant (const char *clsName) 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)

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.


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

Generated by  Doxygen 1.6.0   Back to index