|
VLink
2.0.0
A high-performance communication middleware
|
Client-side proxy monitoring and control surface backed by a MessageLoop.
More...
#include <proxy_api.h>
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... | |
Public Types inherited from vlink::MessageLoop | |
| enum | Type : uint8_t { kNormalType = 0 , kLockfreeType = 1 , kPriorityType = 2 } |
| Internal queue implementation type. More... | |
| enum | Strategy : uint8_t { kOptimizationStrategy = 0 , kPopStrategy = 1 , kBlockStrategy = 2 } |
| Back-pressure strategy applied when the bounded queue is at capacity. More... | |
| enum | Priority : uint16_t { kNoPriority = 0 , kLowestPriority = 1 , kTimerPriority = 50 , kNormalPriority = 100 , kHighestPriority = std::numeric_limits<uint16_t>::max() } |
Built-in priority levels for kPriorityType loops; higher values dispatch first. More... | |
| using | Callback = MoveFunction< void()> |
| Callback type for tasks and event handlers. 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 Config & | get_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... | |
Public Member Functions inherited from vlink::MessageLoop | |
| MessageLoop () | |
Constructs a loop with the default kNormalType queue. More... | |
| MessageLoop (Type type) | |
| Constructs a loop with the given queue type. More... | |
| virtual | ~MessageLoop () |
| Destructor; requests quit and joins the dispatcher thread if needed. More... | |
| void | set_name (const std::string &name) |
| Sets a human-readable name visible to profiling tools. More... | |
| const std::string & | get_name () const |
Returns the loop name set via set_name. More... | |
| Type | get_type () const |
| Returns the queue type this loop was constructed with. More... | |
| Strategy | get_strategy () const |
| Returns the active back-pressure strategy. More... | |
| void | set_strategy (Strategy strategy) |
| Replaces the back-pressure strategy. More... | |
| void | register_begin_handler (Callback &&callback) |
| Registers a callback fired once at loop thread startup. More... | |
| void | register_end_handler (Callback &&callback) |
| Registers a callback fired once when the loop thread exits. More... | |
| void | register_idle_handler (Callback &&callback) |
| Registers a callback fired every time the queue becomes empty. More... | |
| bool | run () |
Runs the loop on the calling thread until quit is requested. More... | |
| bool | async_run () |
| Starts the loop on a new background thread. More... | |
| bool | spin () |
Alias of run blocking the calling thread. More... | |
| bool | spin_once (bool block=true) |
| Processes one batch of pending tasks and timers on the calling thread. More... | |
| bool | quit (bool force=false) |
| Requests the loop to exit. More... | |
| bool | wait_for_quit (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has fully exited. More... | |
| bool | post_task (Callback &&callback) |
| Posts a task for execution on the loop thread. More... | |
| TaskHandle | post_task_handle (Callback &&callback, const PostTaskOptions &options={}) |
Tracked variant of post_task returning a TaskHandle. More... | |
| bool | post_task_with_priority (Callback &&callback, uint16_t priority) |
Posts a task with an explicit priority on a kPriorityType loop. More... | |
| TaskHandle | post_task_with_priority_handle (Callback &&callback, uint16_t priority, const PostTaskOptions &options={}) |
Tracked variant of post_task_with_priority returning a TaskHandle. More... | |
| template<typename CallbackT , typename = std::enable_if_t<!std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::Status | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a void-returning callable and returns a chainable Schedule::Status. More... | |
| template<typename CallbackT , typename = std::enable_if_t<std::is_convertible_v<CallbackT, Schedule::RetCallback>>> | |
| Schedule::RetStatus | exec_task (const Schedule::Config &config, CallbackT &&callback) |
Schedules a bool-returning callable and returns a chainable Schedule::RetStatus. More... | |
| bool | wakeup () |
| Wakes the loop thread if it is suspended in its idle wait. More... | |
| void | reset_lockfree_capacity () |
| Recreates the lock-free queue, clearing all queued tasks and counters. More... | |
| bool | is_running () const |
| Reports whether the loop is currently running. More... | |
| bool | is_ready_to_quit () const |
Reports whether quit has been requested and the loop is winding down. More... | |
| bool | is_busy () const |
| Reports whether the loop is currently executing a task. More... | |
| size_t | get_task_count () const |
| Returns the current pending task count. More... | |
| virtual bool | wait_for_idle (int ms=Timer::kInfinite, bool check=true) |
| Waits until the loop has drained its queue and is not executing a task. More... | |
| virtual size_t | get_max_timer_count () const |
| Returns the maximum number of timers that can be attached. More... | |
| virtual bool | is_in_same_thread () const |
| Reports whether the calling thread is owned by this loop. More... | |
| std::shared_ptr< AliveState > | get_alive_state () const |
| Returns the shared lifetime flag used by cross-thread bridges. More... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task (FunctionT &&function, ArgsT &&... args) |
Dispatches a callable to the loop thread and returns a std::future for the result. More... | |
| template<class FunctionT , class... ArgsT, typename ResultT = std::invoke_result_t<FunctionT, ArgsT...>> | |
| std::future< ResultT > | invoke_task_with_priority (FunctionT &&function, uint16_t priority, ArgsT &&... args) |
Priority variant of invoke_task; requires a kPriorityType loop. 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... | |
Protected Member Functions inherited from vlink::MessageLoop | |
| virtual void | on_idle () |
| Hook invoked on the loop thread each time the queue becomes empty. More... | |
| virtual void | on_task_changed (Callback &&callback, uint32_t start_time) |
| Dispatches a ready task on the loop thread. More... | |
| virtual void | on_task_timeout (Callback &&callback, uint32_t elapsed_time) |
Hook invoked when a task exceeds get_max_elapsed_time(). More... | |
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.
| 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.
| 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.
| using vlink::ProxyAPI::ErrorCallback = MoveFunction<void(Error error)> |
Callback fired on each error-state transition.
Only invoked when Error changes – for instance from kNoError to kVersionCompError, or back to kNoError.
| using vlink::ProxyAPI::InfoCallback = MoveFunction<void(const std::vector<Info>& info_list)> |
Callback delivering the per-topic statistics list once per second.
| info_list | Filtered discovery records relevant to the current mode, including their status fields. |
| using vlink::ProxyAPI::TimeCallback = MoveFunction<void(uint64_t sys_time, uint64_t boot_time)> |
| 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 |
| kReliableCompError |
|
| kTcpCompError |
|
| kDirectCompError |
|
| kMultiProxyError | Multiple proxy servers, or Time identity differs from the handshake. |
| kVersionCompError |
|
| kTokenError | Handshake refused/empty token or identity-matching token mismatch. |
| kUnknownError | Unknown or unclassified error. |
| 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.
| 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 | |
| enum vlink::ProxyAPI::Status : uint8_t |
Per-topic activity status reported inside Info records.
|
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.
| config | Configuration for the proxy connection. |
|
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().
| 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.
| const Config& vlink::ProxyAPI::get_current_config | ( | ) | const |
Returns the configuration supplied at construction.
Config aggregate. | double vlink::ProxyAPI::get_current_cpu_usage | ( | ) | const |
Returns the server's most recently reported CPU utilisation.
0 when disconnected. | Error vlink::ProxyAPI::get_current_error | ( | ) | const |
Returns the current error state.
Error value; kNoError when no error is active. | 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.
| 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.
| double vlink::ProxyAPI::get_current_memory_usage | ( | ) | const |
Returns the server's most recently reported memory utilisation.
0 when disconnected. | 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.
Mode value. | 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.
|
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".
| time | Microseconds since boot. |
|
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.
| time | Microseconds since the Unix epoch. |
| enable_utc | true for UTC; false for local time (default). |
| 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.
0 when unavailable. | 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.
SampleLostInfo holding total and lost sample counters.
|
overrideprotectedvirtual |
Returns the maximum allowed task execution time in milliseconds.
Tasks exceeding this duration trigger on_task_timeout. Zero disables the check.
Reimplemented from vlink::MessageLoop.
|
overrideprotectedvirtual |
Returns the maximum queue depth.
kMaxTaskSize (10000) by default. Reimplemented from vlink::MessageLoop.
| 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.
| 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.
| 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.
"2.0.0". | 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.
true if connected, false otherwise.
|
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.
true when filtering is enabled.
|
static |
Returns true when the build includes SHM (Iceoryx) support.
Decided at compile time by VLINK_SUPPORT_SHM. Useful to gate Config::direct.
true when SHM support is compiled in.
|
overrideprotectedvirtual |
Hook invoked once on the loop thread before the first task runs.
Subclasses override to perform per-thread initialisation.
Reimplemented from vlink::MessageLoop.
|
overrideprotectedvirtual |
Hook invoked once on the loop thread after the last task runs.
Subclasses override to perform per-thread cleanup.
Reimplemented from vlink::MessageLoop.
| 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.
| callback | Callable with signature void(bool connected). |
| 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.
| callback | Callable with signature void(const Data& data). |
| 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.
| callback | Callable with signature void(Error error). |
| 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.
| callback | Callable with signature void(const std::vector<Info>& info_list). |
| 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.
| callback | Callable with signature void(uint64_t sys_time, uint64_t boot_time). |
| 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.
| control | Control message to send. |
| async | true to post asynchronously (default); false to block. |
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.| 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.
| data | Data to inject: URL, serialisation type, schema family, raw bytes, timestamp, and sequence number. |
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.