Chatsync  bbffde5c0c672a526bdc83637acf66dc20a80fbf
Hub::Hub Class Reference

#include <hub.hpp>

Public Member Functions

 Hub (std::string const &name)
 
 ~Hub ()
 
const std::string & name () const
 
std::shared_ptr< std::atomic< bool > > alive () const
 
void addChannel (channeling::Channel *const)
 
void newMessage (const messaging::message_ptr &&msg)
 
void activate ()
 
void deactivate ()
 
bool active ()
 
void tick ()
 

Private Member Functions

void addInput (channeling::Channel *const)
 
void addOutput (channeling::Channel *const)
 
const messaging::message_ptr popMessage ()
 
void pushMessage (const messaging::message_ptr &&item)
 
void msgLoop ()
 

Private Attributes

const std::string _name
 
std::list< chanPtr_inputChannels
 
std::list< chanPtr_outputChannels
 
std::queue< messaging::message_ptr_messages
 
std::mutex _mutex
 
std::condition_variable _cond
 
std::unique_ptr< std::thread > _msgLoop
 
std::atomic_bool _loopRunning
 
std::shared_ptr< std::atomic< bool > > _alive
 

Detailed Description

A thread-safe implementation of two connected channels sets. All input channels are redirected to every output channel.

Constructor & Destructor Documentation

§ Hub()

Hub::Hub::Hub ( std::string const &  name)

§ ~Hub()

Hub::Hub::~Hub ( )
inline

Member Function Documentation

§ activate()

void Hub::Hub::activate ( )

Start message loop

§ active()

bool Hub::Hub::active ( )
inline

Returns whether thread is running

§ addChannel()

void Hub::Hub::addChannel ( channeling::Channel * const  channel)

Append channel accordingly to its direction

§ addInput()

void Hub::Hub::addInput ( channeling::Channel * const  channel)
private

Append one more input channel to list taking ownership

§ addOutput()

void Hub::Hub::addOutput ( channeling::Channel * const  channel)
private

Append one more output channel to list taking ownership

§ alive()

std::shared_ptr<std::atomic<bool> > Hub::Hub::alive ( ) const
inline

§ deactivate()

void Hub::Hub::deactivate ( )

Stop message loop

§ msgLoop()

void Hub::Hub::msgLoop ( )
private

Thread function with main event loop

§ name()

const std::string& Hub::Hub::name ( ) const
inline

§ newMessage()

void Hub::Hub::newMessage ( const messaging::message_ptr &&  msg)

New message receiving callback

Parameters
msgThe message. Costref is used to pass ownership to this Hub. Must be normally passed using std::move()

§ popMessage()

const messaging::message_ptr Hub::Hub::popMessage ( )
private

Sleeps on _cond waiting for messages. When the message comes returns it.

Returns
Incoming message from _messages queue.

§ pushMessage()

void Hub::Hub::pushMessage ( const messaging::message_ptr &&  item)
private

§ tick()

void Hub::Hub::tick ( )

Triggered on tick by main thread

Field Documentation

§ _alive

std::shared_ptr<std::atomic<bool> > Hub::Hub::_alive
private

Shows the hub is still alive and channels should continue work

§ _cond

std::condition_variable Hub::Hub::_cond
private

Lock condvar

§ _inputChannels

std::list<chanPtr> Hub::Hub::_inputChannels
private

Container for all input channels

§ _loopRunning

std::atomic_bool Hub::Hub::_loopRunning
private

Messaging is active

§ _messages

std::queue<messaging::message_ptr> Hub::Hub::_messages
private

Message queue

§ _msgLoop

std::unique_ptr<std::thread> Hub::Hub::_msgLoop
private

Message processing thread (created from msgLoop()

§ _mutex

std::mutex Hub::Hub::_mutex
private

Message queue lock

§ _name

const std::string Hub::Hub::_name
private

Human-readable name

§ _outputChannels

std::list<chanPtr> Hub::Hub::_outputChannels
private

Container for all output channels


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