NSCpp 2.0
NSCpp is a modern C++20 server/client framework designed to simplify network programming in C++. With robust support for both IPv4 and IPv6, as well as TCP and UDP communication protocols.
 
Loading...
Searching...
No Matches
Channel Class Referenceabstract

#include <Channel.h>

Inheritance diagram for Channel:
DebugChannel HelperChannel LogChannel

Public Member Functions

 Channel (const std::string &key)
 Constructor of the Channel's class.
 
void setKey (const std::string &key)
 Defined the Channel's key.
 
const std::string & getKey ()
 Return the Channel's key.
 
void setState (ChannelState state)
 Change the state of the server.
 
void push (ClientData data)
 Add the given data at the end of the queue.
 
ClientData pull ()
 Pop the first data from the queue and return it.
 
bool available ()
 Return true if data is available inside the dataQueue, false otherwise.
 
virtual void run (std::stop_token st)=0
 This method is run in a Thread and handle the Channel.
 

Protected Attributes

std::string key
 This key must be unique on the server on which it is plugged.
 
std::queue< ClientDatadataQueue
 This queue is used to store (and read) the data send to the Channel by the Server.
 
ChannelState state
 Control if the channel is active or not.
 

Constructor & Destructor Documentation

◆ Channel()

Channel::Channel ( const std::string & key)

Constructor of the Channel's class.

Channel is an abstract class, you need to implement its run method in its specialization.

Parameters
keyChannel's key.

Member Function Documentation

◆ available()

bool Channel::available ( )

Return true if data is available inside the dataQueue, false otherwise.

◆ getKey()

const std::string & Channel::getKey ( )

Return the Channel's key.

◆ pull()

ClientData Channel::pull ( )

Pop the first data from the queue and return it.

Handles automatically the lock.

◆ push()

void Channel::push ( ClientData data)

Add the given data at the end of the queue.

Handles automatically the lock.

Parameters
dataClientData structure holding the data from the event.

◆ run()

virtual void Channel::run ( std::stop_token st)
pure virtual

This method is run in a Thread and handle the Channel.

Parameters
Stoptoken used to stop the run loop.

Implemented in DebugChannel, HelperChannel, and LogChannel.

◆ setKey()

void Channel::setKey ( const std::string & key)

Defined the Channel's key.

Warning
It will not update the key on the server. You should unplug the channel, change its key and then re-plugged it for the new key to be effective.
Parameters
keyNew Channel's key.

◆ setState()

void Channel::setState ( ChannelState state)

Change the state of the server.

States are ChannelState::Active or ChannelState::Inactive

When inactive a channel will not received any data even if it is triggered by a client.

Parameters
stateNew state to apply.

Member Data Documentation

◆ dataQueue

std::queue<ClientData> Channel::dataQueue
protected

This queue is used to store (and read) the data send to the Channel by the Server.

◆ key

std::string Channel::key
protected

This key must be unique on the server on which it is plugged.

◆ state

ChannelState Channel::state
protected

Control if the channel is active or not.


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