UCommon
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
ucommon::shell::iobuf Class Reference

Process pipe with I/O buffering. More...

#include <shell.h>

Inheritance diagram for ucommon::shell::iobuf:
Inheritance graph
[legend]
Collaboration diagram for ucommon::shell::iobuf:
Collaboration graph
[legend]

Public Member Functions

void cancel (void)
 Terminate child process.
void close (void)
 Close the i/o buffer.
 iobuf (size_t size=0)
 Construct an i/o buffer.
 iobuf (char *path, char **argv, pmode_t mode, size_t size=512, char **env=((void *) 0))
 Construct an i/o buffer for a child process.
void open (char *path, char **argv, pmode_t mode, size_t size=512, char **env=((void *) 0))
 Open the i/o buffer attached to a child process.
 ~iobuf ()
 Destroy i/o buffer.
- Public Member Functions inherited from ucommon::BufferProtocol
int _getch (void)
 Get a character from the buffer.
int _putch (int ch)
 Put a character into the buffer.
bool eof (void)
 Check if at end of input.
int err (void)
bool flush (void)
 Flush buffered memory to physical I/O.
size_t get (char *address, size_t count)
 Get memory from the buffer.
size_t getline (char *string, size_t size)
 Get text as a line of input from the buffer.
size_t getline (string &buffer)
 Get a string as a line of input from the buffer.
bool is_input (void)
 See if input active.
bool is_open (void)
 See if buffer open.
bool is_output (void)
 See if output active.
bool is_pending (void)
 See if pending input.
 operator bool ()
 See if buffer open.
bool operator! ()
 See if buffer closed.
size_t printf (const char *format,...)
 Print formatted string to the buffer.
void purge (void)
 Purge any pending input or output buffer data.
size_t put (const char *address, size_t count=0)
 Put memory into the buffer.
size_t putline (const char *string)
 Put a string as a line of output to the buffer.
void reset (void)
 Reset input buffer state.
void seteof (void)
 Set eof flag.
- Public Member Functions inherited from ucommon::CharacterProtocol
int get (void)
 Get the next character.
int put (int code)
 Put the next character.

Protected Member Functions

virtual void _clear (void)
 Method to clear low level i/o error.
virtual int _err (void)
virtual size_t _pull (char *address, size_t size)
 Method to pull buffer from physical i/o (read).
virtual size_t _push (char *address, size_t size)
- Protected Member Functions inherited from ucommon::BufferProtocol
virtual bool _blocking (void)
 Return true if blocking.
virtual int _err (void) const =0
 Method to get low level i/o error.
virtual bool _flush (void)
 Flush buffer to physical i/o.
virtual bool _pending (void)
 Check if data is pending.
virtual size_t _push (const char *address, size_t size)=0
 Method to push buffer into physical i/o (write).
void allocate (size_t size, type_t access=BUF_RDWR)
 Allocate I/O buffer(s) of specified size.
 BufferProtocol ()
 Construct an empty (unallocated) buffer.
 BufferProtocol (size_t size, type_t access=BUF_RDWR)
 Construct a buffer of pre-allocated size and access type.
char * gather (size_t size)
 Gather returns a pointer to contiguous input of specified size.
void release (void)
 Release (free) buffer memory.
char * request (size_t size)
 Request workspace in output buffer.
void seteol (const char *string)
 Set end of line marker.
size_t unread (void)
 Get current input position.
size_t unsaved (void)
 Get current output position.
virtual ~BufferProtocol ()
 Destroy object by releasing buffer memory.

Protected Attributes

int ioerror
- Protected Attributes inherited from ucommon::BufferProtocol
const char * format

Friends

class shell

Additional Inherited Members

- Public Types inherited from ucommon::BufferProtocol
enum  type_t { BUF_RD, BUF_WR, BUF_RDWR }

Detailed Description

Process pipe with I/O buffering.

This allows the creation and management of a shell pipe with buffered I/O support. This also offers a common class to manage stdio sessions generically in the child process.

Author:
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 229 of file shell.h.


Constructor & Destructor Documentation

ucommon::shell::iobuf::iobuf ( size_t  size = 0)

Construct an i/o buffer.

If a non-zero size is specified, then the object is attached to the process's stdin & stdout. Otherwise an un-opened object is created.

ucommon::shell::iobuf::iobuf ( char *  path,
char **  argv,
pmode_t  mode,
size_t  size = 512,
char **  env = ((void *) 0) 
)

Construct an i/o buffer for a child process.

This is used to create a child process directly when the object is made. It essentially is the same as the open() method.

Parameters:
pathof program to execute, if filename uses $PATH.
argvto pass to child process.
modeof pipe, rdonly, wronly, or rdwr.
sizeof buffering, and atomic pipe size if settable.
envthat may be passed to child process.
ucommon::shell::iobuf::~iobuf ( )

Destroy i/o buffer.

This may cancel and block waiting for a child process to terminate.


Member Function Documentation

virtual size_t ucommon::shell::iobuf::_pull ( char *  address,
size_t  size 
)
protectedvirtual

Method to pull buffer from physical i/o (read).

The address is passed to this virtual since it is hidden as private.

Parameters:
addressof buffer to pull data into.
sizeof buffer area being pulled..
Returns:
number of read written, 0 on error or end of data.

Implements ucommon::BufferProtocol.

void ucommon::shell::iobuf::cancel ( void  )

Terminate child process.

This also waits for the child process to exit and then closes buffers.

Reimplemented from ucommon::shell::pipeio.

void ucommon::shell::iobuf::close ( void  )

Close the i/o buffer.

If attached to a child process it will wait for the child to exit.

void ucommon::shell::iobuf::open ( char *  path,
char **  argv,
pmode_t  mode,
size_t  size = 512,
char **  env = ((void *) 0) 
)

Open the i/o buffer attached to a child process.

Parameters:
pathof program to execute, if filename uses $PATH.
argvto pass to child process.
modeof pipe, rdonly, wronly, or rdwr.
sizeof buffering, and atomic pipe size if settable.
envthat may be passed to child process.

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