vdr 2.7.5
cRingBufferLinear Class Reference

#include <ringbuffer.h>

Public Member Functions

 cRingBufferLinear (int Size, int Margin=0, bool Statistics=false, const char *Description=NULL)
virtual ~cRingBufferLinear () override
virtual int Available (void) override
virtual int Free (void) override
virtual void Clear (void) override
int Read (int FileHandle, int Max=0)
int Read (cUnbufferedFile *File, int Max=0)
int Put (const uchar *Data, int Count)
ucharGet (int &Count)
void Del (int Count)
Public Member Functions inherited from cRingBuffer
 cRingBuffer (int Size, bool Statistics=false)
virtual ~cRingBuffer ()
void SetTimeouts (int PutTimeout, int GetTimeout)
void SetIoThrottle (void)
void ReportOverflow (int Bytes)

Protected Member Functions

virtual int DataReady (const uchar *Data, int Count)
Protected Member Functions inherited from cRingBuffer
void UpdatePercentage (int Fill)
void WaitForPut (void)
void WaitForGet (void)
void EnablePut (void)
void EnableGet (void)
int Size (void)

Private Attributes

int margin
int head
int tail
int gotten
ucharbuffer
char * description

Additional Inherited Members

Protected Attributes inherited from cRingBuffer
tThreadId getThreadTid
int maxFill
int lastPercent
bool statistics

Detailed Description

Definition at line 48 of file ringbuffer.h.

Constructor & Destructor Documentation

◆ cRingBufferLinear()

cRingBufferLinear::cRingBufferLinear ( int Size,
int Margin = 0,
bool Statistics = false,
const char * Description = NULL )

Creates a linear ring buffer.

The buffer will be able to hold at most Size-Margin-1 bytes of data, and will be guaranteed to return at least Margin bytes in one consecutive block. The optional Description is used for debugging only.

Definition at line 170 of file ringbuffer.c.

References buffer, Clear(), cRingBuffer::cRingBuffer(), description, esyslog, gotten, head, MALLOC, margin, cRingBuffer::Size(), and tail.

◆ ~cRingBufferLinear()

cRingBufferLinear::~cRingBufferLinear ( )
overridevirtual

Definition at line 197 of file ringbuffer.c.

References buffer, and description.

Member Function Documentation

◆ Available()

int cRingBufferLinear::Available ( void )
overridevirtual

Implements cRingBuffer.

Definition at line 211 of file ringbuffer.c.

References head, margin, cRingBuffer::Size(), and tail.

Referenced by cIndexFileGenerator::Action(), and Free().

◆ Clear()

void cRingBufferLinear::Clear ( void )
overridevirtual

Immediately clears the ring buffer.

This function may safely be called from the reading thread without additional locking. If called from the writing thread, proper locking must be used.

Implements cRingBuffer.

Definition at line 217 of file ringbuffer.c.

References cRingBuffer::EnablePut(), head, cRingBuffer::maxFill, and tail.

Referenced by cIndexFileGenerator::Action(), and cRingBufferLinear().

◆ DataReady()

int cRingBufferLinear::DataReady ( const uchar * Data,
int Count )
protectedvirtual

By default a ring buffer has data ready as soon as there are at least 'margin' bytes available.

A derived class can reimplement this function if it has other conditions that define when data is ready. The return value is either 0 if there is not yet enough data available, or the number of bytes from the beginning of Data that are "ready".

Definition at line 206 of file ringbuffer.c.

References margin.

Referenced by Get().

◆ Del()

void cRingBufferLinear::Del ( int Count)

Deletes at most Count bytes from the ring buffer.

Count must be less or equal to the number that was returned by a previous call to Get().

Definition at line 371 of file ringbuffer.c.

References cRingBuffer::EnablePut(), esyslog, gotten, margin, cRingBuffer::Size(), and tail.

Referenced by cIndexFileGenerator::Action().

◆ Free()

virtual int cRingBufferLinear::Free ( void )
inlineoverridevirtual

Reimplemented from cRingBuffer.

Definition at line 80 of file ringbuffer.h.

References Available(), margin, and cRingBuffer::Size().

◆ Get()

uchar * cRingBufferLinear::Get ( int & Count)

Gets data from the ring buffer.

The data will remain in the buffer until a call to Del() deletes it. Returns a pointer to the data, and stores the number of bytes actually available in Count. If the returned pointer is NULL, Count has no meaning.

Definition at line 346 of file ringbuffer.c.

References buffer, DataReady(), cRingBuffer::getThreadTid, gotten, head, margin, cRingBuffer::Size(), tail, cThread::ThreadId(), and cRingBuffer::WaitForGet().

Referenced by cIndexFileGenerator::Action().

◆ Put()

int cRingBufferLinear::Put ( const uchar * Data,
int Count )

Puts at most Count bytes of Data into the ring buffer.

Returns the number of bytes actually stored.

Definition at line 306 of file ringbuffer.c.

References buffer, cRingBuffer::EnableGet(), head, margin, cRingBuffer::Size(), cRingBuffer::statistics, tail, cRingBuffer::UpdatePercentage(), and cRingBuffer::WaitForPut().

Referenced by cIndexFileGenerator::Action().

◆ Read() [1/2]

◆ Read() [2/2]

int cRingBufferLinear::Read ( int FileHandle,
int Max = 0 )

Reads at most Max bytes from FileHandle and stores them in the ring buffer.

If Max is 0, reads as many bytes as possible. Only one actual read() call is done. Returns the number of bytes actually read and stored, or an error value from the actual read() call.

Definition at line 230 of file ringbuffer.c.

References buffer, cRingBuffer::EnableGet(), head, margin, safe_read(), cRingBuffer::Size(), cRingBuffer::statistics, tail, cRingBuffer::UpdatePercentage(), and cRingBuffer::WaitForPut().

Referenced by cIndexFileGenerator::Action().

Member Data Documentation

◆ buffer

uchar* cRingBufferLinear::buffer
private

Definition at line 63 of file ringbuffer.h.

Referenced by cRingBufferLinear(), Get(), Put(), Read(), Read(), and ~cRingBufferLinear().

◆ description

char* cRingBufferLinear::description
private

Definition at line 64 of file ringbuffer.h.

Referenced by cRingBufferLinear(), and ~cRingBufferLinear().

◆ gotten

int cRingBufferLinear::gotten
private

Definition at line 62 of file ringbuffer.h.

Referenced by cRingBufferLinear(), Del(), and Get().

◆ head

int cRingBufferLinear::head
private

Definition at line 61 of file ringbuffer.h.

Referenced by Available(), Clear(), cRingBufferLinear(), Get(), Put(), Read(), and Read().

◆ margin

int cRingBufferLinear::margin
private

Definition at line 61 of file ringbuffer.h.

Referenced by Available(), cRingBufferLinear(), DataReady(), Del(), Free(), Get(), Put(), Read(), and Read().

◆ tail

int cRingBufferLinear::tail
private

Definition at line 61 of file ringbuffer.h.

Referenced by Available(), Clear(), cRingBufferLinear(), Del(), Get(), Put(), Read(), and Read().


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