VLink  2.0.0
A high-performance communication middleware
vlink::ProxyAPI Class Reference

Client-side proxy monitoring and control surface backed by a MessageLoop. More...

#include <proxy_api.h>

Inheritance diagram for vlink::ProxyAPI:
Collaboration diagram for vlink::ProxyAPI:

Classes

struct  Config
 Construction-time configuration aggregate for ProxyAPI. More...
 
struct  Control
 Control message sent from a kController instance to ProxyServer. More...
 
struct  Data
 Raw message payload delivered via DataCallback or sent via send_data(). More...
 
struct  Info
 Statistics and metadata describing one discovered topic endpoint. More...
 
struct  Process
 Description of a VLink node process attached to a topic endpoint. More...
 
struct  UrlMeta
 Pairs a topic URL with its serialisation type and node role. More...
 

Public Types

enum  Mode : uint8_t {
  kOffline = 0 , kObserveOne = 1 , kObserveAll = 2 , kRecord = 3 ,
  kPlay = 4 , kEdit = 5 , kAuto = 6 , kAutoAndObserveAll = 7
}
 Proxy operation modes published via send_control(). More...
 
enum  Error : uint8_t {
  kNoError = 0 , kModeError = 1 , kControlError = 2 , kReliableCompError = 3 ,
  kTcpCompError = 4 , kDirectCompError = 5 , kMultiProxyError = 7 , kVersionCompError = 8 ,
  kTokenError = 9 , kUnknownError = 10
}
 Compatibility and protocol error codes reported through ErrorCallback. More...
 
enum  Status : uint8_t { kActive = 0 , kInActive = 1 , kPending = 2 , kInvalid = 3 }
 Per-topic activity status reported inside Info records. More...
 
enum  Role : uint8_t { kController = 0 , kListener }
 Role this ProxyAPI instance plays towards the ProxyServer. More...
 
using ConnectCallback = MoveFunction< void(bool connected)>
 Callback fired when the connection state with ProxyServer changes. More...
 
using ErrorCallback = MoveFunction< void(Error error)>
 Callback fired on each error-state transition. More...
 
using TimeCallback = MoveFunction< void(uint64_t sys_time, uint64_t boot_time)>
 Callback delivering the server's wall-clock and boot-time from each heartbeat. More...
 
using InfoCallback = MoveFunction< void(const std::vector< Info > &info_list)>
 Callback delivering the per-topic statistics list once per second. More...
 
using DataCallback = MoveFunction< void(const Data &data)>
 Callback delivering raw message data from the active proxy data path. More...
 
 Internal queue implementation type. More...
 Back-pressure strategy applied when the bounded queue is at capacity. More...
 Built-in priority levels for kPriorityType loops; higher values dispatch first. More...

Public Member Functions

 ProxyAPI (const Config &config)
 Constructs a ProxyAPI using the supplied configuration. More...
 
 ~ProxyAPI () override
 Destroys the ProxyAPI and releases every transport handle. More...
 
void register_connect_callback (ConnectCallback &&callback)
 Registers a callback for connection-state changes. More...
 
void register_error_callback (ErrorCallback &&callback)
 Registers a callback for error-state transitions. More...
 
void register_time_callback (TimeCallback &&callback)
 Registers a callback for heartbeat timestamp delivery. More...
 
void register_info_callback (InfoCallback &&callback)
 Registers a callback for per-topic statistics updates. More...
 
void register_data_callback (DataCallback &&callback)
 Registers a callback for raw message data relayed by the server. More...
 
bool send_control (const Control &control, bool async=true)
 Publishes a Control message to the ProxyServer. More...
 
bool send_data (const Data &data)
 Injects raw message data into the proxy data path. More...
 
const Configget_current_config () const
 Returns the configuration supplied at construction. More...
 
Mode get_current_mode () const
 Returns the most recently requested proxy operation mode. More...
 
Error get_current_error () const
 Returns the current error state. More...
 
std::string get_current_hostname () const
 Returns the hostname of the connected ProxyServer. More...
 
std::string get_current_machine_id () const
 Returns the machine ID of the connected ProxyServer. More...
 
uint64_t get_current_sys_time () const
 Returns the best estimate of the server's current wall-clock time. More...
 
uint64_t get_current_boot_time () const
 Returns the best estimate of the server's current boot time. More...
 
double get_current_cpu_usage () const
 Returns the server's most recently reported CPU utilisation. More...
 
double get_current_memory_usage () const
 Returns the server's most recently reported memory utilisation. More...
 
int64_t get_latency () const
 Returns the latest backend-reported latency on the data channel. More...
 
SampleLostInfo get_lost () const
 Returns the sample-loss statistics on the data channel. More...
 
bool is_connected () const
 Returns whether a valid connection to ProxyServer exists. More...
 
std::string get_proxy_version () const
 Returns the VLINK_VERSION string reported by the server. More...
 
std::unordered_set< std::string > get_proxy_hostnames () const
 Returns every server hostname observed during this session. More...
 
std::unordered_set< std::string > get_proxy_machine_ids () const
 Returns every server machine ID observed during this session. More...
 

Static Public Member Functions

static bool is_support_shm ()
 Returns true when the build includes SHM (Iceoryx) support. More...
 
static bool is_enable_filter ()
 Returns true when topic filtering support is compiled in. More...
 
static std::string get_format_sys_time (uint64_t time, bool enable_utc=false)
 Formats a microsecond wall-clock timestamp as a human-readable string. More...
 
static std::string get_format_boot_time (uint64_t time)
 Formats a microsecond boot-time duration as a human-readable string. More...
 

Protected Member Functions

size_t get_max_task_count () const override
 Returns the maximum queue depth. More...
 
uint32_t get_max_elapsed_time () const override
 Returns the maximum allowed task execution time in milliseconds. More...
 
void on_begin () override
 Hook invoked once on the loop thread before the first task runs. More...
 
void on_end () override
 Hook invoked once on the loop thread after the last task runs. More...
 

Detailed Description

Client-side proxy monitoring and control surface backed by a MessageLoop.

Connects to a ProxyServer over security-authenticated DDS control channels and exposes registration entry points for connection state, error transitions, heartbeat timestamps, per-topic statistics, and raw data payloads. In direct mode data payloads ride on locally-created SHM channels instead of the server-relayed data channel. Inherits MessageLoop; start the loop with run() or async_run() so the handshake retries, heartbeat timer, handle reset, and async control posts can execute.

Member Typedef Documentation

◆ ConnectCallback

using vlink::ProxyAPI::ConnectCallback = MoveFunction<void(bool connected)>

Callback fired when the connection state with ProxyServer changes.

connected becomes true on the first valid heartbeat and false after five seconds of heartbeat silence or when the control channel reports disconnection.

◆ DataCallback

using vlink::ProxyAPI::DataCallback = MoveFunction<void(const Data& data)>

Callback delivering raw message data from the active proxy data path.

Fires for every message forwarded in observe, record, or auto modes. In non-direct mode the bytes are relayed by ProxyServer; in direct mode they come from local direct subscribers. Data::raw is shallow-borrowed – copy it if you must retain it past the callback.

◆ ErrorCallback

Callback fired on each error-state transition.

Only invoked when Error changes – for instance from kNoError to kVersionCompError, or back to kNoError.

◆ InfoCallback

using vlink::ProxyAPI::InfoCallback = MoveFunction<void(const std::vector<Info>& info_list)>

Callback delivering the per-topic statistics list once per second.

Parameters
info_listFiltered discovery records relevant to the current mode, including their status fields.

◆ TimeCallback

using vlink::ProxyAPI::TimeCallback = MoveFunction<void(uint64_t sys_time, uint64_t boot_time)>

Callback delivering the server's wall-clock and boot-time from each heartbeat.

Parameters
sys_timeServer system time in microseconds since the Unix epoch.
boot_timeServer uptime in microseconds since boot.

Member Enumeration Documentation

◆ Error

enum vlink::ProxyAPI::Error : uint8_t

Compatibility and protocol error codes reported through ErrorCallback.

Errors are produced when the client parses an incoming Time heartbeat or a handshake response; the callback fires only when the error state changes.

Enumerator
kNoError 

No error; the connection is healthy.

kModeError 

Reserved legacy code; unsupported modes are ignored server-side.

kControlError 

Server responded with a different control_id.

kReliableCompError 

reliable setting differs between client and server.

kTcpCompError 

enable_tcp setting differs between client and server.

kDirectCompError 

direct setting differs between client and server.

kMultiProxyError 

Multiple proxy servers, or Time identity differs from the handshake.

kVersionCompError 

VLINK_VERSION string differs between client and server.

kTokenError 

Handshake refused/empty token or identity-matching token mismatch.

kUnknownError 

Unknown or unclassified error.

◆ Mode

enum vlink::ProxyAPI::Mode : uint8_t

Proxy operation modes published via send_control().

The mode governs what the ProxyServer observes or what the controller may inject. Only a kController instance may switch the mode.

Enumerator
kOffline 

Disconnected; server releases every subscription.

kObserveOne 

Observe a single topic taken from the URL list.

kObserveAll 

Observe every discovered topic on the network.

kRecord 

Record data from topics in the URL list.

kPlay 

Injection/playback mode, usually fed by recorded data.

kEdit 

Forward data injected by the controller.

kAuto 

Observe specified URLs and accept controller injection.

kAutoAndObserveAll 

Observe every topic and accept controller injection.

◆ Role

enum vlink::ProxyAPI::Role : uint8_t

Role this ProxyAPI instance plays towards the ProxyServer.

kController may call send_control() and send_data(). kListener is a passive observer; send calls return false immediately.

Enumerator
kController 
kListener 

◆ Status

enum vlink::ProxyAPI::Status : uint8_t

Per-topic activity status reported inside Info records.

Enumerator
kActive 

Topic is actively receiving data.

kInActive 

Topic exists but has not produced data recently.

kPending 

Topic was just discovered; statistics are still accumulating.

kInvalid 

Topic type does not support observation (e.g. subscriber-only).

Constructor & Destructor Documentation

◆ ProxyAPI()

vlink::ProxyAPI::ProxyAPI ( const Config config)
explicit

Constructs a ProxyAPI using the supplied configuration.

Stores config, starts the internal heartbeat timer, and derives a unique control_id from the CPU timestamp so the server can distinguish concurrent controllers. Transport handles are created by reset_handle(), which runs when the inherited MessageLoop starts and again whenever the reconnect logic resets the connection. A controller also caches and posts an initial kAuto Control, but it is only published once the loop, handshake, and transport handles are all ready.

Parameters
configConfiguration for the proxy connection.

◆ ~ProxyAPI()

vlink::ProxyAPI::~ProxyAPI ( )
override

Destroys the ProxyAPI and releases every transport handle.

Quits the inherited MessageLoop (if running), waits for it to stop, then releases DDS/SHM handles. For controller instances, normal MessageLoop shutdown publishes kOffline from on_end().

Member Function Documentation

◆ get_current_boot_time()

uint64_t vlink::ProxyAPI::get_current_boot_time ( ) const

Returns the best estimate of the server's current boot time.

Computed as the last received boot_time plus the elapsed microseconds since that heartbeat, extrapolated via an ElapsedTimer.

Returns
Estimated server uptime in microseconds since boot.

◆ get_current_config()

const Config& vlink::ProxyAPI::get_current_config ( ) const

Returns the configuration supplied at construction.

Returns
Const reference to the internal Config aggregate.

◆ get_current_cpu_usage()

double vlink::ProxyAPI::get_current_cpu_usage ( ) const

Returns the server's most recently reported CPU utilisation.

Returns
CPU usage percentage in the range [0, 100]; 0 when disconnected.

◆ get_current_error()

Error vlink::ProxyAPI::get_current_error ( ) const

Returns the current error state.

Returns
Current Error value; kNoError when no error is active.

◆ get_current_hostname()

std::string vlink::ProxyAPI::get_current_hostname ( ) const

Returns the hostname of the connected ProxyServer.

With handshake enabled, initialised from the successful handshake response and cross-checked against Time heartbeats. Without handshake, populated from the first valid heartbeat. Empty before any server identity is accepted and after disconnection.

Returns
Server hostname, or empty when unavailable.

◆ get_current_machine_id()

std::string vlink::ProxyAPI::get_current_machine_id ( ) const

Returns the machine ID of the connected ProxyServer.

With handshake enabled, initialised from the successful handshake response and cross-checked against Time heartbeats. Without handshake, populated from the first valid heartbeat. Empty before any server identity is accepted and after disconnection.

Returns
Server machine ID, or empty when unavailable.

◆ get_current_memory_usage()

double vlink::ProxyAPI::get_current_memory_usage ( ) const

Returns the server's most recently reported memory utilisation.

Returns
Memory usage percentage in the range [0, 100]; 0 when disconnected.

◆ get_current_mode()

Mode vlink::ProxyAPI::get_current_mode ( ) const

Returns the most recently requested proxy operation mode.

Reflects the mode most recently set through send_control(). Updated on the calling thread before any async DDS publish.

Returns
Current Mode value.

◆ get_current_sys_time()

uint64_t vlink::ProxyAPI::get_current_sys_time ( ) const

Returns the best estimate of the server's current wall-clock time.

Computed as the last received sys_time plus the elapsed microseconds since that heartbeat, extrapolated via an ElapsedTimer. Returns the raw sys_time field when the timer is not yet running.

Returns
Estimated server system time in microseconds since the Unix epoch.

◆ get_format_boot_time()

static std::string vlink::ProxyAPI::get_format_boot_time ( uint64_t  time)
static

Formats a microsecond boot-time duration as a human-readable string.

Converts time (microseconds since boot) into a formatted elapsed string, e.g. "0d 01:23:45.678".

Parameters
timeMicroseconds since boot.
Returns
Formatted elapsed-time string.

◆ get_format_sys_time()

static std::string vlink::ProxyAPI::get_format_sys_time ( uint64_t  time,
bool  enable_utc = false 
)
static

Formats a microsecond wall-clock timestamp as a human-readable string.

Output format: "YYYY/MM/DD HH:MM:SS:mmm" where mmm is milliseconds. Uses localtime_r by default; gmtime_r when enable_utc is true.

Parameters
timeMicroseconds since the Unix epoch.
enable_utctrue for UTC; false for local time (default).
Returns
Formatted timestamp string, or empty on conversion error.

◆ get_latency()

int64_t vlink::ProxyAPI::get_latency ( ) const

Returns the latest backend-reported latency on the data channel.

In direct (SHM) mode, or before the DDS data subscriber is initialised, this returns 0. Otherwise it delegates to the underlying data subscriber's latency tracker. Main backends report one-way/end-to-end data latency in nanoseconds.

Returns
Latency in nanoseconds, or 0 when unavailable.

◆ get_lost()

SampleLostInfo vlink::ProxyAPI::get_lost ( ) const

Returns the sample-loss statistics on the data channel.

In direct (SHM) mode, or before the DDS data subscriber is initialised, this returns a default-constructed (zero) SampleLostInfo. Otherwise it delegates to the underlying data subscriber.

Returns
SampleLostInfo holding total and lost sample counters.

◆ get_max_elapsed_time()

uint32_t vlink::ProxyAPI::get_max_elapsed_time ( ) const
overrideprotectedvirtual

Returns the maximum allowed task execution time in milliseconds.

Tasks exceeding this duration trigger on_task_timeout. Zero disables the check.

Returns
Maximum execution time in milliseconds.

Reimplemented from vlink::MessageLoop.

◆ get_max_task_count()

size_t vlink::ProxyAPI::get_max_task_count ( ) const
overrideprotectedvirtual

Returns the maximum queue depth.

Returns
kMaxTaskSize (10000) by default.

Reimplemented from vlink::MessageLoop.

◆ get_proxy_hostnames()

std::unordered_set<std::string> vlink::ProxyAPI::get_proxy_hostnames ( ) const

Returns every server hostname observed during this session.

Hostnames are accumulated for the lifetime of the connection. They are NOT cleared on disconnect, only when reset_handle() runs.

Returns
Unordered set of observed hostnames.

◆ get_proxy_machine_ids()

std::unordered_set<std::string> vlink::ProxyAPI::get_proxy_machine_ids ( ) const

Returns every server machine ID observed during this session.

Analogous to get_proxy_hostnames(); accumulated for the lifetime of the connection.

Returns
Unordered set of observed machine IDs.

◆ get_proxy_version()

std::string vlink::ProxyAPI::get_proxy_version ( ) const

Returns the VLINK_VERSION string reported by the server.

With handshake enabled, initialised from the successful handshake response and subsequently refreshed from Time metadata after token/control checks. Without handshake, populated from the first valid heartbeat. Empty before any server version is accepted and after a handle reset.

Returns
Server VLink version string, e.g. "2.0.0".

◆ is_connected()

bool vlink::ProxyAPI::is_connected ( ) const

Returns whether a valid connection to ProxyServer exists.

true once the first valid heartbeat arrives; false after five seconds without a heartbeat or when the control channel reports disconnection.

Returns
true if connected, false otherwise.

◆ is_enable_filter()

static bool vlink::ProxyAPI::is_enable_filter ( )
static

Returns true when topic filtering support is compiled in.

Decided at compile time by VLINK_PROXY_ENABLE_FILTER. When false the filter_str and filter_by_process fields in Control are ignored by the server.

Returns
true when filtering is enabled.

◆ is_support_shm()

static bool vlink::ProxyAPI::is_support_shm ( )
static

Returns true when the build includes SHM (Iceoryx) support.

Decided at compile time by VLINK_SUPPORT_SHM. Useful to gate Config::direct.

Returns
true when SHM support is compiled in.

◆ on_begin()

void vlink::ProxyAPI::on_begin ( )
overrideprotectedvirtual

Hook invoked once on the loop thread before the first task runs.

Subclasses override to perform per-thread initialisation.

Reimplemented from vlink::MessageLoop.

◆ on_end()

void vlink::ProxyAPI::on_end ( )
overrideprotectedvirtual

Hook invoked once on the loop thread after the last task runs.

Subclasses override to perform per-thread cleanup.

Reimplemented from vlink::MessageLoop.

◆ register_connect_callback()

void vlink::ProxyAPI::register_connect_callback ( ConnectCallback &&  callback)

Registers a callback for connection-state changes.

If the API is already connected when the registration runs, the callback is invoked immediately with connected=true inside this call. Callbacks are replaced atomically; only one callback is active at a time.

Parameters
callbackCallable with signature void(bool connected).

◆ register_data_callback()

void vlink::ProxyAPI::register_data_callback ( DataCallback &&  callback)

Registers a callback for raw message data relayed by the server.

There is no immediate invocation at registration time. Data arrives when the server is in a mode that forwards messages: kObserveOne, kObserveAll, kRecord, kAuto, or kAutoAndObserveAll.

Parameters
callbackCallable with signature void(const Data& data).

◆ register_error_callback()

void vlink::ProxyAPI::register_error_callback ( ErrorCallback &&  callback)

Registers a callback for error-state transitions.

If a non-zero error is already active at registration time, the callback fires immediately with the current error inside this call.

Parameters
callbackCallable with signature void(Error error).

◆ register_info_callback()

void vlink::ProxyAPI::register_info_callback ( InfoCallback &&  callback)

Registers a callback for per-topic statistics updates.

Invoked once per second with the full Info list from the server. There is no immediate invocation at registration; data arrives on the next server broadcast cycle.

Parameters
callbackCallable with signature void(const std::vector<Info>& info_list).

◆ register_time_callback()

void vlink::ProxyAPI::register_time_callback ( TimeCallback &&  callback)

Registers a callback for heartbeat timestamp delivery.

If timestamps have already been received (timers active) the callback is invoked immediately with the latest extrapolated values inside this call.

Parameters
callbackCallable with signature void(uint64_t sys_time, uint64_t boot_time).

◆ send_control()

bool vlink::ProxyAPI::send_control ( const Control control,
bool  async = true 
)

Publishes a Control message to the ProxyServer.

Valid only for the kController role; returns false immediately for kListener. The control is cached internally and automatically re-sent when the server reconnects after a dropout.

When async is true (default) the DDS Control publish is posted to the MessageLoop thread and the return value reports only whether posting was accepted. When async is false the publish runs synchronously on the calling thread and the return value reports the publish result. In direct mode, direct-map synchronisation is still queued on the MessageLoop, so the return value also depends on whether that enqueue was accepted.

Entries in control.url_meta_list are encoded using their supplied ser and schema verbatim. Proxy no longer back-fills missing routing metadata from discovery caches: entries with an empty ser or unknown schema are ignored by the direct-map sync path and cannot become usable server-side routes.

In direct mode, matching local SHM publishers are created or destroyed to mirror the publisher entries. Direct subscribers are synchronised either from subscriber entries in url_meta_list or, for kObserveAll and kAutoAndObserveAll, from the latest Info list reported by the server. Setter endpoints are observed with getter semantics so field updates keep their last-value behaviour.

Parameters
controlControl message to send.
asynctrue to post asynchronously (default); false to block.
Returns
When async=false, true means the DDS publish succeeded and any direct-map sync was queued. When async=true, true means the publish task was accepted. false on listener role, shutdown, or enqueue/publish failure.
Note
Thread-safe. The control is also stored as the last-known control for automatic resend on reconnect.

◆ send_data()

bool vlink::ProxyAPI::send_data ( const Data data)

Injects raw message data into the proxy data path.

Valid only for the kController role; returns false for kListener. In direct mode the data is published through the local SHM publisher matching data.url and ProxyServer is not on the data relay path. In non-direct mode the payload is wrapped in a ProxyData envelope and forwarded over the DDS data channel. Returns false if no subscribers are listening on the target channel.

The caller must provide both data.ser and a known data.schema. Proxy no longer guesses the decode stack from cached discovery metadata.

Parameters
dataData to inject: URL, serialisation type, schema family, raw bytes, timestamp, and sequence number.
Returns
In non-direct mode, true only if the underlying data publish succeeds. In direct mode, true means a matching local direct publisher and subscriber were found, metadata matched, and the publish attempt was made (backend result is not surfaced). false otherwise.

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