Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Buffer Class Reference

The Buffer System Class. More...

#include <buffer.h>

List of all members.

Public Methods

 Buffer ( int checkSleep = 10000 )
 Constructor (optional argument). More...

 ~Buffer ()
 Deconstructor. More...

void write (packet* pak)
 writes a packet into the buffer. More...

packetread ()
 reads a packet from the buffer. More...

bool isEmpty ()
 checks if the buffer is empty. More...


Private Attributes

int checkSleep
 the time it waits after realizing that the buffer is empty. More...

pthread_mutex_t buf_lock
 The mutex lock to make the buffer threadsafe. More...

pthread_mutex_t buf_waitlock
 not used/obsolete. More...

queue<packet*> intBuffer
 internal queue. More...


Detailed Description

The Buffer System Class.

Author(s):
Stonedbones
Date:
310100

Definition at line 14 of file buffer.h.

00014 {
00015     public:
00017 
00020     Buffer ( int checkSleep = 10000 );
00022     ~Buffer ();
00023 
00025 
00028     void    write (packet* pak);
00030 
00033     packet* read ();
00034 
00036 
00039     bool    isEmpty ();
00040 
00041     private:
00042 
00043     int checkSleep; 
00044     pthread_mutex_t buf_lock; 
00045     pthread_mutex_t buf_waitlock; 
00046     queue<packet*>  intBuffer; 
00047 }

Constructor & Destructor Documentation

Buffer::Buffer ( int checkSleep = 10000)

Constructor (optional argument).

Parameters:
checkSleep   the time it waits to check the queue again (shall hopefully become obsolete very soon!)

Definition at line 31 of file buffer.cpp.

00031 {
00032     checkSleep = cS;
00033 }

Buffer::~Buffer ()

Deconstructor.

Definition at line 45 of file buffer.cpp.

00045 {
00046     while (!intBuffer.empty ()) intBuffer.pop ();
00047 }

Member Function Documentation

bool Buffer::isEmpty ()

checks if the buffer is empty.

Returns:
true when empty, false when filled

Definition at line 111 of file buffer.cpp.

00112 {
00113     if (intBuffer.empty ())
00114         {
00115         usleep ( checkSleep );
00116         return true;
00117         }
00118     else
00119         {
00120         return false;
00121         };
00122     }

packet * Buffer::read ()

reads a packet from the buffer.

Returns:
the packet

Definition at line 80 of file buffer.cpp.

00080 {
00081     packet* tmp;
00082 
00083     pthread_mutex_lock ( &buf_lock );
00084 
00085     if ( intBuffer.empty () )
00086         {
00087         tmp = 0;
00088         }
00089     else
00090         {
00091         tmp = intBuffer.front ();
00092         intBuffer.pop ();
00093         }
00094 
00095     pthread_mutex_unlock ( &buf_lock );
00096 
00097     return tmp;
00098 }

void Buffer::write ( packet * pak)

writes a packet into the buffer.

Parameters:
pak   the packet

Definition at line 60 of file buffer.cpp.

00061 {
00062     pthread_mutex_lock ( &buf_lock );
00063 
00064     intBuffer.push (pak);
00065 
00066     pthread_mutex_unlock ( &buf_lock );
00067     }

Member Data Documentation

pthread_mutex_t Buffer::buf_lock [private]

The mutex lock to make the buffer threadsafe.

Definition at line 44 of file buffer.h.

pthread_mutex_t Buffer::buf_waitlock [private]

not used/obsolete.

Definition at line 45 of file buffer.h.

int Buffer::checkSleep [private]

the time it waits after realizing that the buffer is empty.

Definition at line 43 of file buffer.h.

queue<packet *> Buffer::intBuffer [private]

internal queue.

Definition at line 46 of file buffer.h.


The documentation for this class was generated from the following files:
Generated at Sat May 13 13:50:24 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000