cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
client_config.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
21
22#include <chrono>
23#include <ratio>
24#include <string_view>
25#include <utility>
26
30
31namespace msgpack_rpc::config {
32
33namespace {
34
35constexpr auto CLIENT_CONFIG_CALL_TIMEOUT = std::chrono::seconds(15);
36
37} // namespace
38
39ClientConfig::ClientConfig() : call_timeout_(CLIENT_CONFIG_CALL_TIMEOUT) {}
40
42 uris_.push_back(std::move(uri));
43 return *this;
44}
45
46ClientConfig& ClientConfig::add_uri(std::string_view uri) {
47 return add_uri(addresses::URI::parse(uri));
48}
49
50const std::vector<addresses::URI>& ClientConfig::uris() const noexcept {
51 return uris_;
52}
53
54ClientConfig& ClientConfig::call_timeout(std::chrono::nanoseconds value) {
55 if (value <= std::chrono::nanoseconds(0)) {
56 throw MsgpackRPCException(StatusCode::INVALID_ARGUMENT,
57 "Duration of timeout must be longer than zero.");
58 }
59 call_timeout_ = value;
60 return *this;
61}
62
63std::chrono::nanoseconds ClientConfig::call_timeout() const noexcept {
64 return call_timeout_;
65}
66
70
72 return message_parser_;
73}
74
76
77const ExecutorConfig& ClientConfig::executor() const noexcept {
78 return executor_;
79}
80
84
86 return reconnection_;
87}
88
89} // namespace msgpack_rpc::config
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition uri.h:38
static URI parse(std::string_view uri_string)
Parse a string to create a URI.
Definition uri.cpp:54
Class of exceptions in cpp-msgpack-rpc library.
ReconnectionConfig & reconnection() noexcept
Get the configuration of reconnection.
std::vector< addresses::URI > uris_
URIs.
ExecutorConfig & executor() noexcept
Get the configuration of executors.
ExecutorConfig executor_
Configuration of executors.
ReconnectionConfig reconnection_
Configuration of reconnection.
const std::vector< addresses::URI > & uris() const noexcept
Get the URIs of the server.
MessageParserConfig message_parser_
Configuration of parsers of messages.
std::chrono::nanoseconds call_timeout() const noexcept
Get the duration of timeout of RPCs.
std::chrono::nanoseconds call_timeout_
Duration of timeout of RPCs.
MessageParserConfig & message_parser() noexcept
Get the configuration of parsers of messages.
ClientConfig & add_uri(addresses::URI uri)
Add a URI of the server.
Class of configuration of executors.
Class of configuration of parsers of messages.
Class of configurations of reconnection.
Definition of ClientConfig class.
Definition of MsgpackRPCException class.
Namespace of configurations.
Definition of StatusCode enumeration.
Definition of URI class.