reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
resip::Dispatcher Class Reference

A generic thread-bank class. More...

#include <Dispatcher.hxx>

Public Member Functions

 Dispatcher (std::unique_ptr< Worker > prototype, resip::SipStack *stack, int workers=2, bool startImmediately=true)
 
virtual ~Dispatcher ()
 
virtual bool post (std::unique_ptr< resip::ApplicationMessage > &work)
 Posts a message to this thread bank.
 
size_t fifoCountDepth () const
 
time_t fifoTimeDepth () const
 
int workPoolSize () const
 
void stop ()
 This Dispatcher will stop accepting new work, but processing will continue normally on the messages already in the queue.
 
void resume ()
 Resumes accepting work.
 
void shutdownAll ()
 Shuts down the thread-bank.
 
void startAll ()
 Starts the thread bank.
 

Public Attributes

resip::SipStack * mStack
 

Protected Attributes

resip::TimeLimitFifo< resip::ApplicationMessage > mFifo
 
bool mAcceptingWork
 
bool mShutdown
 
bool mStarted
 
Worker * mWorkerPrototype
 
resip::RWMutex mMutex
 
std::vector< WorkerThread * > mWorkerThreads
 

Detailed Description

A generic thread-bank class.

This is intended to be a generic thread-bank class that operates under the paradigm of accepting messages, modifying those messages, and posting the messages back to the originator through the SipStack. (Since this uses ApplicationMessages, the message will automatically get back to the correct TransactionUser; what happens from there is the coder's business.)

This class gets generality by using prototyping of a very simple class, Worker. All the user must do is subclass Worker to do the work needed, and pass an instance of this class when constructing the Dispatcher. Dispatcher will clone this Worker as many times as needed to fill the thread bank.

Note
The functions in this class are intended to be thread-safe.

Definition at line 37 of file Dispatcher.hxx.

Constructor & Destructor Documentation

◆ Dispatcher()

resip::Dispatcher::Dispatcher ( std::unique_ptr< Worker >  prototype,
resip::SipStack *  stack,
int  workers = 2,
bool  startImmediately = true 
)
Parameters
prototypeThe prototypical instance of Worker.
stackThe stack to post messages to.
workersThe number of threads in this bank.
startImmediatelyWhether to start this thread bank on construction.

Definition at line 10 of file Dispatcher.cxx.

◆ ~Dispatcher()

resip::Dispatcher::~Dispatcher ( )
virtual

Definition at line 32 of file Dispatcher.cxx.

Member Function Documentation

◆ fifoCountDepth()

size_t resip::Dispatcher::fifoCountDepth ( ) const
Returns
The number of messages in this Dispatcher's queue

Definition at line 72 of file Dispatcher.cxx.

◆ fifoTimeDepth()

time_t resip::Dispatcher::fifoTimeDepth ( ) const
Returns
The time between which the front of the queue was posted and the back of the queue was posted.

Definition at line 78 of file Dispatcher.cxx.

◆ post()

bool resip::Dispatcher::post ( std::unique_ptr< resip::ApplicationMessage > &  work)
virtual

Posts a message to this thread bank.

Parameters
workThe message that conveys the work that needs to be done. It is understood that any information that needs to be conveyed back to the originator will be placed in the message by the Workers in the thread bank.
Returns
true iff this message was successfully posted. (This may not be the case if this Dispatcher is in the process of shutting down)

Definition at line 54 of file Dispatcher.cxx.

◆ resume()

void resip::Dispatcher::resume ( )

Resumes accepting work.

Definition at line 97 of file Dispatcher.cxx.

◆ shutdownAll()

void resip::Dispatcher::shutdownAll ( )

Shuts down the thread-bank.

Definition at line 104 of file Dispatcher.cxx.

◆ startAll()

void resip::Dispatcher::startAll ( )

Starts the thread bank.

Definition at line 122 of file Dispatcher.cxx.

◆ stop()

void resip::Dispatcher::stop ( )

This Dispatcher will stop accepting new work, but processing will continue normally on the messages already in the queue.

Definition at line 90 of file Dispatcher.cxx.

◆ workPoolSize()

int resip::Dispatcher::workPoolSize ( ) const
Returns
The number of workers in this thread bank.

Definition at line 84 of file Dispatcher.cxx.

Member Data Documentation

◆ mAcceptingWork

bool resip::Dispatcher::mAcceptingWork
protected

Definition at line 116 of file Dispatcher.hxx.

◆ mFifo

resip::TimeLimitFifo<resip::ApplicationMessage> resip::Dispatcher::mFifo
protected

Definition at line 115 of file Dispatcher.hxx.

◆ mMutex

resip::RWMutex resip::Dispatcher::mMutex
protected

Definition at line 121 of file Dispatcher.hxx.

◆ mShutdown

bool resip::Dispatcher::mShutdown
protected

Definition at line 117 of file Dispatcher.hxx.

◆ mStack

resip::SipStack* resip::Dispatcher::mStack

Definition at line 110 of file Dispatcher.hxx.

◆ mStarted

bool resip::Dispatcher::mStarted
protected

Definition at line 118 of file Dispatcher.hxx.

◆ mWorkerPrototype

Worker* resip::Dispatcher::mWorkerPrototype
protected

Definition at line 119 of file Dispatcher.hxx.

◆ mWorkerThreads

std::vector<WorkerThread*> resip::Dispatcher::mWorkerThreads
protected

Definition at line 123 of file Dispatcher.hxx.


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