Chatsync
bbffde5c0c672a526bdc83637acf66dc20a80fbf
|
#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 |
A thread-safe implementation of two connected channels sets. All input channels are redirected to every output channel.
Hub::Hub::Hub | ( | std::string const & | name | ) |
|
inline |
void Hub::Hub::activate | ( | ) |
Start message loop
|
inline |
Returns whether thread is running
void Hub::Hub::addChannel | ( | channeling::Channel * const | channel | ) |
Append channel accordingly to its direction
|
private |
Append one more input channel to list taking ownership
|
private |
Append one more output channel to list taking ownership
|
inline |
void Hub::Hub::deactivate | ( | ) |
Stop message loop
|
private |
Thread function with main event loop
|
inline |
void Hub::Hub::newMessage | ( | const messaging::message_ptr && | msg | ) |
New message receiving callback
msg | The message. Costref is used to pass ownership to this Hub. Must be normally passed using std::move() |
|
private |
Sleeps on _cond waiting for messages. When the message comes returns it.
|
private |
void Hub::Hub::tick | ( | ) |
Triggered on tick by main thread
|
private |
Shows the hub is still alive and channels should continue work
|
private |
Lock condvar
|
private |
Container for all input channels
|
private |
Messaging is active
|
private |
Message queue
|
private |
Message processing thread (created from msgLoop()
|
private |
Message queue lock
|
private |
Human-readable name
|
private |
Container for all output channels