ucommon::BufferProtocol Class Reference

Common buffer protocol class. More...

#include <protocols.h>

Inheritance diagram for ucommon::BufferProtocol:
Inheritance graph
[legend]
Collaboration diagram for ucommon::BufferProtocol:
Collaboration graph
[legend]

Public Types

enum  type_t { BUF_RD, BUF_WR, BUF_RDWR }

Public Member Functions

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 (string &buffer)
 Get a string as a line of input from the buffer.
size_t getline (char *string, size_t size)
 Get text 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.

Protected Member Functions

virtual bool _blocking (void)
 Return true if blocking.
virtual void _clear (void)=0
 Method to clear low level i/o error.
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 _pull (char *address, size_t size)=0
 Method to pull buffer from physical i/o (read).
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 (size_t size, type_t access=BUF_RDWR)
 Construct a buffer of pre-allocated size and access type.
 BufferProtocol ()
 Construct an empty (unallocated) buffer.
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.
 ~BufferProtocol ()
 Destroy object by releasing buffer memory.

Protected Attributes

const char * format

Detailed Description

Common buffer protocol class.

This is used to create objects which will stream character data as needed. This class can support bidirectional streaming as may be needed for serial devices, sockets, and pipes. The buffering mechanisms are hidden from derived classes, and two virtuals are used to communicate with the physical transport.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 165 of file protocols.h.


Constructor & Destructor Documentation

ucommon::BufferProtocol::BufferProtocol ( size_t  size,
type_t  access = BUF_RDWR 
) [protected]

Construct a buffer of pre-allocated size and access type.

Parameters:
size of buffer to allocate.
access mode of buffer.

Member Function Documentation

virtual int ucommon::BufferProtocol::_err ( void   )  const [protected, pure virtual]

Method to get low level i/o error.

Returns:
error from low level i/o methods.

Implemented in ucommon::fbuf, and ucommon::TCPBuffer.

int ucommon::BufferProtocol::_getch ( void   )  [virtual]

Get a character from the buffer.

If no data is available, return EOF.

Returns:
character from buffer or eof.

Implements ucommon::CharacterProtocol.

virtual size_t ucommon::BufferProtocol::_pull ( char *  address,
size_t  size 
) [protected, pure virtual]

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

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

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

Implemented in ucommon::fbuf, ucommon::TCPBuffer, ucommon::SSLBuffer, and ucommon::shell::iobuf.

virtual size_t ucommon::BufferProtocol::_push ( const char *  address,
size_t  size 
) [protected, pure virtual]

Method to push buffer into physical i/o (write).

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

Parameters:
address of data to push.
size of data to push.
Returns:
number of bytes written, 0 on error.

Implemented in ucommon::fbuf, ucommon::TCPBuffer, and ucommon::SSLBuffer.

int ucommon::BufferProtocol::_putch ( int  ch  )  [virtual]

Put a character into the buffer.

Returns:
character put into buffer or eof.

Implements ucommon::CharacterProtocol.

void ucommon::BufferProtocol::allocate ( size_t  size,
type_t  access = BUF_RDWR 
) [protected]

Allocate I/O buffer(s) of specified size.

If a buffer is currently allocated, it is released.

Parameters:
size of buffer to allocate.
access mode of buffer.
bool ucommon::BufferProtocol::eof ( void   ) 

Check if at end of input.

Returns:
true if end of data, false if input still buffered.
bool ucommon::BufferProtocol::flush ( void   )  [inline]

Flush buffered memory to physical I/O.

Returns:
true on success, false if not active or fails.

Definition at line 340 of file protocols.h.

char* ucommon::BufferProtocol::gather ( size_t  size  )  [protected]

Gather returns a pointer to contiguous input of specified size.

This may require moving the input data in memory.

Parameters:
size of gather space.
Returns:
data pointer to gathered data or NULL if not available.
size_t ucommon::BufferProtocol::get ( char *  address,
size_t  count 
)

Get memory from the buffer.

This method will become "get()" in abi 4 and may become a protected method.

Parameters:
address of characters save from buffer.
count of characters to get from buffer.
Returns:
number of characters actually copied.
size_t ucommon::BufferProtocol::getline ( string buffer  ) 

Get a string as a line of input from the buffer.

The eol character(s) are used to mark the end of a line. Because the end of line character is stripped, the length of the string may be less than the actual count read. If at the end of the file buffer and unable to read more data an error occured then 0 is returned.

Parameters:
buffer to save input into.
Returns:
count of characters actually read or 0 if at end of data.
size_t ucommon::BufferProtocol::getline ( char *  string,
size_t  size 
)

Get text as a line of input from the buffer.

The eol character(s) are used to mark the end of a line. Because the end of line character is stripped, the length of the string may be less than the actual count read. If at the end of the file buffer and unable to read more data an error occured then 0 is returned.

Parameters:
string to save input into.
size limit of string to save.
Returns:
count of characters actually read or 0 if at end of data.
bool ucommon::BufferProtocol::is_input ( void   )  [inline]

See if input active.

Returns:
true if input active.

Definition at line 415 of file protocols.h.

bool ucommon::BufferProtocol::is_open ( void   )  [inline]

See if buffer open.

Returns:
true if buffer active.

Definition at line 408 of file protocols.h.

bool ucommon::BufferProtocol::is_output ( void   )  [inline]

See if output active.

Returns:
true if output active.

Definition at line 422 of file protocols.h.

bool ucommon::BufferProtocol::is_pending ( void   )  [inline]

See if pending input.

Returns:
true if input pending.

Definition at line 429 of file protocols.h.

ucommon::BufferProtocol::operator bool (  )  [inline]

See if buffer open.

Returns:
true if buffer active.

Definition at line 394 of file protocols.h.

bool ucommon::BufferProtocol::operator! (  )  [inline]

See if buffer closed.

Returns:
true if buffer inactive.

Definition at line 401 of file protocols.h.

size_t ucommon::BufferProtocol::printf ( const char *  format,
  ... 
)

Print formatted string to the buffer.

The maximum output size is the buffer size, and the operation flushes the buffer.

Parameters:
format string.
Returns:
number of bytes written.
size_t ucommon::BufferProtocol::put ( const char *  address,
size_t  count = 0 
)

Put memory into the buffer.

If count is 0 then put as NULL terminated string. This method will become "put()" in abi 4 and may become a protected method.

Parameters:
address of characters to put into buffer.
count of characters to put into buffer.
Returns:
number of characters actually written.
size_t ucommon::BufferProtocol::putline ( const char *  string  ) 

Put a string as a line of output to the buffer.

The eol character is appended to the end.

Parameters:
string to write.
Returns:
total characters successfully written, including eol chars.
char* ucommon::BufferProtocol::request ( size_t  size  )  [protected]

Request workspace in output buffer.

This returns a pointer to memory from the output buffer and advances the output position. This is sometimes used for a form of zero copy write.

Parameters:
size of request area.
Returns:
data pointer or NULL if not available.
void ucommon::BufferProtocol::reset ( void   ) 

Reset input buffer state.

Drops any pending input.

void ucommon::BufferProtocol::seteol ( const char *  string  )  [inline, protected]

Set end of line marker.

Normally this is set to cr & lf, which actually supports both lf alone and cr/lf termination of lines. However, putline() will always add the full cr/lf if this mode is used. This option only effects getline() and putline().

Parameters:
string for eol for getline and putline.

Definition at line 204 of file protocols.h.

size_t ucommon::BufferProtocol::unread ( void   )  [inline, protected]

Get current input position.

Sometimes used to help compute and report a "tell" offset.

Returns:
offset of input buffer.

Definition at line 286 of file protocols.h.

size_t ucommon::BufferProtocol::unsaved ( void   )  [inline, protected]

Get current output position.

Sometimes used to help compute a "trunc" operation.

Definition at line 293 of file protocols.h.


The documentation for this class was generated from the following file:
Generated on Thu Jul 14 16:34:56 2011 for ucommon by  doxygen 1.6.3