VLink  2.0.0
A high-performance communication middleware
client.h 文件参考

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

#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"
client.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

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

命名空间

 

详细描述

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()) { ... }
注解
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).
参见
server.h, node.h, serializer.h, base/functional.h