Chatsync  bbffde5c0c672a526bdc83637acf66dc20a80fbf
ircChannel::IrcChannel Class Reference

#include <ircchannel.hpp>

Inheritance diagram for ircChannel::IrcChannel:
channeling::Channel

Public Member Functions

 IrcChannel (Hub::Hub *hub, const std::string &config)
 
 ~IrcChannel ()
 
std::string type () const override
 
- Public Member Functions inherited from channeling::Channel
 Channel (Hub::Hub *const hub, const std::string &config)
 
virtual ~Channel ()
 
virtual std::string const & name () const
 
ChannelDirection direction () const
 
virtual int connect (const std::string &hostname, const uint32_t port) const
 
virtual int send (const uint32_t fd, const std::string &msg) const
 
virtual int send (const std::string &msg) const
 
virtual int disconnect (const uint32_t fd) const
 
virtual int disconnect () const
 

Protected Member Functions

void tick () override
 
void incoming (const messaging::message_ptr &&msg) override
 
- Protected Member Functions inherited from channeling::Channel
virtual void pollThread ()
 
void startPolling ()
 
void stopPolling ()
 

Private Member Functions

void registerConnection ()
 
void ping ()
 
void pong () const
 
void checkTimeout ()
 
std::future< void > activate () override
 
const messaging::message_ptr parse (const char *line) const override
 
const messaging::message_ptr parseImpl (const std::string &toParse) const
 

Private Attributes

const std::string _server
 
const uint32_t _port
 
const std::string _channel
 
std::chrono::time_point< std::chrono::high_resolution_clock > _ping_time
 
std::mutex _pong_time_mutex
 
std::chrono::time_point< std::chrono::high_resolution_clock > _last_pong_time
 
std::atomic_bool _connection_issue
 

Static Private Attributes

static const channeling::ChannelCreatorImpl< IrcChannelcreator
 

Additional Inherited Members

- Data Fields inherited from channeling::Channel
const uint16_t _id
 
- Protected Attributes inherited from channeling::Channel
std::atomic_bool _active
 
std::unique_ptr< std::thread > _thread
 
std::atomic_bool _pipeRunning
 
int _fd
 
const config::ConfigParser _config
 
const std::string _name
 
const ChannelDirection _direction
 
Hub::Hub *const _hub
 

Detailed Description

IRC connection channel

Capable of connection an IRC server, joining one single channel and message transmission/receiving. Responds to PING with PONG to maintain connection.

Constructor & Destructor Documentation

§ IrcChannel()

ircChannel::IrcChannel::IrcChannel ( Hub::Hub hub,
const std::string &  config 
)
explicit

§ ~IrcChannel()

ircChannel::IrcChannel::~IrcChannel ( )

Member Function Documentation

§ activate()

std::future< void > ircChannel::IrcChannel::activate ( )
overrideprivatevirtual

Prepare all prerequisites for polling thread or prepare the output and start working

Opening file descriptors, connecting to network must be done here. After future is valid channel is considered to be ready for work.

Exceptions
activate_errorin case of problems

Implements channeling::Channel.

§ checkTimeout()

void ircChannel::IrcChannel::checkTimeout ( )
private

Checks if max_timeout is reached and calls ping()

Todo:
Add heuristics of timeout

§ incoming()

void ircChannel::IrcChannel::incoming ( const messaging::message_ptr &&  msg)
overrideprotectedvirtual

Parse line and send it to needed output place in case of Output direction

Parameters
msgIncoming message from hub. Passed by value to preserve ownership and ensure existence during processing in all output channels.

Implements channeling::Channel.

§ parse()

const messaging::message_ptr ircChannel::IrcChannel::parse ( const char *  line) const
overrideprivatevirtual

Parse a text line and generate a corresponding Message

Todo:
Decide if it should throw something
Parameters
lineText line from socket.
Return values
nullptrIf message was technical for protocol.
message_ptrIf useful payload found.

Implements channeling::Channel.

§ parseImpl()

const messaging::message_ptr ircChannel::IrcChannel::parseImpl ( const std::string &  toParse) const
private

§ ping()

void ircChannel::IrcChannel::ping ( )
private

Sends PING message to server

§ pong()

void ircChannel::IrcChannel::pong ( ) const
private

Reacts to PONG message from server

§ registerConnection()

void ircChannel::IrcChannel::registerConnection ( )
private

Sends PASS, NICK and USER commands to register irc connection

§ tick()

void ircChannel::IrcChannel::tick ( )
overrideprotectedvirtual

If during max_timeout*5 we got no PONG we try to reconnect

Reimplemented from channeling::Channel.

§ type()

std::string ircChannel::IrcChannel::type ( ) const
inlineoverridevirtual

Return channel "type" — unique string to identify channel in config file

Return values
std::stringType line

Implements channeling::Channel.

Field Documentation

§ _channel

const std::string ircChannel::IrcChannel::_channel
private

Channel name (starting with #)

§ _connection_issue

std::atomic_bool ircChannel::IrcChannel::_connection_issue
mutableprivate

< The connection issue has been detected, check is ongoing

§ _last_pong_time

std::chrono::time_point<std::chrono::high_resolution_clock> ircChannel::IrcChannel::_last_pong_time
mutableprivate

Last pong received from server

§ _ping_time

std::chrono::time_point<std::chrono::high_resolution_clock> ircChannel::IrcChannel::_ping_time
private

Ping to server in microseconds

§ _pong_time_mutex

std::mutex ircChannel::IrcChannel::_pong_time_mutex
mutableprivate

Lock for _last_pong_time

§ _port

const uint32_t ircChannel::IrcChannel::_port
private

Connection port

§ _server

const std::string ircChannel::IrcChannel::_server
private

Server address

§ creator

const channeling::ChannelCreatorImpl< IrcChannel > ircChannel::IrcChannel::creator
staticprivate

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