VLink 2.0.0
A high-performance communication middleware
Loading...
Searching...
No Matches
client.h File Reference

Type-safe method-model client (caller side) for VLink RPC. More...

#include <chrono>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <unordered_map>
#include "./impl/client_impl.h"
#include "./node.h"
#include "./internal/client-inl.h"
Include dependency graph for client.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

 Type-safe client for the VLink method (RPC) communication model. More...
 Convenience alias for Client with message security enabled. More...

Namespaces

Detailed Description

Type-safe method-model client (caller side) for VLink RPC.

Client<ReqT, RespT, SecT> is the caller side of the VLink method model. It serialises a request, delivers it to a matching Server, and returns the deserialised response.

Method Model Overview
Client<Req,Resp> Server<Req,Resp>
| Transport Back-end |
|-- invoke(req) -------> | |
| serialize(req) |-- request delivery -----------> |
| [wait] | |--> callback(req,resp)
| |<-- response delivery ---------- |
| deserialize(resp) | |
|<-- returns resp -------| |
Five Invocation Modes
Method Signature Block Notes
invoke (ref) invoke(req, resp&, timeout) Yes Returns true/false.
invoke (optional) invoke(req, timeout) -> optional<Resp> Yes Returns nullopt on timeout.
invoke (callback) invoke(req, RespCallback) No Callback on response.
async_invoke async_invoke(req) -> future<Resp> No std::future based.
send send(req) No Fire-and-forget (no resp).
Synchronous Invocation
Client<Req, Resp> client("dds://my_service");
client.wait_for_connected();
Resp resp;
if (client.invoke(Req{...}, resp)) {
std::cout << "result: " << resp.value << std::endl;
}
// or using optional:
if (auto r = client.invoke(Req{...})) {
std::cout << r->value << std::endl;
}
Asynchronous Invocation
// callback-based
client.invoke(Req{...}, [](const Resp& resp) {
std::cout << "async result: " << resp.value << std::endl;
});
// future-based
auto future = client.async_invoke(Req{...});
auto resp = future.get();
Server Connection Detection
Client<Req, Resp> client("dds://my_service");
client.detect_connected([](bool connected) { ... }); // async
client.wait_for_connected(); // blocking
if (client.is_connected()) { ... } // non-blocking
Note
A timeout of 0 is treated as infinite (a warning is logged). send() is only valid when RespT == EmptyType. invoke() / async_invoke() are only valid when kHasResp is true.
Template Parameters
ReqTRequest message type. Must satisfy Serializer::is_supported().
RespTResponse type. Defaults to Traits::EmptyType (fire-and-forget).
SecTSecurity mode; defaults to SecurityType::kWithoutSecurity.