libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::IQueue Class Referenceabstract

This class implements a queue after the producer-consumer paradigm. More...

#include <IQueue.h>

Inheritance diagram for BaseLib::IQueue:
BaseLib::IQueueBase BaseLib::Hgdc BaseLib::Systems::IPhysicalInterface BaseLib::TcpSocket

Public Member Functions

 IQueue (SharedObjects *baseLib, uint32_t queueCount, uint32_t bufferSize)
 Constructor. More...
 
virtual ~IQueue ()
 
void startQueue (int32_t index, bool waitWhenFull, uint32_t processingThreadCount, int32_t threadPriority=0, int32_t threadPolicy=SCHED_OTHER)
 Starts the threads of a queue. More...
 
void startQueue (int32_t index, bool waitWhenFull, uint32_t initialProcessingThreadCount, uint32_t maxProcessingThreadCount)
 Starts the threads of a queue using a thread count that can be increased later. More...
 
void stopQueue (int32_t index)
 Stops the threads of a queue previously started with startQueue(). More...
 
bool queueIsStarted (int32_t index)
 Checks if the specified queue has been started. More...
 
bool addThread (int32_t index)
 Start an additional thread. More...
 
bool enqueue (int32_t index, std::shared_ptr< IQueueEntry > &entry, bool waitWhenFull=false)
 Enqueues an item. More...
 
virtual void processQueueEntry (int32_t index, std::shared_ptr< IQueueEntry > &entry)=0
 This method is called by the processing threads for each item to process. More...
 
bool queueEmpty (int32_t index)
 Checks if a queue is empty. More...
 
uint32_t processingThreadCount (int32_t index)
 Returns the number of processing threads. More...
 
uint32_t maxProcessingThreadCount (int32_t index)
 Returns the maximum number of processing threads. More...
 
int32_t queueSize (int32_t index)
 Returns the number of items queued in a queue. More...
 
double threadLoad (int32_t index)
 
double maxThreadLoad (int32_t index)
 
double maxThreadLoad1m (int32_t index)
 
double maxThreadLoad10m (int32_t index)
 
double maxThreadLoad1h (int32_t index)
 
int64_t maxWait (int32_t index)
 
int64_t maxWait1m (int32_t index)
 
int64_t maxWait10m (int32_t index)
 
int64_t maxWait1h (int32_t index)
 
- Public Member Functions inherited from BaseLib::IQueueBase
 IQueueBase (SharedObjects *baseLib, uint32_t queueCount)
 
virtual ~IQueueBase ()
 
void printQueueFullError (BaseLib::Output &out, const std::string &message)
 Prints a rate limited (1 output per 10 seconds) error message and keeps count of error messages. More...
 

Additional Inherited Members

- Protected Attributes inherited from BaseLib::IQueueBase
SharedObjects_bl = nullptr
 
int32_t _queueCount = 2
 
std::unique_ptr< std::atomic_bool[]> _stopProcessingThread
 
std::atomic< uint32_t > _droppedEntries {0}
 
std::atomic< int64_t > _lastQueueFullError {0}
 

Detailed Description

This class implements a queue after the producer-consumer paradigm.

It can manage one or more queues. Your class needs to be derived from IQueue to use it.

Constructor & Destructor Documentation

§ IQueue()

BaseLib::IQueue::IQueue ( SharedObjects baseLib,
uint32_t  queueCount,
uint32_t  bufferSize 
)

Constructor.

Parameters
baseLibA base library object.
queueCountThe number of queues to initialize.
bufferSizeThe maximum number of items allowed to be queued.

§ ~IQueue()

BaseLib::IQueue::~IQueue ( )
virtual

Member Function Documentation

§ addThread()

bool BaseLib::IQueue::addThread ( int32_t  index)

Start an additional thread.

Parameters
indexThe index of the queue to add the new thread.
Returns
Returns true when the thread could be started.

§ enqueue()

bool BaseLib::IQueue::enqueue ( int32_t  index,
std::shared_ptr< IQueueEntry > &  entry,
bool  waitWhenFull = false 
)

Enqueues an item.

Parameters
indexThe index of the queue to enqueue the item into.
entryThe item to queue.
waitWhenFullWhen set to true the method waits until the queue is empty enough to queue the item. When waitWhenFull is set to true in startQueue(), this argument is ignored.
Returns
Returns true if the item was successfully queued and false otherwise.

§ maxProcessingThreadCount()

uint32_t BaseLib::IQueue::maxProcessingThreadCount ( int32_t  index)

Returns the maximum number of processing threads.

Returns
The number maximum number of processing threads for this queue.

§ maxThreadLoad()

double BaseLib::IQueue::maxThreadLoad ( int32_t  index)

§ maxThreadLoad10m()

double BaseLib::IQueue::maxThreadLoad10m ( int32_t  index)

§ maxThreadLoad1h()

double BaseLib::IQueue::maxThreadLoad1h ( int32_t  index)

§ maxThreadLoad1m()

double BaseLib::IQueue::maxThreadLoad1m ( int32_t  index)

§ maxWait()

int64_t BaseLib::IQueue::maxWait ( int32_t  index)

§ maxWait10m()

int64_t BaseLib::IQueue::maxWait10m ( int32_t  index)

§ maxWait1h()

int64_t BaseLib::IQueue::maxWait1h ( int32_t  index)

§ maxWait1m()

int64_t BaseLib::IQueue::maxWait1m ( int32_t  index)

§ processingThreadCount()

uint32_t BaseLib::IQueue::processingThreadCount ( int32_t  index)

Returns the number of processing threads.

Returns
The number of processing threads for this queue.

§ processQueueEntry()

virtual void BaseLib::IQueue::processQueueEntry ( int32_t  index,
std::shared_ptr< IQueueEntry > &  entry 
)
pure virtual

This method is called by the processing threads for each item to process.

It needs to be implemented by the derived class.

Parameters
indexThe index of the queue.
entryThe queued item to process.

§ queueEmpty()

bool BaseLib::IQueue::queueEmpty ( int32_t  index)

Checks if a queue is empty.

Parameters
indexThe index of the queue to check.
Returns
Returns true if the queue is empty.

§ queueIsStarted()

bool BaseLib::IQueue::queueIsStarted ( int32_t  index)

Checks if the specified queue has been started.

§ queueSize()

int32_t BaseLib::IQueue::queueSize ( int32_t  index)

Returns the number of items queued in a queue.

Parameters
indexThe index of the queue to check.
Returns
Return the number of queued items.

§ startQueue() [1/2]

void BaseLib::IQueue::startQueue ( int32_t  index,
bool  waitWhenFull,
uint32_t  processingThreadCount,
int32_t  threadPriority = 0,
int32_t  threadPolicy = SCHED_OTHER 
)

Starts the threads of a queue.

Parameters
indexThe index of the queue to start. The number of queues is defined by queueCount in the constructor.
waitWhenFullWhen set to true, enqueue() waits until the queue is empty enough to queue the provided item. This takes precedence over the argument waitWhenFull of enqueue().
processingThreadCountThe number of processing threads to start.
threadPriorityThe thread priority to set. Default is 0 (= disabled). The thread priority values depends on threadPolicy. See man sched for more details.
threadPolicyThe thread policy to use. Default is SCHED_OTHER (= disabled). See man sched for more details.

§ startQueue() [2/2]

void BaseLib::IQueue::startQueue ( int32_t  index,
bool  waitWhenFull,
uint32_t  initialProcessingThreadCount,
uint32_t  maxProcessingThreadCount 
)

Starts the threads of a queue using a thread count that can be increased later.

Parameters
indexThe index of the queue to start. The number of queues is defined by queueCount in the constructor.
waitWhenFullWhen set to true, enqueue() waits until the queue is empty enough to queue the provided item. This takes precedence over the argument waitWhenFull of enqueue().
initialProcessingThreadCountThe number of processing threads to start with the call of this method.
maxProcessingThreadCountThe number maximum number of processing threads that can be started.

§ stopQueue()

void BaseLib::IQueue::stopQueue ( int32_t  index)

Stops the threads of a queue previously started with startQueue().

Parameters
indexThe index of the queue to stop.

§ threadLoad()

double BaseLib::IQueue::threadLoad ( int32_t  index)

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