Chatsync  bbffde5c0c672a526bdc83637acf66dc20a80fbf
fileChannel::FileChannel Class Reference

#include <filechannel.hpp>

Inheritance diagram for fileChannel::FileChannel:
channeling::Channel

Public Member Functions

 FileChannel (Hub::Hub *hub, const std::string &config)
 
 ~FileChannel ()
 
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
 
virtual void tick ()
 

Protected Member Functions

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

int openPipe (const std::string &filename)
 
std::future< void > activate () override
 
const messaging::message_ptr parse (const char *line) const override
 

Private Attributes

std::fstream _file
 

Static Private Attributes

static const channeling::ChannelCreatorImpl< FileChannelcreator
 

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

File channel

May be useful for logging

Constructor & Destructor Documentation

§ FileChannel()

fileChannel::FileChannel::FileChannel ( Hub::Hub hub,
const std::string &  config 
)
explicit

§ ~FileChannel()

fileChannel::FileChannel::~FileChannel ( )

Member Function Documentation

§ activate()

std::future< void > fileChannel::FileChannel::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.

§ incoming()

void fileChannel::FileChannel::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.

§ openPipe()

int fileChannel::FileChannel::openPipe ( const std::string &  filename)
private

Opens input pipe

Parameters
filenamePipe name with full path (if needed)
Return values
intFile descriptor
Exceptions
Channeling::activate_errorwhen can't open file

§ parse()

const messaging::message_ptr fileChannel::FileChannel::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.

§ type()

std::string fileChannel::FileChannel::type ( ) const
inlineoverridevirtual

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

Return values
std::stringType line

Implements channeling::Channel.

Field Documentation

§ _file

std::fstream fileChannel::FileChannel::_file
private

File stream to save log

§ creator

const channeling::ChannelCreatorImpl< FileChannel > fileChannel::FileChannel::creator
staticprivate

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