ucc::Buffer Class Reference

A thread-safe buffer for serializing and streaming class data. More...

#include <thread.h>

Inheritance diagram for ucc::Buffer:

Inheritance graph
[legend]
Collaboration diagram for ucc::Buffer:

Collaboration graph
[legend]

Public Member Functions

 Buffer (size_t size, size_t count)
 Create a buffer to hold a series of objects.
virtual ~Buffer ()
 Deallocate buffer and unblock any waiting threads.
unsigned getSize (void)
 Get the size of the buffer.
unsigned getCount (void)
 Get the number of objects in the buffer currently.
void * get (timeout_t timeout)
 Get the next object from the buffer.
void * get (void)
 Get the next object from the buffer.
void put (void *data)
 Put (copy) an object into the buffer.
bool put (void *data, timeout_t timeout)
 Put (copy) an object into the buffer.
void release (void)
 Release must be called when we get an object from the buffer.
void copy (void *data)
 Copy the next object from the buffer.
bool copy (void *data, timeout_t timeout)
 Copy the next object from the buffer.
 operator bool ()
 Test if there is data waiting in the buffer.
bool operator! ()
 Test if the buffer is empty.

Detailed Description

A thread-safe buffer for serializing and streaming class data.

While the queue and stack operate by managing lists of reference pointers to objects of various mixed kind, the buffer holds physical copies of objects that being passed through it, and all must be the same size. The buffer class can be used stand-alone or with the typed bufferof template. The buffer is accessed in fifo order.

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 1898 of file thread.h.


Constructor & Destructor Documentation

ucc::Buffer::Buffer ( size_t  size,
size_t  count 
)

Create a buffer to hold a series of objects.

Parameters:
size of each object in buffer.
count of objects in the buffer.


Member Function Documentation

bool ucc::Buffer::copy ( void *  data,
timeout_t  timeout 
)

Copy the next object from the buffer.

Buffer is auto-released.

Parameters:
data pointer to copy into.
timeout to wait when buffer is empty in milliseconds.
Returns:
true if object copied, or false if timed out.

void ucc::Buffer::copy ( void *  data  ) 

Copy the next object from the buffer.

This blocks until an object becomes available. Buffer is auto-released.

Parameters:
data pointer to copy into.

void* ucc::Buffer::get ( void   ) 

Get the next object from the buffer.

This blocks until an object becomes available.

Returns:
pointer to next object from buffer.

Reimplemented in ucc::bufferof< T >.

void* ucc::Buffer::get ( timeout_t  timeout  ) 

Get the next object from the buffer.

Parameters:
timeout to wait when buffer is empty in milliseconds.
Returns:
pointer to next object in the buffer or NULL if timed out.

Reimplemented in ucc::bufferof< T >.

unsigned ucc::Buffer::getCount ( void   ) 

Get the number of objects in the buffer currently.

Returns:
number of objects buffered.

unsigned ucc::Buffer::getSize ( void   ) 

Get the size of the buffer.

Returns:
size of the buffer.

ucc::Buffer::operator bool (  ) 

Test if there is data waiting in the buffer.

Returns:
true if buffer has data.

bool ucc::Buffer::operator! (  ) 

Test if the buffer is empty.

Returns:
true if the buffer is empty.

bool ucc::Buffer::put ( void *  data,
timeout_t  timeout 
)

Put (copy) an object into the buffer.

Parameters:
data to copy into the buffer.
timeout to wait if buffer is full.
Returns:
true if copied, false if timed out while full.

void ucc::Buffer::put ( void *  data  ) 

Put (copy) an object into the buffer.

This blocks while the buffer is full.

Parameters:
data to copy into the buffer.

void ucc::Buffer::release ( void   ) 

Release must be called when we get an object from the buffer.

This is because the pointer we return is a physical pointer to memory that is part of the buffer. The object we get cannot be removed or the memory modified while the object is being used.


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

Generated on Wed Aug 19 22:05:23 2009 for UCommon by  doxygen 1.5.9