107 #include <type_traits>
108 #include <unordered_map>
131 template <
typename ReqT,
typename RespT = Traits::EmptyType, SecurityType SecT = SecurityType::kWithoutSecurity>
134 using UniquePtr = std::unique_ptr<Client<ReqT, RespT, SecT>>;
135 using SharedPtr = std::shared_ptr<Client<ReqT, RespT, SecT>>;
140 static constexpr
bool kHasResp = !std::is_same_v<RespT, Traits::EmptyType>;
177 template <
typename ConfT,
typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
242 [[nodiscard]]
bool invoke(
const ReqT& req, RespT& resp,
256 [[nodiscard]] std::optional<RespT>
invoke(
const ReqT& req,
285 [[nodiscard]] std::future<RespT>
async_invoke(
const ReqT& req);
297 bool send(
const ReqT& req);
301 std::chrono::milliseconds timeout = std::chrono::milliseconds(0));
303 uint64_t future_seq_{0};
304 std::mutex future_mtx_;
305 std::unordered_map<std::uint64_t, std::shared_ptr<std::promise<RespT>>> future_map_;
320 template <
typename ReqT,
typename RespT = Traits::EmptyType>
323 using UniquePtr = std::unique_ptr<SecurityClient<ReqT, RespT>>;
324 using SharedPtr = std::shared_ptr<SecurityClient<ReqT, RespT>>;
336 template <
typename SecurityConfigT = Security::Config>
350 template <
typename SecurityConfigT = Security::Config>
364 template <
typename ConfT,
typename SecurityConfigT = Security::Config,
365 typename = std::enable_if_t<std::is_base_of_v<Conf, ConfT>>>
383 template <
typename SecurityConfigT = Security::Config>
384 explicit SecurityClient(
const std::string& url_str, SecurityConfigT&& sec_cfg = {},
Fixed-size 128-byte buffer holder with SBO, five ownership modes and integrated codecs.
Definition: bytes.h:120
Type-safe RPC caller for the VLink method communication model.
Definition: client.h:132
void detect_connected(ConnectCallback &&callback)
Registers a callback invoked when the server-presence state changes.
Definition: client-inl.h:122
std::unique_ptr< Client< ReqT, RespT, SecT > > UniquePtr
Owning unique-pointer alias.
Definition: client.h:134
static SharedPtr create_shared(const std::string &url_str, InitType type=InitType::kWithInit)
Heap-allocates a Client and wraps it in a std::shared_ptr.
Definition: client-inl.h:46
bool wait_for_connected(std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
Blocks until a server is discovered or timeout expires.
Definition: client-inl.h:127
Client(const ConfT &conf, InitType type=InitType::kWithInit)
Constructs a client from a typed transport configuration object.
Definition: client-inl.h:53
static UniquePtr create_unique(const std::string &url_str, InitType type=InitType::kWithInit)
Heap-allocates a Client and wraps it in a std::unique_ptr.
Definition: client-inl.h:40
static constexpr bool kHasResp
true when response expected.
Definition: client.h:140
bool invoke(const ReqT &req, RespT &resp, std::chrono::milliseconds timeout=Timeout::kDefaultInterval)
Synchronous request/response invocation with an output parameter.
Definition: client-inl.h:142
std::future< RespT > async_invoke(const ReqT &req)
Asynchronous future-based invocation.
Definition: client-inl.h:279
~Client() override
Destroys the client and tears down outstanding promises.
Definition: client-inl.h:111
static constexpr Serializer::Type kReqType
Codec for the request.
Definition: client.h:141
std::shared_ptr< Client< ReqT, RespT, SecT > > SharedPtr
Owning shared-pointer alias.
Definition: client.h:135
bool is_connected() const
Non-blocking query of server presence.
Definition: client-inl.h:137
static constexpr ImplType kImplType
Node role tag (kClient).
Definition: client.h:139
bool send(const ReqT &req)
Fire-and-forget request emission.
Definition: client-inl.h:386
static constexpr Serializer::Type kRespType
Codec for the response.
Definition: client.h:142
Copyable type-erased callable analogue of std::function with a tunable SBO and pool spill.
Definition: functional.h:131
Function< void(bool)> ConnectCallback
Callback fired when peer presence changes.
Definition: node_impl.h:171
Transport-agnostic CRTP base for all VLink communication primitives.
Definition: node.h:164
Convenience alias of Client with per-message encryption enabled.
Definition: client.h:321
std::unique_ptr< SecurityClient< ReqT, RespT > > UniquePtr
Owning unique-pointer alias.
Definition: client.h:323
static UniquePtr create_unique(const std::string &url_str, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Heap-allocates a SecurityClient and wraps it in a std::unique_ptr.
Definition: client-inl.h:478
std::shared_ptr< SecurityClient< ReqT, RespT > > SharedPtr
Owning shared-pointer alias.
Definition: client.h:324
static SharedPtr create_shared(const std::string &url_str, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Heap-allocates a SecurityClient and wraps it in a std::shared_ptr.
Definition: client-inl.h:488
SecurityClient(const ConfT &conf, SecurityConfigT &&sec_cfg={}, InitType type=InitType::kWithInit)
Constructs a SecurityClient from a typed configuration object.
Definition: client-inl.h:498
Transport-neutral backbone shared by every method-model client implementation.
Pool-backed type-erased callables: copyable vlink::Function and move-only vlink::MoveFunction.
Type
Identifies the codec to use for a given C++ message type.
Definition: serializer.h:154
constexpr bool is_supported(Type type) noexcept
Reports whether type identifies a usable codec.
Definition: serializer-inl.h:160
InitType
Selects between immediate and deferred node initialisation.
Definition: types.h:154
@ kWithInit
Initialise immediately in the constructor.
ImplType
Bitmask identifying the role of a VLink node implementation.
Definition: types.h:110
@ kClient
Method client (RPC caller).
Definition: types.h:113
Common CRTP base for every VLink communication primitive.
static constexpr std::chrono::milliseconds kDefaultInterval
Default wait timeout: 5 seconds.
Definition: types.h:258