Ember
Loading...
Searching...
No Matches
Ember::Monitor::TCPServer Class Reference

Single-client TCP server for receiving behavior tree data from monitored applications. More...

#include <TCPServer.h>

Public Types

using MessageCallback = std::function<void(const Network::MessageFrame &)>
 Callback invoked when a message is received from the client.
using ConnectCallback = std::function<void(const std::string &address)>
 Callback invoked when a client connects.
using DisconnectCallback = std::function<void()>
 Callback invoked when the client disconnects.

Public Member Functions

 TCPServer ()
 ~TCPServer ()
bool Start (uint16_t port)
 Starts the server listening on the given port. Returns true on success.
void Stop ()
 Stops the server and disconnects any client.
bool IsRunning () const
 Returns true if the server is listening.
bool IsClientConnected () const
 Returns true if a client is currently connected.
std::string GetClientAddress () const
 Returns the connected client's address string.
std::string GetClientName () const
 Returns the client's display name.
void SetClientName (const std::string &name)
 Sets the client's display name.
uint16_t GetPort () const
 Returns the port the server is listening on.
void SetMessageCallback (MessageCallback cb)
 Sets the callback for incoming messages.
void SetConnectCallback (ConnectCallback cb)
 Sets the callback for client connections.
void SetDisconnectCallback (DisconnectCallback cb)
 Sets the callback for client disconnections.
void Poll ()
 Processes pending I/O (accept, read). Call periodically from the main loop.
bool Send (const Network::MessageFrame &frame)
 Sends a message frame to the connected client. Returns true on success.
void DisconnectClient ()
 Disconnects the current client without stopping the server.

Private Member Functions

void AcceptConnection ()
void ReadFromClient ()
bool SetNonBlocking (int socket)

Private Attributes

int m_serverSocket = -1
int m_clientSocket = -1
std::string m_clientAddress
std::string m_clientName
uint16_t m_port = 0
std::vector< uint8_t > m_recvBuffer
MessageCallback m_messageCallback
ConnectCallback m_connectCallback
DisconnectCallback m_disconnectCallback

Detailed Description

Single-client TCP server for receiving behavior tree data from monitored applications.

Definition at line 14 of file TCPServer.h.

Member Typedef Documentation

◆ ConnectCallback

using Ember::Monitor::TCPServer::ConnectCallback = std::function<void(const std::string &address)>

Callback invoked when a client connects.

Definition at line 19 of file TCPServer.h.

◆ DisconnectCallback

using Ember::Monitor::TCPServer::DisconnectCallback = std::function<void()>

Callback invoked when the client disconnects.

Definition at line 21 of file TCPServer.h.

◆ MessageCallback

Callback invoked when a message is received from the client.

Definition at line 17 of file TCPServer.h.

Constructor & Destructor Documentation

◆ TCPServer()

Ember::Monitor::TCPServer::TCPServer ( )

Definition at line 15 of file TCPServer.cpp.

◆ ~TCPServer()

Ember::Monitor::TCPServer::~TCPServer ( )

Definition at line 17 of file TCPServer.cpp.

Member Function Documentation

◆ AcceptConnection()

void Ember::Monitor::TCPServer::AcceptConnection ( )
private

Definition at line 96 of file TCPServer.cpp.

◆ DisconnectClient()

void Ember::Monitor::TCPServer::DisconnectClient ( )

Disconnects the current client without stopping the server.

Definition at line 82 of file TCPServer.cpp.

◆ GetClientAddress()

std::string Ember::Monitor::TCPServer::GetClientAddress ( ) const
inline

Returns the connected client's address string.

Definition at line 36 of file TCPServer.h.

◆ GetClientName()

std::string Ember::Monitor::TCPServer::GetClientName ( ) const
inline

Returns the client's display name.

Definition at line 38 of file TCPServer.h.

◆ GetPort()

uint16_t Ember::Monitor::TCPServer::GetPort ( ) const
inline

Returns the port the server is listening on.

Definition at line 42 of file TCPServer.h.

◆ IsClientConnected()

bool Ember::Monitor::TCPServer::IsClientConnected ( ) const
inline

Returns true if a client is currently connected.

Definition at line 33 of file TCPServer.h.

◆ IsRunning()

bool Ember::Monitor::TCPServer::IsRunning ( ) const
inline

Returns true if the server is listening.

Definition at line 31 of file TCPServer.h.

◆ Poll()

void Ember::Monitor::TCPServer::Poll ( )

Processes pending I/O (accept, read). Call periodically from the main loop.

Definition at line 173 of file TCPServer.cpp.

◆ ReadFromClient()

void Ember::Monitor::TCPServer::ReadFromClient ( )
private

Definition at line 125 of file TCPServer.cpp.

◆ Send()

bool Ember::Monitor::TCPServer::Send ( const Network::MessageFrame & frame)

Sends a message frame to the connected client. Returns true on success.

Definition at line 209 of file TCPServer.cpp.

◆ SetClientName()

void Ember::Monitor::TCPServer::SetClientName ( const std::string & name)
inline

Sets the client's display name.

Definition at line 40 of file TCPServer.h.

◆ SetConnectCallback()

void Ember::Monitor::TCPServer::SetConnectCallback ( ConnectCallback cb)
inline

Sets the callback for client connections.

Definition at line 47 of file TCPServer.h.

◆ SetDisconnectCallback()

void Ember::Monitor::TCPServer::SetDisconnectCallback ( DisconnectCallback cb)
inline

Sets the callback for client disconnections.

Definition at line 49 of file TCPServer.h.

◆ SetMessageCallback()

void Ember::Monitor::TCPServer::SetMessageCallback ( MessageCallback cb)
inline

Sets the callback for incoming messages.

Definition at line 45 of file TCPServer.h.

◆ SetNonBlocking()

bool Ember::Monitor::TCPServer::SetNonBlocking ( int socket)
private

Definition at line 19 of file TCPServer.cpp.

◆ Start()

bool Ember::Monitor::TCPServer::Start ( uint16_t port)

Starts the server listening on the given port. Returns true on success.

Definition at line 27 of file TCPServer.cpp.

◆ Stop()

void Ember::Monitor::TCPServer::Stop ( )

Stops the server and disconnects any client.

Definition at line 72 of file TCPServer.cpp.

Member Data Documentation

◆ m_clientAddress

std::string Ember::Monitor::TCPServer::m_clientAddress
private

Definition at line 67 of file TCPServer.h.

◆ m_clientName

std::string Ember::Monitor::TCPServer::m_clientName
private

Definition at line 68 of file TCPServer.h.

◆ m_clientSocket

int Ember::Monitor::TCPServer::m_clientSocket = -1
private

Definition at line 66 of file TCPServer.h.

◆ m_connectCallback

ConnectCallback Ember::Monitor::TCPServer::m_connectCallback
private

Definition at line 74 of file TCPServer.h.

◆ m_disconnectCallback

DisconnectCallback Ember::Monitor::TCPServer::m_disconnectCallback
private

Definition at line 75 of file TCPServer.h.

◆ m_messageCallback

MessageCallback Ember::Monitor::TCPServer::m_messageCallback
private

Definition at line 73 of file TCPServer.h.

◆ m_port

uint16_t Ember::Monitor::TCPServer::m_port = 0
private

Definition at line 69 of file TCPServer.h.

◆ m_recvBuffer

std::vector<uint8_t> Ember::Monitor::TCPServer::m_recvBuffer
private

Definition at line 71 of file TCPServer.h.

◆ m_serverSocket

int Ember::Monitor::TCPServer::m_serverSocket = -1
private

Definition at line 65 of file TCPServer.h.


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