HiveMindBridge
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TCPServer Class Reference

#include <TCPServer.h>

Inheritance diagram for TCPServer:
Inheritance graph
Collaboration diagram for TCPServer:
Collaboration graph

Public Member Functions

 TCPServer (int port, ILogger &logger)
 
 ~TCPServer ()
 
void listen ()
 
bool receive (uint8_t *data, uint16_t length) override
 
bool send (const uint8_t *data, uint16_t length) override
 
void close () override
 
bool isClientConnected () override
 
void onConnect (std::function< void()> hook) override
 
void onDisconnect (std::function< void()> hook) override
 

Private Member Functions

void init ()
 

Private Attributes

ILogger & m_logger
 
int m_serverFd
 
int m_clientFd
 
int m_port
 
int m_addressLength
 
struct sockaddr_in m_address
 
bool m_isClientConnected = false
 
std::function< void()> m_onConnect
 
std::function< void()> m_onDisonnect
 

Constructor & Destructor Documentation

◆ TCPServer()

TCPServer::TCPServer ( int  port,
ILogger &  logger 
)

Construct a TCPServer

Parameters
portPort to open the server to
loggerused to log info of the server
Here is the call graph for this function:

◆ ~TCPServer()

TCPServer::~TCPServer ( )
Here is the call graph for this function:

Member Function Documentation

◆ close()

void TCPServer::close ( )
overridevirtual

Terminate a client connection.

Implements ITCPServer.

Here is the caller graph for this function:

◆ init()

void TCPServer::init ( )
private

Create and bind the socket.

Here is the caller graph for this function:

◆ isClientConnected()

bool TCPServer::isClientConnected ( )
overridevirtual

See if the server has a client connected

Returns
true if the TCP server has a client connected.

Implements ITCPServer.

◆ listen()

void TCPServer::listen ( )
virtual

Start listening for incoming client connections and accept one client. This is blocking until a client connects.

Implements ITCPServer.

◆ onConnect()

void TCPServer::onConnect ( std::function< void()>  hook)
overridevirtual

Register a callback to be run when a TCP connection is established with a client HiveMind

Parameters
hookThe function to be run

Implements ITCPServer.

◆ onDisconnect()

void TCPServer::onDisconnect ( std::function< void()>  hook)
overridevirtual

Register a callback to be run as soon as the TCP Server notices that the connection was lost.

Parameters
hookThe function to be run

Implements ITCPServer.

◆ receive()

bool TCPServer::receive ( uint8_t *  data,
uint16_t  length 
)
overridevirtual

Read data from socket.

Parameters
dataThe buffer on which the incoming data will be written.
lengthThe length of the provided buffer.
Returns
The length of the data read.

Implements ITCPServer.

Here is the call graph for this function:

◆ send()

bool TCPServer::send ( const uint8_t *  data,
uint16_t  length 
)
overridevirtual

Send some data to the client.

Parameters
dataThe buffer containing the data to send.
lengthThe length of the data on the buffer.

Implements ITCPServer.

Member Data Documentation

◆ m_address

struct sockaddr_in TCPServer::m_address
private

◆ m_addressLength

int TCPServer::m_addressLength
private

◆ m_clientFd

int TCPServer::m_clientFd
private

◆ m_isClientConnected

bool TCPServer::m_isClientConnected = false
private

◆ m_logger

ILogger& TCPServer::m_logger
private

◆ m_onConnect

std::function<void()> TCPServer::m_onConnect
private

◆ m_onDisonnect

std::function<void()> TCPServer::m_onDisonnect
private

◆ m_port

int TCPServer::m_port
private

◆ m_serverFd

int TCPServer::m_serverFd
private

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