|
VLink 2.0.0
A high-performance communication middleware
|
Type-safe client for the VLink method (RPC) communication model. 更多...
#include <client.h>
Public 类型 | |
| using | UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>> |
| Unique-pointer alias. | |
| using | SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>> |
| Shared-pointer alias. | |
| using | ConnectCallback = NodeImpl::ConnectCallback |
| Callback type fired when server connection state changes. | |
| using | RespCallback = std::function<void(const RespT&)> |
| Callback type for async response delivery. | |
| Public 类型 继承自 vlink::Node< ClientImpl, SecurityType::kWithoutSecurity > | |
| using | StatusCallback |
| Callback type for node status-change notifications. | |
Public 成员函数 | |
| template<typename ConfT, typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>> | |
| Client (const ConfT &conf, InitType type=InitType::kWithInit) | |
| Constructs a client from a typed transport configuration object. | |
| Client (const std::string &url_str, InitType type=InitType::kWithInit) | |
| Constructs a client from a URL string. | |
| ~Client () override | |
| void | detect_connected (ConnectCallback &&callback) |
| Registers a callback invoked when the server connection state changes. | |
| bool | wait_for_connected (std::chrono::milliseconds timeout=Timeout::kDefaultInterval) |
| Blocks until a server is available or the timeout expires. | |
| bool | is_connected () const |
Returns true if a server is currently available. | |
| bool | invoke (const ReqT &req, RespT &resp, std::chrono::milliseconds timeout=Timeout::kDefaultInterval) |
| Sends a request and blocks until the response is received. | |
| std::optional< RespT > | invoke (const ReqT &req, std::chrono::milliseconds timeout=Timeout::kDefaultInterval) |
Sends a request and returns the response as std::optional. | |
| bool | invoke (const ReqT &req, RespCallback &&callback) |
Sends a request and invokes callback asynchronously on the response. | |
| std::future< RespT > | async_invoke (const ReqT &req) |
Sends a request and returns a std::future for the response. | |
| bool | send (const ReqT &req) |
| Sends a fire-and-forget request with no response. | |
| Public 成员函数 继承自 vlink::Node< ClientImpl, SecurityType::kWithoutSecurity > | |
| virtual bool | init () |
| Initialises the node and its transport back-end. | |
| virtual bool | deinit () |
| Shuts down the node and releases all transport resources. | |
| virtual void | interrupt () |
| Unblocks any active blocking wait on this node. | |
| bool | has_inited () const |
Returns true if init() has been successfully called. | |
| bool | is_support_loan () const |
Returns true if the transport supports zero-copy loaned buffers. | |
| Bytes | loan (int64_t size) |
| Allocates a loaned buffer from the transport memory pool. | |
| bool | return_loan (const Bytes &bytes) |
| Returns a previously loaned buffer back to the transport pool. | |
| virtual void | set_manual_unloan (bool manual_unloan) |
| Enables or disables manual-unloan mode for zero-copy receives. | |
| virtual bool | is_manual_unloan () const |
Returns true if manual-unloan mode is active. | |
| bool | suspend () |
| Suspends message delivery on this node. | |
| bool | resume () |
Resumes message delivery after a suspend(). | |
| bool | is_suspend () const |
Returns true if the node is currently suspended. | |
| bool | attach (class MessageLoop *message_loop) |
Attaches the node to a MessageLoop for callback dispatching. | |
| bool | detach () |
Detaches the node from its current MessageLoop. | |
| class MessageLoop * | get_message_loop () const |
Returns the MessageLoop this node is attached to. | |
| const AbstractNode * | get_abstract_node () const |
| Returns the abstract node handle for graph introspection. | |
| Status::BasePtr | get_status (Status::Type type) const |
| Returns the current status object for the specified status type. | |
| void | register_status_handler (StatusCallback &&callback) |
| Registers a handler called when the node's status changes. | |
| void | set_property (const std::string &prop, const std::string &value) |
| Sets a transport-specific key-value property on the node. | |
| std::string | get_property (const std::string &prop) const |
| Retrieves a transport-specific property value. | |
| TransportType | get_transport_type () const |
Returns the TransportType of the transport this node is bound to. | |
| const std::string & | get_url () const |
| Returns the URL string used to construct this node. | |
| void | set_security_key (const std::string &key) |
| Sets the symmetric encryption key for message security. | |
| void | set_record_path (const std::string &path) |
| Sets the filesystem path for message bag recording. | |
| void | set_security_callbacks (Security::Callback &&encrypt_callback, Security::Callback &&decrypt_callback) |
| Installs custom encrypt and decrypt callbacks. | |
| void | set_ser_type (const std::string &ser_type, SchemaType schema_type=SchemaType::kUnknown) |
| Overrides the runtime wire metadata for this node. | |
| const std::string & | get_ser_type () const |
| Returns the current serialisation type string. | |
| SchemaType | get_schema_type () const |
| Returns the current coarse schema family. | |
| void | set_discovery_enabled (bool enable) |
| Enables or disables peer-discovery on this node. | |
| bool | get_discovery_enabled () const |
Returns true if peer-discovery is currently enabled. | |
| void | bind_proto_arena (void *proto_arena) |
| Binds a Protobuf Arena for arena-allocated message objects. | |
| double | get_cpu_usage () const |
| Returns the cumulative CPU usage ratio for this node. | |
| bool | get_safety_quit () const |
Returns true if safe-quit mode is currently active. | |
| void | set_safety_quit (bool safety_quit) |
| Enables or disables safe-quit mode. | |
| void | set_ssl_options (const SslOptions &options) |
| Configures transport-layer SSL/TLS encryption for this node. | |
静态 Public 成员函数 | |
| static UniquePtr | create_unique (const std::string &url_str, InitType type=InitType::kWithInit) |
Creates a Client on the heap wrapped in a unique_ptr. | |
| static SharedPtr | create_shared (const std::string &url_str, InitType type=InitType::kWithInit) |
Creates a Client on the heap wrapped in a shared_ptr. | |
静态 Public 属性 | |
| static constexpr ImplType | kImplType = kClient |
Node role identifier (kClient). | |
| static constexpr bool | kHasResp = !std::is_same_v<RespT, Traits::EmptyType> |
true when RespT is not EmptyType (client expects a response). | |
| static constexpr Serializer::Type | kReqType = Serializer::get_type_of<ReqT>() |
Serializer type for ReqT. | |
| static constexpr Serializer::Type | kRespType = Serializer::get_type_of<RespT>() |
Serializer type for RespT. | |
额外继承的成员函数 | |
| Protected 成员函数 继承自 vlink::Node< ClientImpl, SecurityType::kWithoutSecurity > | |
| Node () | |
| virtual | ~Node () |
| void | enable_security () |
| void | invoke_callback (const CallbackT &callback, ArgsT &&... args) |
| TypeT | get_default_value () |
| Protected 属性 继承自 vlink::Node< ClientImpl, SecurityType::kWithoutSecurity > | |
| std::atomic_bool | has_inited_ |
| std::unique_ptr< ClientImpl > | impl_ |
| std::optional< Security > | security_ |
| std::optional< std::mutex > | quit_mtx_ |
| void * | proto_arena_ |
| bool | is_support_loan_ |
| bool | is_manual_unloan_ |
Type-safe client for the VLink method (RPC) communication model.
| ReqT | Request type. |
| RespT | Response type (defaults to Traits::EmptyType – fire-and-forget). |
| SecT | Security mode. |
| using vlink::Client< ReqT, RespT, SecT >::ConnectCallback = NodeImpl::ConnectCallback |
Callback type fired when server connection state changes.
| using vlink::Client< ReqT, RespT, SecT >::RespCallback = std::function<void(const RespT&)> |
Callback type for async response delivery.
| using vlink::Client< ReqT, RespT, SecT >::SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>> |
Shared-pointer alias.
| using vlink::Client< ReqT, RespT, SecT >::UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>> |
Unique-pointer alias.
|
inlineexplicit |
Constructs a client from a typed transport configuration object.
Accepts any Conf-derived configuration. A compile-time static_assert verifies the configuration supports the client role.
| ConfT | Conf-derived configuration type. |
| conf | Populated configuration object. |
| type | kWithInit to call init() immediately (default). |
|
inlineexplicit |
Constructs a client from a URL string.
| url_str | Service URL (e.g. "someip://30490/0x1/my_method"). |
| type | kWithInit to call init() immediately (default). |
|
inlineoverride |
|
inlinenodiscard |
Sends a request and returns a std::future for the response.
Only valid when kHasResp is true (enforced by static_assert). The future is set when the response arrives. If the call fails (serialisation error, transport error, or deserialisation failure) the future's exception is set with an Exception::RuntimeError.
| req | Request value to send. |
std::future<RespT> resolved when the response arrives.
|
inlinestaticnodiscard |
|
inlinestaticnodiscard |
|
inline |
Registers a callback invoked when the server connection state changes.
Fires immediately (synchronously) if the server is already connected. Otherwise fires asynchronously when the server first becomes available.
| callback | void(bool) – true when connected to a server. |
|
inline |
Sends a request and invokes callback asynchronously on the response.
Only valid when kHasResp is true. The call returns immediately; the callback is invoked on the transport thread (or on the attached MessageLoop thread) when the response arrives.
| req | Request value to send. |
| callback | void(const RespT&) invoked with the response. |
true if the request was accepted by the transport; false on error.
|
inlinenodiscard |
Sends a request and blocks until the response is received.
Only valid when kHasResp is true (enforced by static_assert). Serialises req, sends it to the server, blocks for up to timeout, and deserialises the response into resp. A timeout of 0 is treated as infinite.
| req | Request value to send. |
| resp | Output parameter filled with the deserialised response. |
| timeout | Maximum wait for the response. |
true if the response was received in time; false otherwise.
|
inlinenodiscard |
Sends a request and returns the response as std::optional.
Convenience overload that returns std::nullopt on timeout or error instead of requiring an output parameter. Only valid when kHasResp is true. A timeout of 0 is treated as infinite.
| req | Request value to send. |
| timeout | Maximum wait for the response. |
std::optional<RespT> – nullopt on timeout/error.
|
inlinenodiscard |
Returns true if a server is currently available.
Non-blocking poll; reflects the transport's last known server state.
true when connected to a server.
|
inline |
Sends a fire-and-forget request with no response.
Only valid when RespT == EmptyType (enforced by static_assert). The call returns immediately after the transport has accepted the request; no response is expected or awaited.
| req | Request value to send. |
true if the transport accepted the request; false on error.
|
inline |
Blocks until a server is available or the timeout expires.
A timeout of 0 is treated as infinite (a warning is logged). A negative timeout also waits indefinitely. Can be interrupted by interrupt(), which causes this method to return false.
| timeout | Maximum wait duration. Default: Timeout::kDefaultInterval. |
true if a server appeared; false on timeout or interrupt.
|
staticconstexpr |
true when RespT is not EmptyType (client expects a response).
|
staticconstexpr |
Node role identifier (kClient).
|
staticconstexpr |
Serializer type for ReqT.
|
staticconstexpr |
Serializer type for RespT.