107#include <unordered_map>
122template <
typename ReqT,
typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
126 using UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>>;
129 using SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>>;
141 static constexpr bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>;
182 template <
typename ConfT,
typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
243 [[nodiscard]]
bool invoke(
const ReqT& req, RespT& resp,
258 [[nodiscard]] std::optional<RespT>
invoke(
const ReqT& req,
287 [[nodiscard]] std::future<RespT>
async_invoke(
const ReqT& req);
300 bool send(
const ReqT& req);
304 std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
306 uint64_t future_seq_{0};
307 std::mutex future_mtx_;
308 std::unordered_map<std::uint64_t, std::shared_ptr<std::promise<RespT>>> future_map_;
323template <
typename ReqT,
typename RespT = Traits::EmptyType>
Versatile 128-byte byte buffer with SBO, five ownership modes and compression helpers.
定义 bytes.h:113
void detect_connected(ConnectCallback &&callback)
Registers a callback invoked when the server connection state changes.
定义 client-inl.h:118
std::unique_ptr< Client< ReqT, RespT, SecT > > UniquePtr
Unique-pointer alias.
定义 client.h:126
static SharedPtr create_shared(const std::string &url_str, InitType type=InitType::kWithInit)
Creates a Client on the heap wrapped in a shared_ptr.
定义 client-inl.h:45
bool wait_for_connected(std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
Blocks until a server is available or the timeout expires.
定义 client-inl.h:123
std::shared_ptr< Client< ReqT, RespT, SecT > > SharedPtr
Shared-pointer alias.
定义 client.h:129
Client(const ConfT &conf, InitType type=InitType::kWithInit)
Constructs a client from a typed transport configuration object.
定义 client-inl.h:52
static UniquePtr create_unique(const std::string &url_str, InitType type=InitType::kWithInit)
Creates a Client on the heap wrapped in a unique_ptr.
定义 client-inl.h:39
std::function< void(const RespT &)> RespCallback
Callback type for async response delivery.
定义 client.h:135
static constexpr bool kHasResp
true when RespT is not EmptyType (client expects a response).
定义 client.h:141
bool invoke(const ReqT &req, RespT &resp, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
Sends a request and blocks until the response is received.
定义 client-inl.h:138
std::future< RespT > async_invoke(const ReqT &req)
Sends a request and returns a std::future for the response.
定义 client-inl.h:269
~Client() override
定义 client-inl.h:111
static constexpr Serializer::Type kReqType
Serializer type for ReqT.
定义 client.h:144
bool is_connected() const
Returns true if a server is currently available.
定义 client-inl.h:133
static constexpr ImplType kImplType
Node role identifier (kClient).
定义 client.h:138
bool send(const ReqT &req)
Sends a fire-and-forget request with no response.
定义 client-inl.h:375
static constexpr Serializer::Type kRespType
Serializer type for RespT.
定义 client.h:147
NodeImpl::ConnectCallback ConnectCallback
Callback type fired when server connection state changes.
定义 client.h:132
std::function< void(bool)> ConnectCallback
Callback invoked when the peer connection state changes.
定义 node_impl.h:148
std::function< void(const Bytes &)> MsgCallback
Callback delivering a raw serialised message to a SubscriberImpl or GetterImpl.
定义 node_impl.h:177
Convenience alias for Client with message security enabled.
定义 client.h:324
Abstract base class for all transport-specific client (RPC caller) implementations.
constexpr Type get_type_of() noexcept
Deduces the Type enumerator for T at compile time.
定义 serializer-inl.h:160
Type
Identifies the serialisation codec to use for a given C++ type.
定义 serializer.h:123
constexpr bool is_supported(Type type) noexcept
Returns true when type identifies a supported serializer.
定义 serializer-inl.h:157
InitType
Controls whether a node is initialised immediately at construction.
定义 types.h:132
@ kWithInit
Initialise immediately in the constructor.
定义 types.h:134
ImplType
Bitmask identifying the role of a VLink node implementation.
定义 types.h:89
@ kClient
Method client (RPC caller).
定义 types.h:92
@ kWithSecurity
Encrypted and authenticated transport.
定义 types.h:150
Base CRTP template for all VLink communication nodes.
static constexpr std::chrono::milliseconds kDefaultInterval
Default wait timeout: 5 seconds.
定义 types.h:201