|
VLink
2.0.0
A high-performance communication middleware
|
Portable host-system utility functions. 更多...
函数 | |
| VLINK_EXPORT std::string | get_app_path () noexcept |
| Returns the absolute path of the executable that is currently running. 更多... | |
| VLINK_EXPORT std::string | get_app_dir () noexcept |
| Returns the directory portion of the executable's absolute path. 更多... | |
| VLINK_EXPORT std::string | get_app_name () noexcept |
| Returns the file-name portion of the executable's absolute path. 更多... | |
| VLINK_EXPORT std::string | get_host_name () noexcept |
| Returns the local machine's host name as reported by the operating system. 更多... | |
| VLINK_EXPORT int32_t | get_pid () noexcept |
| Returns the process identifier of the calling process. 更多... | |
| VLINK_EXPORT std::string | get_pid_str () noexcept |
| Returns the process identifier of the calling process as a decimal string. 更多... | |
| VLINK_EXPORT std::string | get_tmp_dir () noexcept |
| Returns a path suitable for short-lived temporary files. 更多... | |
| VLINK_EXPORT std::string | get_env (const std::string &key, const std::string &default_value="") noexcept |
| Reads the current value of an environment variable. 更多... | |
| VLINK_EXPORT bool | set_env (const std::string &key, const std::string &value, bool force=true) noexcept |
| Sets or updates an environment variable. 更多... | |
| VLINK_EXPORT bool | unset_env (const std::string &key) noexcept |
| Removes an environment variable. 更多... | |
| VLINK_EXPORT bool | is_ignored_iface_name (const char *name) noexcept |
| Returns whether an interface name is treated as virtual/tunnel-only by address discovery. 更多... | |
| VLINK_EXPORT std::vector< std::string > | get_all_ipv4_address (bool filter_available=false) noexcept |
| Returns every IPv4 address bound to a local network interface. 更多... | |
| VLINK_EXPORT std::vector< std::string > | get_all_ipv6_address (bool filter_available=false) noexcept |
| Returns every IPv6 address bound to a local network interface. 更多... | |
| VLINK_EXPORT std::string | get_interface_name_by_ipv4 (const std::string &ipv4) noexcept |
| Returns the interface name that owns a given IPv4 address. 更多... | |
| VLINK_EXPORT std::string | get_interface_name_by_ipv6 (const std::string &ipv6) noexcept |
| Returns the interface name that owns a given IPv6 address. 更多... | |
| VLINK_EXPORT std::vector< std::string > | get_dds_default_address (bool filter_available=false, int max_count=5) noexcept |
| Selects IPv4 addresses suitable as DDS participant unicast locators. 更多... | |
| VLINK_EXPORT bool | check_singleton (const std::string &program_name="") noexcept |
| Provides a singleton mutual-exclusion check for a program name. 更多... | |
| VLINK_EXPORT bool | wait_for_device (const std::string &path, int timeout_ms, int poll_ms=50) noexcept |
| Polls a filesystem path until it exists or a timeout expires. 更多... | |
| VLINK_EXPORT void | yield_cpu () noexcept |
| Emits the most efficient CPU pause/yield hint for the host ISA. 更多... | |
| VLINK_EXPORT void | set_console_utf8_output () noexcept |
| Sets the Windows console output code page to UTF-8. 更多... | |
| VLINK_EXPORT bool | set_thread_name (const std::string &name, std::thread *thread=nullptr) noexcept |
| Sets the OS-visible name of a thread so debug tools display it. 更多... | |
| VLINK_EXPORT bool | set_thread_priority (int priority_level, int policy=-1, std::thread *thread=nullptr) noexcept |
| Updates the scheduling policy and priority of a thread. 更多... | |
| VLINK_EXPORT bool | set_thread_stick (uint32_t core_mask, std::thread *thread=nullptr) noexcept |
| Pins a thread to a set of CPU cores expressed as a bitmask. 更多... | |
| VLINK_EXPORT uint64_t | get_native_thread_id () noexcept |
| Returns the native OS thread identifier of the calling thread. 更多... | |
| VLINK_EXPORT void | register_terminate_signal (MoveFunction< void(int)> &&callback, bool is_async=false, bool pass_through=false) noexcept |
| Installs a callback for graceful termination signals. 更多... | |
| VLINK_EXPORT void | register_crash_signal (MoveFunction< void(int)> &&callback) noexcept |
Installs a callback for crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGBUS. 更多... | |
| VLINK_EXPORT void | start_detect_keyboard (MoveFunction< void(const std::string &key)> &&callback=nullptr, int poll_ms=20) noexcept |
| Starts a background poller that detects keyboard input on stdin. 更多... | |
| VLINK_EXPORT void | stop_detect_keyboard () noexcept |
Stops the keyboard poller started by start_detect_keyboard(). 更多... | |
| VLINK_EXPORT std::pair< int, int > | get_terminal_size () noexcept |
| Returns the current terminal dimensions in columns and rows. 更多... | |
| VLINK_EXPORT double | get_cpu_usage () noexcept |
| Returns the system-wide CPU usage as a percentage averaged over all logical CPUs. 更多... | |
| VLINK_EXPORT double | get_memory_usage () noexcept |
| Returns the system-wide memory usage as a percentage of total physical RAM. 更多... | |
| VLINK_EXPORT bool | is_process_running (const std::string &process_name) noexcept |
| Reports whether at least one process with the given executable name is alive. 更多... | |
| VLINK_EXPORT int32_t | get_timezone_diff () noexcept |
| Returns the local timezone offset from UTC in minutes. 更多... | |
| VLINK_EXPORT std::string | get_machine_id () noexcept |
| Returns a stable identifier for the host machine. 更多... | |
| VLINK_EXPORT void | try_release_sys_memory () noexcept |
| Hints to the OS that any unreferenced cached memory pages can be released. 更多... | |
Portable host-system utility functions.
|
noexcept |
Provides a singleton mutual-exclusion check for a program name.
Uses a Win32 mutex on Windows and a POSIX lock file under VLINK_LOCK_DIR (or the platform default) elsewhere. Returns false when another instance already holds the lock.
| program_name | Program tag used to build the lock identity. Empty defaults to the executable name. |
true when this process holds the singleton lock.
|
noexcept |
Returns every IPv4 address bound to a local network interface.
| filter_available | When true, only includes interfaces in the UP state. Default: false. |
|
noexcept |
Returns every IPv6 address bound to a local network interface.
| filter_available | When true, only includes interfaces in the UP state. Default: false. |
|
noexcept |
Returns the directory portion of the executable's absolute path.
|
noexcept |
Returns the file-name portion of the executable's absolute path.
|
noexcept |
Returns the absolute path of the executable that is currently running.
|
noexcept |
Returns the system-wide CPU usage as a percentage averaged over all logical CPUs.
Implemented as (1 - idle_delta / total_delta) * 100 from /proc/stat on Linux/Android or GetSystemTimes on Windows. Because the previous sample is zero-initialised, the first call after process start reports the average usage since boot rather than the usage over an interval.
[0.0, 100.0], or -1.0 on error / unsupported platform.
|
noexcept |
Selects IPv4 addresses suitable as DDS participant unicast locators.
When 127.0.0.1 is present it is placed first in the result; the remaining non-loopback unicast addresses are then appended until max_count is reached. Loopback is therefore included (as the leading entry) rather than filtered out.
| filter_available | When true, only includes UP interfaces. Default: false. |
| max_count | Upper bound on the number of returned addresses. Default: 5. |
|
noexcept |
Reads the current value of an environment variable.
| key | Variable name. |
| default_value | Value returned when key is not set. Default: empty string. |
default_value when unset.
|
noexcept |
Returns the local machine's host name as reported by the operating system.
|
noexcept |
Returns the interface name that owns a given IPv4 address.
| ipv4 | Address to look up. |
|
noexcept |
Returns the interface name that owns a given IPv6 address.
| ipv6 | Address to look up. |
|
noexcept |
Returns a stable identifier for the host machine.
Reads /etc/machine-id on Linux and uses platform-specific equivalents elsewhere.
|
noexcept |
Returns the system-wide memory usage as a percentage of total physical RAM.
[0.0, 100.0], or -1.0 on error / unsupported platform.
|
noexcept |
Returns the native OS thread identifier of the calling thread.
Maps to:
syscall(SYS_gettid) — kernel TID matching top / perf.pthread_threadid_np() — 64-bit Mach thread id.GetCurrentThreadId() — Win32 thread id.
|
noexcept |
Returns the process identifier of the calling process.
-1 on failure.
|
noexcept |
Returns the process identifier of the calling process as a decimal string.
|
noexcept |
Returns the current terminal dimensions in columns and rows.
{columns, rows}; {-1, -1} when stdout is not a TTY.
|
noexcept |
Returns the local timezone offset from UTC in minutes.
UTC+8 returns 480; UTC-5 returns -300.
|
noexcept |
Returns a path suitable for short-lived temporary files.
Honours the VLINK_TMP_DIR environment override. Otherwise falls back to std::filesystem::temp_directory_path(), or /var/log on QNX.
|
noexcept |
Returns whether an interface name is treated as virtual/tunnel-only by address discovery.
Used by get_all_ipv4_address(true) and get_all_ipv6_address(true) to skip container, VPN, bridge and tunnel adapters when choosing transport discovery addresses.
| name | Interface name; nullptr is treated as ignored. |
true when the name should be filtered out.
|
noexcept |
Reports whether at least one process with the given executable name is alive.
| process_name | Executable name without a path component. |
true when a matching process exists.
|
noexcept |
Installs a callback for crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGBUS.
Useful for emitting crash diagnostics. The callback should be async-signal-safe and short.
| callback | Callback receiving the signal number. |
|
noexcept |
Installs a callback for graceful termination signals.
Hooks SIGINT, SIGTERM and SIGHUP on POSIX, or SIGINT / SIGTERM on Windows.
| callback | Callback receiving the signal number. |
| is_async | When true, runs the callback on a dedicated thread instead of the signal context. Default: false. |
| pass_through | When true, re-raises the signal after the callback returns so the default OS behaviour also fires. Default: false. |
|
noexcept |
Sets the Windows console output code page to UTF-8.
Calls SetConsoleOutputCP(CP_UTF8); a no-op on non-Windows targets.
|
noexcept |
Sets or updates an environment variable.
| key | Variable name. |
| value | Variable value. |
| force | When true (default), overwrites an existing variable. |
true on success.
|
noexcept |
Sets the OS-visible name of a thread so debug tools display it.
| name | Thread name; Linux truncates beyond 15 characters. |
| thread | Thread to rename, or nullptr for the calling thread. Default: nullptr. |
true on success.
|
noexcept |
Updates the scheduling policy and priority of a thread.
On Linux wraps pthread_setschedparam. Real-time policies require CAP_SYS_NICE or an adequate RLIMIT_RTPRIO. POSIX policy constants (SCHED_FIFO, SCHED_RR, SCHED_OTHER) come from <sched.h>, which callers must include. On Windows the value is mapped to a thread priority class or silently ignored.
| priority_level | Policy-dependent priority value. |
| policy | Scheduling policy; -1 leaves the existing policy untouched. |
| thread | Thread to configure, or nullptr for the calling thread. Default: nullptr. |
true on success.
|
noexcept |
Pins a thread to a set of CPU cores expressed as a bitmask.
Bit i of core_mask corresponds to core i, so 0b0101 pins to cores 0 and 2. Wraps pthread_setaffinity_np on Linux.
| core_mask | Bitmask of CPU cores. |
| thread | Thread to pin, or nullptr for the calling thread. Default: nullptr. |
true on success.
|
noexcept |
Starts a background poller that detects keyboard input on stdin.
Calls callback with a key name string (such as "enter" or "q") whenever a key is detected. Stop with stop_detect_keyboard().
| callback | Callback receiving the key name. Default: nullptr (ignore events). |
| poll_ms | Polling interval in milliseconds. Default: 20. |
|
noexcept |
Stops the keyboard poller started by start_detect_keyboard().
|
noexcept |
Hints to the OS that any unreferenced cached memory pages can be released.
On Linux invokes malloc_trim(0); on other platforms it is a no-op.
|
noexcept |
Removes an environment variable.
| key | Variable name. |
true on success.
|
noexcept |
Polls a filesystem path until it exists or a timeout expires.
Useful for waiting for device nodes (e.g. /dev/video0) at startup.
| path | Filesystem path to poll. |
| timeout_ms | Maximum total wait in milliseconds. |
| poll_ms | Polling interval in milliseconds. Default: 50. |
true when the path appears within the timeout.
|
inlinenoexcept |
Emits the most efficient CPU pause/yield hint for the host ISA.
Details
Maps to PAUSE on x86, YIELD on ARMv7/AArch64, an explicit fence on RISC-V, and std::this_thread::yield() as a portable fallback. Always inlined.