unilink  0.4.3
A simple C++ library for unified async communication
unilink Namespace Reference

Namespaces

 
 
 
 
 
 
 
 
 
 
 
 
 

Classes

struct  ReconnectDecision
 Represents a decision on whether to retry a connection attempt. More...
 

Typedefs

using ReconnectPolicy = std::function< ReconnectDecision(const diagnostics::ErrorInfo &, uint32_t)>
 Function type for determining reconnection policy. More...
 
using TcpClient = wrapper::TcpClient
 
using TcpServer = wrapper::TcpServer
 
using Serial = wrapper::Serial
 
using Udp = wrapper::Udp
 
using MessageContext = wrapper::MessageContext
 
using ConnectionContext = wrapper::ConnectionContext
 
using ErrorContext = wrapper::ErrorContext
 

Enumerations

enum class  ErrorCode {
  Success = 0 , Unknown , InvalidConfiguration , InternalError ,
  IoError , ConnectionRefused , ConnectionReset , ConnectionAborted ,
  TimedOut , NotConnected , AlreadyConnected , PortInUse ,
  AccessDenied , Stopped , StartFailed
}
 Structured error codes for Unilink. More...
 

Functions

std::string to_string (ErrorCode code)
 Convert ErrorCode to human-readable string. More...
 
ReconnectPolicy FixedInterval (std::chrono::milliseconds delay)
 Creates a policy that retries with a fixed interval. More...
 
ReconnectPolicy ExponentialBackoff (std::chrono::milliseconds min_delay, std::chrono::milliseconds max_delay, double factor=2.0, bool jitter=true)
 Creates a policy that retries with exponential backoff. More...
 
builder::TcpServerBuilder tcp_server (uint16_t port)
 Create a TCP server builder. More...
 
builder::TcpClientBuilder tcp_client (const std::string &host, uint16_t port)
 Create a TCP client builder. More...
 
builder::SerialBuilder serial (const std::string &device, uint32_t baud_rate)
 Create a Serial port builder. More...
 
builder::UdpBuilder udp (uint16_t local_port)
 Create a UDP builder. More...
 

Typedef Documentation

◆ ConnectionContext

Definition at line 93 of file unilink.hpp.

◆ ErrorContext

Definition at line 94 of file unilink.hpp.

◆ MessageContext

Definition at line 92 of file unilink.hpp.

◆ ReconnectPolicy

using unilink::ReconnectPolicy = typedef std::function<ReconnectDecision(const diagnostics::ErrorInfo&, uint32_t)>

Function type for determining reconnection policy.

Accepts the last error information and the current attempt count (0-based). Returns a ReconnectDecision.

Definition at line 46 of file reconnect_policy.hpp.

◆ Serial

Definition at line 88 of file unilink.hpp.

◆ TcpClient

Definition at line 86 of file unilink.hpp.

◆ TcpServer

Definition at line 87 of file unilink.hpp.

◆ Udp

using unilink::Udp = typedef wrapper::Udp

Definition at line 89 of file unilink.hpp.

Enumeration Type Documentation

◆ ErrorCode

enum unilink::ErrorCode
strong

Structured error codes for Unilink.

Enumerator
Success 
Unknown 
InvalidConfiguration 
InternalError 
IoError 
ConnectionRefused 
ConnectionReset 
ConnectionAborted 
TimedOut 
NotConnected 
AlreadyConnected 
PortInUse 
AccessDenied 
Stopped 
StartFailed 

Definition at line 26 of file error_codes.hpp.

Function Documentation

◆ ExponentialBackoff()

ReconnectPolicy unilink::ExponentialBackoff ( std::chrono::milliseconds  min_delay,
std::chrono::milliseconds  max_delay,
double  factor = 2.0,
bool  jitter = true 
)
inline

Creates a policy that retries with exponential backoff.

Parameters
min_delayThe initial delay.
max_delayThe maximum delay cap.
factorThe multiplier for each retry (default 2.0).
jitterWhether to add randomization to the delay (default true).
Returns
A ReconnectPolicy function.

Definition at line 72 of file reconnect_policy.hpp.

◆ FixedInterval()

ReconnectPolicy unilink::FixedInterval ( std::chrono::milliseconds  delay)
inline

Creates a policy that retries with a fixed interval.

Parameters
delayThe delay between retries.
Returns
A ReconnectPolicy function.

Definition at line 54 of file reconnect_policy.hpp.

◆ serial()

builder::SerialBuilder unilink::serial ( const std::string &  device,
uint32_t  baud_rate 
)
inline

Create a Serial port builder.

Parameters
deviceThe serial device path (e.g., "/dev/ttyUSB0")
baud_rateThe baud rate for serial communication
Returns
SerialBuilder A configured builder for Serial

Definition at line 121 of file unilink.hpp.

◆ tcp_client()

builder::TcpClientBuilder unilink::tcp_client ( const std::string &  host,
uint16_t  port 
)
inline

Create a TCP client builder.

Parameters
hostThe host address to connect to
portThe port number to connect to
Returns
TcpClientBuilder A configured builder for TcpClient

Definition at line 111 of file unilink.hpp.

◆ tcp_server()

builder::TcpServerBuilder unilink::tcp_server ( uint16_t  port)
inline

Create a TCP server builder.

Parameters
portThe port number for the server
Returns
TcpServerBuilder A configured builder for TcpServer

Definition at line 103 of file unilink.hpp.

◆ to_string()

std::string unilink::to_string ( ErrorCode  code)
inline

Convert ErrorCode to human-readable string.

Definition at line 53 of file error_codes.hpp.

◆ udp()

builder::UdpBuilder unilink::udp ( uint16_t  local_port)
inline

Create a UDP builder.

Parameters
local_portThe local port to bind
Returns
UdpBuilder A configured builder for UDP

Definition at line 130 of file unilink.hpp.