Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
SocketClientParams Class Referenceabstract

Abstract interface to represent parameters to the socket client. More...

#include <SocketClientParams.hxx>

Inheritance diagram for SocketClientParams:
EmptySocketClientParams DefaultSocketClientParams

Public Types

enum  SearchMode { AUTO_MANUAL = 0 , MANUAL_AUTO = 1 , AUTO_ONLY = 2 , MANUAL_ONLY = 3 }
 Parameter that determines what order we will attempt to connect. More...
 
enum  LogMessage {
  CYCLE_START = 0 , CONNECT_RE = 1 , MDNS_SEARCH = 2 , MDNS_NOT_FOUND = 3 ,
  MDNS_FOUND = 4 , CONNECT_MDNS = 5 , CONNECT_MANUAL = 6 , CONNECT_FAILED_SELF = 7 ,
  CONNECT_FAILED_ONESHOT = 8 , CONNECTION_LOST
}
 Enum for sending connection status updates to the caller. More...
 

Public Member Functions

virtual SearchMode search_mode ()=0
 
virtual string mdns_service_name ()=0
 
virtual string mdns_host_name ()=0
 
virtual string manual_host_name ()=0
 
virtual int manual_port ()=0
 
virtual bool enable_last ()=0
 
virtual string last_host_name ()=0
 
virtual int last_port ()=0
 
virtual bool one_shot ()
 
virtual void set_last (const char *hostname, int port)
 This function is called on an unspecified thread when a connection is successfully established.
 
virtual void log_message (LogMessage id, const string &arg=string())
 Notifies the caller about the current phase of the connection.
 
virtual int retry_seconds ()
 
virtual int timeout_seconds ()
 
virtual bool disallow_local ()
 

Static Public Member Functions

static std::unique_ptr< SocketClientParamsfrom_static (string hostname, int port)
 
static std::unique_ptr< SocketClientParamsfrom_static_and_mdns (string hostname, int port, string mdns_service)
 

Detailed Description

Abstract interface to represent parameters to the socket client.

This interface can be implemented just purely based on compiled-in values, filled in from optargs or wrapping a configuration location in an openlcb config space.

Implementations must be thread-safe (i.e. do locking internally; all functions of this class may be called from unspecified threads including also concurrently).

Definition at line 46 of file SocketClientParams.hxx.

Member Enumeration Documentation

◆ LogMessage

Enum for sending connection status updates to the caller.

Enumerator
CONNECT_RE 

Attempting to reconnect. Arg is host:port.

MDNS_SEARCH 

Starting mDNS lookup. Argument: mdns [hostname.]service_name.

MDNS_NOT_FOUND 

mDNS lookup failed.

MDNS_FOUND 

mDNS lookup suceeded.

CONNECT_MDNS 

Connecting to mDNS target. Arg is host:port.

CONNECT_MANUAL 

Connecting to manual target. Arg is hostname:port.

CONNECT_FAILED_SELF 

Connection dropped because target is localhost.

CONNECT_FAILED_ONESHOT 

Attempt to search & connect failed, given up. No arg.

Definition at line 128 of file SocketClientParams.hxx.

◆ SearchMode

Parameter that determines what order we will attempt to connect.

Enumerator
AUTO_MANUAL 

Try mDNS first, then (if it failed) try manual address.

MANUAL_AUTO 

Try manual address first, then (if it failed) try mDNS.

AUTO_ONLY 

Try only mDNS, ignore manual address.

MANUAL_ONLY 

Try only manual address, never try mDNS lookups.

Definition at line 69 of file SocketClientParams.hxx.

Constructor & Destructor Documentation

◆ ~SocketClientParams()

virtual SocketClientParams::~SocketClientParams ( )
inlinevirtual

Definition at line 64 of file SocketClientParams.hxx.

Member Function Documentation

◆ disallow_local()

virtual bool SocketClientParams::disallow_local ( )
inlinevirtual
Returns
true if we should actively skip connections that happen to match our own IP address.

Definition at line 174 of file SocketClientParams.hxx.

◆ enable_last()

virtual bool SocketClientParams::enable_last ( )
pure virtual
Returns
true if first attempt should be to connect to last_host_name:last_port.

Implemented in EmptySocketClientParams.

◆ from_static()

static std::unique_ptr< SocketClientParams > SocketClientParams::from_static ( string  hostname,
int  port 
)
static
Returns
a new socket client params instance that allows only manual connection.
Parameters
hostnameis the manual hostname
portis the manual port number

◆ from_static_and_mdns()

static std::unique_ptr< SocketClientParams > SocketClientParams::from_static_and_mdns ( string  hostname,
int  port,
string  mdns_service 
)
static
Returns
a new socket client params instance that allows only manual connection.
Parameters
hostnameis the manual hostname
portis the manual port number
mdns_serviceis the mdns service name

◆ last_host_name()

virtual string SocketClientParams::last_host_name ( )
pure virtual
Returns
the last successfully used IP address, as dotted decimal. Nullptr or empty if no successful connection has ever been made.

Implemented in EmptySocketClientParams.

◆ last_port()

virtual int SocketClientParams::last_port ( )
pure virtual
Returns
the last successfully used port number.

Implemented in EmptySocketClientParams.

◆ log_message()

virtual void SocketClientParams::log_message ( LogMessage  id,
const string &  arg = string() 
)
inlinevirtual

Notifies the caller about the current phase of the connection.

This function will be called from an unspecified thread, so the callee is responsible for locking.

Parameters
idis the enum of the message to emit.
argis a parameter to the message (usually hostname, IP address etc. Sometimes empty).

Definition at line 156 of file SocketClientParams.hxx.

◆ manual_host_name()

virtual string SocketClientParams::manual_host_name ( )
pure virtual
Returns
null or empty string if no manual address is configured. Otherwise a dotted-decimal IP address or a DNS hostname (not mDNS) for manual address to connect to.

Implemented in EmptySocketClientParams, and DefaultSocketClientParams.

◆ manual_port()

virtual int SocketClientParams::manual_port ( )
pure virtual
Returns
port number to use for manual connection.

Implemented in EmptySocketClientParams, and DefaultSocketClientParams.

◆ mdns_host_name()

virtual string SocketClientParams::mdns_host_name ( )
pure virtual
Returns
null or empty string if any mdns server is okay to connect to. If nonempty, then only an mdns server will be chosen that has the specific host name.

Implemented in EmptySocketClientParams.

◆ mdns_service_name()

virtual string SocketClientParams::mdns_service_name ( )
pure virtual
Returns
the service name to use for mDNS lookup; nullptr or empty string if mdns is not to be used.

Implemented in EmptySocketClientParams, and DefaultSocketClientParams.

◆ one_shot()

virtual bool SocketClientParams::one_shot ( )
inlinevirtual
Returns
false for repeated connection attempts, true if we should stop after the first failed connection attempt. If a one-stop mode fails, the caller has to delete and re-create the socket client.

Definition at line 116 of file SocketClientParams.hxx.

◆ retry_seconds()

virtual int SocketClientParams::retry_seconds ( )
inlinevirtual
Returns
Minimum time to spend between failed connection attempts.

Definition at line 161 of file SocketClientParams.hxx.

◆ search_mode()

virtual SearchMode SocketClientParams::search_mode ( )
pure virtual
Returns
search mode for how to locate the server.

Implemented in EmptySocketClientParams.

◆ set_last()

virtual void SocketClientParams::set_last ( const char *  hostname,
int  port 
)
inlinevirtual

This function is called on an unspecified thread when a connection is successfully established.

Parameters
hostnameis filled with a dotted decimal representation of the connected remote host when the connection succeeds.
portis the TCP port number.

Definition at line 123 of file SocketClientParams.hxx.

◆ timeout_seconds()

virtual int SocketClientParams::timeout_seconds ( )
inlinevirtual
Returns
How long to wait for connections to be established.

Definition at line 167 of file SocketClientParams.hxx.


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