VLink  2.0.0
A high-performance communication middleware
client.h File Reference

Caller-side primitive of the VLink method (RPC) communication model. More...

#include <chrono>
#include <future>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <type_traits>
#include <unordered_map>
#include "./base/functional.h"
#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

class  vlink::Client< ReqT, RespT, SecT >
 Type-safe RPC caller for the VLink method communication model. More...
 
class  vlink::SecurityClient< ReqT, RespT >
 Convenience alias of Client with per-message encryption enabled. More...
 

Namespaces

 

Detailed Description

Caller-side primitive of the VLink method (RPC) communication model.

Client<ReqT, RespT, SecT> issues remote calls to a matching Server. The request is serialised with the codec selected at compile time, sent via the active transport back-end, and (when RespT != EmptyType) the response payload is decoded back into a RespT instance and handed to the caller through one of several invocation styles.

The class is a thin, header-only template wrapper around ClientImpl with additional bookkeeping for std::future-based async invocations.

Request / Response Sequence
*   Client<Req,Resp>           Transport Back-end           Server<Req,Resp>
*   -----------------          ------------------           -----------------
*      | invoke(req)                  |                            |
*      |----------------------------->|  serialised request        |
*      |                              |--------------------------->|
*      |                              |                            |  user handler
*      |                              |                            |  fills resp
*      |                              |                            |
*      |                              |  serialised response       |
*      |                              |<---------------------------|
*      | deserialised response        |                            |
*      |<-----------------------------|                            |
* 
Five Invocation Modes
Method Blocking Result delivery When to use
invoke(req, resp&, timeout) Yes Out-param + bool Classic synchronous call
invoke(req, timeout) Yes std::optional Synchronous, no out-param
invoke(req, RespCallback) No Callback Async with handler
async_invoke(req) No std::future Future / promise model
send(req) No None Fire-and-forget request
Synchronous Invocation Example
vlink::Client<Req, Resp> cli("dds://compute/sum");
cli.wait_for_connected();
Resp resp;
if (cli.invoke(Req{1, 2}, resp)) { use(resp); }
if (auto r = cli.invoke(Req{3, 4})) { use(*r); }
Asynchronous Invocation Example
cli.invoke(Req{7, 8}, [](const Resp& r) { use(r); });
std::future<Resp> fut = cli.async_invoke(Req{9, 10});
Resp value = fut.get();
Connection Detection
cli.detect_connected([](bool connected) { ... });
cli.wait_for_connected(std::chrono::milliseconds(200));
if (cli.is_connected()) { ... }
Note
A timeout of 0 is treated as infinite and logs a warning. send() is only available when RespT == EmptyType, and the response-bearing overloads are only available when kHasResp is true (enforced by static_assert in the response-bearing entry points; the std::optional -returning overload inherits the constraint by delegating to the out-parameter invoke).
See also
server.h, node.h, serializer.h, base/functional.h