dlvhex  2.5.0
ProcessBuf Class Reference

A std::streambuf interface for creating child processes and writing/reading data via stdin/stdout. More...

#include <include/dlvhex2/ProcessBuf.h>

Public Member Functions

 ProcessBuf ()
 Constructor.
 ProcessBuf (const ProcessBuf &b)
 Copy-constructor.
virtual ~ProcessBuf ()
 Destructor.
virtual void endoffile ()
 Send EOF to the process.
virtual pid_t open (const std::vector< std::string > &c)
 Open a commandline in a seprate process.
virtual int close (bool kill=false)
 Wait for end of process.

Protected Member Functions

virtual std::streambuf::int_type overflow (std::streambuf::int_type c)
 Called when an overflow occurred.
virtual std::streambuf::int_type underflow ()
 Called when an underflow occurred.
virtual std::streambuf::int_type sync ()
 Synchronization.

Private Member Functions

void initBuffers ()
 Initializes obuf and ibuf.

Private Attributes

int status
 Status of the child process.
unsigned bufsize
 Buffer size.
std::streambuf::char_type * obuf
 Data of the output buffer.
std::streambuf::char_type * ibuf
 Data of the input buffer.

Detailed Description

A std::streambuf interface for creating child processes and writing/reading data via stdin/stdout.

Definition at line 63 of file ProcessBuf.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 60 of file ProcessBuf.cpp.

References initBuffers().

Copy-constructor.

Parameters:
bOther ProcessBuf.

Definition at line 84 of file ProcessBuf.cpp.

References initBuffers().

ProcessBuf::~ProcessBuf ( ) [virtual]

Destructor.

Definition at line 104 of file ProcessBuf.cpp.

References close(), ibuf, and obuf.


Member Function Documentation

int ProcessBuf::close ( bool  kill = false) [virtual]

Wait for end of process.

Parameters:
Iftrue the process will be killed, otherwise the method waits.
Returns:
Return code of the process.

Definition at line 338 of file ProcessBuf.cpp.

References endoffile(), ibuf, LOG, and status.

Referenced by DLVProcess::close(), endoffile(), open(), DLVProcess::~DLVProcess(), and ~ProcessBuf().

void ProcessBuf::endoffile ( ) [virtual]

Send EOF to the process.

Definition at line 300 of file ProcessBuf.cpp.

References bufsize, close(), and obuf.

Referenced by close(), and DLVProcess::endoffile().

void ProcessBuf::initBuffers ( ) [private]

Initializes obuf and ibuf.

Definition at line 121 of file ProcessBuf.cpp.

References bufsize, ibuf, and obuf.

Referenced by ProcessBuf().

pid_t ProcessBuf::open ( const std::vector< std::string > &  c) [virtual]

Open a commandline in a seprate process.

Parameters:
cCommandline to open.
Returns:
Process ID if the new process.

Definition at line 131 of file ProcessBuf.cpp.

References close(), LOG, printvector(), and WARNING().

Referenced by DLVProcess::spawn().

std::streambuf::int_type ProcessBuf::overflow ( std::streambuf::int_type  c) [protected, virtual]

Called when an overflow occurred.

Parameters:
cSee std::streambuf.
Returns:
std::streambuf.

Definition at line 416 of file ProcessBuf.cpp.

References sync().

std::streambuf::int_type ProcessBuf::sync ( ) [protected, virtual]

Synchronization.

Parameters:
cSee std::streambuf.
Returns:
std::streambuf.

Definition at line 477 of file ProcessBuf.cpp.

References bufsize, ibuf, and obuf.

Referenced by overflow().

std::streambuf::int_type ProcessBuf::underflow ( ) [protected, virtual]

Called when an underflow occurred.

Parameters:
cSee std::streambuf.
Returns:
std::streambuf.

Definition at line 436 of file ProcessBuf.cpp.

References bufsize, and ibuf.


Field Documentation

unsigned ProcessBuf::bufsize [private]

Buffer size.

Definition at line 119 of file ProcessBuf.h.

Referenced by endoffile(), initBuffers(), sync(), and underflow().

std::streambuf::char_type* ProcessBuf::ibuf [private]

Data of the input buffer.

Definition at line 124 of file ProcessBuf.h.

Referenced by close(), initBuffers(), sync(), underflow(), and ~ProcessBuf().

std::streambuf::char_type* ProcessBuf::obuf [private]

Data of the output buffer.

Definition at line 122 of file ProcessBuf.h.

Referenced by endoffile(), initBuffers(), sync(), and ~ProcessBuf().

int ProcessBuf::status [private]

Status of the child process.

Definition at line 117 of file ProcessBuf.h.

Referenced by close().


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