MASA-Core
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
Buffer Class Reference

Detailed Description

Definition at line 50 of file Buffer.hpp.

#include <Buffer.hpp>

Inheritance diagram for Buffer:
CellsReader CellsWriter FileBuffer NullBuffer SocketBuffer

List of all members.

Public Member Functions

 Buffer ()
virtual ~Buffer ()
virtual int read (cell_t *data, int nmemb)
virtual int write (const cell_t *data, int nmemb)
virtual int getType ()
int readBuffer (char *data, int size, int nmemb)
int writeBuffer (const char *data, int size, int nmemb)
void waitEmptyBuffer ()
void destroy ()
bool isDestroyed ()
virtual void autoFlushThread ()=0
virtual void autoLoadThread ()=0
virtual void initAutoFlush ()=0
virtual void initAutoLoad ()=0
virtual void destroyAutoFlush ()=0
 This method is called prior to the auto-load thread destruction.
virtual void destroyAutoLoad ()=0
 This method is called prior to the auto-load thread destruction.
void autoFlush ()
void autoLoad ()
int getUsage ()
 Use this method only for statistics purpose, since the returned value is volatile and not synchronized (without mutex).
int getCapacity ()
 Returns the maximum capacity in bytes of the buffer.
float getBlockingReadTime ()
 Returns the number of milliseconds that was blocked waiting for data.
float getBlockingWriteTime ()
 Returns the number of milliseconds that was blocked waiting for space.
int getBytesWritten ()
 Returns the amount of bytes written in the buffer since its creation.
int getBytesRead ()
 Returns the amount of bytes read from the buffer since its creation.
buffer_statistics_t getStatistics ()
 Returns a struct containing statistics of the buffer.
void setLogFile (string logFile, int interval)
 Defines a logfile to receive the buffer statistics in each interval period.

Private Member Functions

int circularLoad (char *dst, int len)
int circularStore (const char *src, int len)
int sizeUsed ()
int sizeAvailable ()
void createAutoLoadThread ()
void createAutoFlushThread ()
void logThread ()
void joinThreads ()

Static Private Member Functions

static void * staticFlushThread (void *arg)
static void * staticLoadThread (void *arg)
static void * staticLogThread (void *arg)

Private Attributes

float blockingReadTime
float blockingWriteTime
int volatileUsage
int bytesRead
int bytesWritten
float tempBlockingWriteTime
float tempBlockingReadTime
pthread_mutex_t mutex
pthread_cond_t notFullCond
pthread_cond_t notEmptyCond
pthread_cond_t emptyCond
pthread_cond_t loggerCond
bool destroyed
char * buffer
int buffer_size
int buffer_start
int buffer_end
int buffer_max
pthread_t threadId
bool inputBuffer
pthread_t loggerThread
string logFile
bool isLogging
int logInterval

Constructor & Destructor Documentation

Definition at line 35 of file Buffer.cpp.

Buffer::~Buffer ( ) [virtual]

Definition at line 67 of file Buffer.cpp.


Member Function Documentation

Definition at line 232 of file Buffer.cpp.

virtual void Buffer::autoFlushThread ( ) [pure virtual]

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

void Buffer::autoLoad ( )

Definition at line 237 of file Buffer.cpp.

virtual void Buffer::autoLoadThread ( ) [pure virtual]

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

int Buffer::circularLoad ( char *  dst,
int  len 
) [private]

Definition at line 118 of file Buffer.cpp.

int Buffer::circularStore ( const char *  src,
int  len 
) [private]

Definition at line 140 of file Buffer.cpp.

void Buffer::createAutoFlushThread ( ) [private]

Definition at line 254 of file Buffer.cpp.

void Buffer::createAutoLoadThread ( ) [private]

Definition at line 244 of file Buffer.cpp.

void Buffer::destroy ( )

Definition at line 72 of file Buffer.cpp.

virtual void Buffer::destroyAutoFlush ( ) [pure virtual]

This method is called prior to the auto-load thread destruction.

See the Buffer::destroyAutoLoad() method description.

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

virtual void Buffer::destroyAutoLoad ( ) [pure virtual]

This method is called prior to the auto-load thread destruction.

For example, if the auto-load thread is waiting for a socket input, then the destroyAutoLoad must destroy the socket in order to wake the thread execution. Note that during and after this method is called, the Buffer::isDestroyed() method will always return true.

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

Returns the number of milliseconds that was blocked waiting for data.

Returns:
blocking time in readBuffer method.

Definition at line 289 of file Buffer.cpp.

Returns the number of milliseconds that was blocked waiting for space.

Returns:
blocking time in writeBuffer method.

Definition at line 293 of file Buffer.cpp.

Returns the amount of bytes read from the buffer since its creation.

Returns:
the number of bytes read.

Definition at line 301 of file Buffer.cpp.

Returns the amount of bytes written in the buffer since its creation.

Returns:
the number of bytes written.

Definition at line 297 of file Buffer.cpp.

Returns the maximum capacity in bytes of the buffer.

Returns:
The size of the buffer in bytes.

Definition at line 285 of file Buffer.cpp.

Returns a struct containing statistics of the buffer.

Returns:
statistics of the buffer.

Definition at line 305 of file Buffer.cpp.

int Buffer::getType ( ) [virtual]

Implements CellsReader.

Definition at line 93 of file Buffer.cpp.

Use this method only for statistics purpose, since the returned value is volatile and not synchronized (without mutex).

Returns:
the number of bytes in the buffer.

Definition at line 281 of file Buffer.cpp.

virtual void Buffer::initAutoFlush ( ) [pure virtual]

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

virtual void Buffer::initAutoLoad ( ) [pure virtual]

Implemented in FileBuffer, SocketBuffer, and NullBuffer.

Definition at line 105 of file Buffer.cpp.

void Buffer::joinThreads ( ) [private]

Definition at line 97 of file Buffer.cpp.

void Buffer::logThread ( ) [private]

Definition at line 330 of file Buffer.cpp.

int Buffer::read ( cell_t data,
int  nmemb 
) [virtual]

Implements CellsReader.

Definition at line 167 of file Buffer.cpp.

int Buffer::readBuffer ( char *  data,
int  size,
int  nmemb 
)

Definition at line 171 of file Buffer.cpp.

void Buffer::setLogFile ( string  logFile,
int  interval 
)

Defines a logfile to receive the buffer statistics in each interval period.

Parameters:
logFilethe filename of the log file.
intervalThe period in seconds to log the statistics.

Definition at line 353 of file Buffer.cpp.

int Buffer::sizeAvailable ( ) [private]

Definition at line 155 of file Buffer.cpp.

int Buffer::sizeUsed ( ) [private]

Definition at line 159 of file Buffer.cpp.

void * Buffer::staticFlushThread ( void *  arg) [static, private]

Definition at line 263 of file Buffer.cpp.

void * Buffer::staticLoadThread ( void *  arg) [static, private]

Definition at line 269 of file Buffer.cpp.

void * Buffer::staticLogThread ( void *  arg) [static, private]

Definition at line 275 of file Buffer.cpp.

Definition at line 109 of file Buffer.cpp.

int Buffer::write ( const cell_t data,
int  nmemb 
) [virtual]

Implements CellsWriter.

Definition at line 200 of file Buffer.cpp.

int Buffer::writeBuffer ( const char *  data,
int  size,
int  nmemb 
)

Definition at line 204 of file Buffer.cpp.


Member Data Documentation

float Buffer::blockingReadTime [private]

Definition at line 144 of file Buffer.hpp.

float Buffer::blockingWriteTime [private]

Definition at line 145 of file Buffer.hpp.

char* Buffer::buffer [private]

Definition at line 162 of file Buffer.hpp.

int Buffer::buffer_end [private]

Definition at line 165 of file Buffer.hpp.

int Buffer::buffer_max [private]

Definition at line 166 of file Buffer.hpp.

int Buffer::buffer_size [private]

Definition at line 163 of file Buffer.hpp.

int Buffer::buffer_start [private]

Definition at line 164 of file Buffer.hpp.

int Buffer::bytesRead [private]

Definition at line 147 of file Buffer.hpp.

int Buffer::bytesWritten [private]

Definition at line 148 of file Buffer.hpp.

bool Buffer::destroyed [private]

Definition at line 160 of file Buffer.hpp.

pthread_cond_t Buffer::emptyCond [private]

Definition at line 157 of file Buffer.hpp.

bool Buffer::inputBuffer [private]

Definition at line 169 of file Buffer.hpp.

bool Buffer::isLogging [private]

Definition at line 173 of file Buffer.hpp.

string Buffer::logFile [private]

Definition at line 172 of file Buffer.hpp.

pthread_cond_t Buffer::loggerCond [private]

Definition at line 158 of file Buffer.hpp.

pthread_t Buffer::loggerThread [private]

Definition at line 171 of file Buffer.hpp.

int Buffer::logInterval [private]

Definition at line 174 of file Buffer.hpp.

pthread_mutex_t Buffer::mutex [private]

Definition at line 154 of file Buffer.hpp.

pthread_cond_t Buffer::notEmptyCond [private]

Definition at line 156 of file Buffer.hpp.

pthread_cond_t Buffer::notFullCond [private]

Definition at line 155 of file Buffer.hpp.

Definition at line 151 of file Buffer.hpp.

Definition at line 150 of file Buffer.hpp.

pthread_t Buffer::threadId [private]

Definition at line 168 of file Buffer.hpp.

int Buffer::volatileUsage [private]

Definition at line 146 of file Buffer.hpp.


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