|
VLink
2.0.0
A high-performance communication middleware
|
Portable host-system utility surface used across the VLink runtime. 更多...
#include <string>#include <thread>#include <utility>#include <vector>#include "./functional.h"#include "./macros.h"命名空间 | |
| vlink | |
| vlink::Utils | |
| Portable host-system utility functions. | |
函数 | |
| VLINK_EXPORT std::string | vlink::Utils::get_app_path () noexcept |
| Returns the absolute path of the executable that is currently running. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_app_dir () noexcept |
| Returns the directory portion of the executable's absolute path. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_app_name () noexcept |
| Returns the file-name portion of the executable's absolute path. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_host_name () noexcept |
| Returns the local machine's host name as reported by the operating system. 更多... | |
| VLINK_EXPORT int32_t | vlink::Utils::get_pid () noexcept |
| Returns the process identifier of the calling process. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_pid_str () noexcept |
| Returns the process identifier of the calling process as a decimal string. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_tmp_dir () noexcept |
| Returns a path suitable for short-lived temporary files. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_env (const std::string &key, const std::string &default_value="") noexcept |
| Reads the current value of an environment variable. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::set_env (const std::string &key, const std::string &value, bool force=true) noexcept |
| Sets or updates an environment variable. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::unset_env (const std::string &key) noexcept |
| Removes an environment variable. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::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 > | vlink::Utils::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 > | vlink::Utils::get_all_ipv6_address (bool filter_available=false) noexcept |
| Returns every IPv6 address bound to a local network interface. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_interface_name_by_ipv4 (const std::string &ipv4) noexcept |
| Returns the interface name that owns a given IPv4 address. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::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 > | vlink::Utils::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 | vlink::Utils::check_singleton (const std::string &program_name="") noexcept |
| Provides a singleton mutual-exclusion check for a program name. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::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 | vlink::Utils::yield_cpu () noexcept |
| Emits the most efficient CPU pause/yield hint for the host ISA. 更多... | |
| VLINK_EXPORT void | vlink::Utils::set_console_utf8_output () noexcept |
| Sets the Windows console output code page to UTF-8. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::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 | vlink::Utils::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 | vlink::Utils::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 | vlink::Utils::get_native_thread_id () noexcept |
| Returns the native OS thread identifier of the calling thread. 更多... | |
| VLINK_EXPORT void | vlink::Utils::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 | vlink::Utils::register_crash_signal (MoveFunction< void(int)> &&callback) noexcept |
Installs a callback for crash signals such as SIGSEGV, SIGABRT, SIGFPE, SIGBUS. 更多... | |
| VLINK_EXPORT void | vlink::Utils::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 | vlink::Utils::stop_detect_keyboard () noexcept |
Stops the keyboard poller started by start_detect_keyboard(). 更多... | |
| VLINK_EXPORT std::pair< int, int > | vlink::Utils::get_terminal_size () noexcept |
| Returns the current terminal dimensions in columns and rows. 更多... | |
| VLINK_EXPORT double | vlink::Utils::get_cpu_usage () noexcept |
| Returns the system-wide CPU usage as a percentage averaged over all logical CPUs. 更多... | |
| VLINK_EXPORT double | vlink::Utils::get_memory_usage () noexcept |
| Returns the system-wide memory usage as a percentage of total physical RAM. 更多... | |
| VLINK_EXPORT bool | vlink::Utils::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 | vlink::Utils::get_timezone_diff () noexcept |
| Returns the local timezone offset from UTC in minutes. 更多... | |
| VLINK_EXPORT std::string | vlink::Utils::get_machine_id () noexcept |
| Returns a stable identifier for the host machine. 更多... | |
| VLINK_EXPORT void | vlink::Utils::try_release_sys_memory () noexcept |
| Hints to the OS that any unreferenced cached memory pages can be released. 更多... | |
Portable host-system utility surface used across the VLink runtime.
vlink::Utils gathers free functions that paper over differences between Linux, macOS, Windows, QNX and Android. All public entry points are noexcept and report failure via empty strings, false return values or sentinel values such as pid == -1.
Helper categories provided by the namespace:
| Category | Representative entry points |
|---|---|
| Process introspection | get_app_path, get_app_dir, get_app_name, get_pid |
| Host identity | get_host_name, get_machine_id, get_timezone_diff |
| Filesystem helpers | get_tmp_dir, wait_for_device |
| Environment management | get_env, set_env, unset_env |
| Network discovery | get_all_ipv4_address, get_dds_default_address |
| Thread control | set_thread_name, set_thread_priority, set_thread_stick |
| Signal handling | register_terminate_signal, register_crash_signal |
| Input/terminal | start_detect_keyboard, get_terminal_size |
| System metrics | get_cpu_usage, get_memory_usage, is_process_running |
| Memory hints | try_release_sys_memory |
| Low-level primitives | yield_cpu |
yield_cpu() is inlined to emit the optimal idle hint per ISA: PAUSE on x86, YIELD on ARM, an explicit fence on RISC-V, otherwise std::this_thread::yield().