cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
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
*/
20
#include "
msgpack_rpc/config/client_config.h
"
21
22
#include <chrono>
23
#include <ratio>
24
#include <string_view>
25
#include <utility>
26
27
#include "
msgpack_rpc/addresses/uri.h
"
28
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
29
#include "
msgpack_rpc/common/status_code.h
"
30
31
namespace
msgpack_rpc::config
{
32
33
namespace
{
34
35
constexpr
auto
CLIENT_CONFIG_CALL_TIMEOUT = std::chrono::seconds(15);
36
37
}
// namespace
38
39
ClientConfig::ClientConfig
() :
call_timeout_
(CLIENT_CONFIG_CALL_TIMEOUT) {}
40
41
ClientConfig
&
ClientConfig::add_uri
(
addresses::URI
uri) {
42
uris_
.push_back(std::move(uri));
43
return
*
this
;
44
}
45
46
ClientConfig
&
ClientConfig::add_uri
(std::string_view uri) {
47
return
add_uri
(
addresses::URI::parse
(uri));
48
}
49
50
const
std::vector<addresses::URI>&
ClientConfig::uris
() const noexcept {
51
return
uris_
;
52
}
53
54
ClientConfig
&
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
63
std::chrono::nanoseconds
ClientConfig::call_timeout
() const noexcept {
64
return
call_timeout_
;
65
}
66
67
MessageParserConfig
&
ClientConfig::message_parser
() noexcept {
68
return
message_parser_
;
69
}
70
71
const
MessageParserConfig
&
ClientConfig::message_parser
() const noexcept {
72
return
message_parser_
;
73
}
74
75
ExecutorConfig
&
ClientConfig::executor
() noexcept {
return
executor_
; }
76
77
const
ExecutorConfig
&
ClientConfig::executor
() const noexcept {
78
return
executor_
;
79
}
80
81
ReconnectionConfig
&
ClientConfig::reconnection
() noexcept {
82
return
reconnection_
;
83
}
84
85
const
ReconnectionConfig
&
ClientConfig::reconnection
() const noexcept {
86
return
reconnection_
;
87
}
88
89
}
// namespace msgpack_rpc::config
msgpack_rpc::addresses::URI
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition
uri.h:38
msgpack_rpc::addresses::URI::parse
static URI parse(std::string_view uri_string)
Parse a string to create a URI.
Definition
uri.cpp:54
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc::config::ClientConfig::reconnection
ReconnectionConfig & reconnection() noexcept
Get the configuration of reconnection.
Definition
client_config.cpp:81
msgpack_rpc::config::ClientConfig::uris_
std::vector< addresses::URI > uris_
URIs.
Definition
client_config.h:130
msgpack_rpc::config::ClientConfig::executor
ExecutorConfig & executor() noexcept
Get the configuration of executors.
Definition
client_config.cpp:75
msgpack_rpc::config::ClientConfig::executor_
ExecutorConfig executor_
Configuration of executors.
Definition
client_config.h:139
msgpack_rpc::config::ClientConfig::ClientConfig
ClientConfig()
Constructor.
Definition
client_config.cpp:39
msgpack_rpc::config::ClientConfig::reconnection_
ReconnectionConfig reconnection_
Configuration of reconnection.
Definition
client_config.h:142
msgpack_rpc::config::ClientConfig::uris
const std::vector< addresses::URI > & uris() const noexcept
Get the URIs of the server.
Definition
client_config.cpp:50
msgpack_rpc::config::ClientConfig::message_parser_
MessageParserConfig message_parser_
Configuration of parsers of messages.
Definition
client_config.h:136
msgpack_rpc::config::ClientConfig::call_timeout
std::chrono::nanoseconds call_timeout() const noexcept
Get the duration of timeout of RPCs.
Definition
client_config.cpp:63
msgpack_rpc::config::ClientConfig::call_timeout_
std::chrono::nanoseconds call_timeout_
Duration of timeout of RPCs.
Definition
client_config.h:133
msgpack_rpc::config::ClientConfig::message_parser
MessageParserConfig & message_parser() noexcept
Get the configuration of parsers of messages.
Definition
client_config.cpp:67
msgpack_rpc::config::ClientConfig::add_uri
ClientConfig & add_uri(addresses::URI uri)
Add a URI of the server.
Definition
client_config.cpp:41
msgpack_rpc::config::ExecutorConfig
Class of configuration of executors.
Definition
executor_config.h:31
msgpack_rpc::config::MessageParserConfig
Class of configuration of parsers of messages.
Definition
message_parser_config.h:31
msgpack_rpc::config::ReconnectionConfig
Class of configurations of reconnection.
Definition
reconnection_config.h:31
client_config.h
Definition of ClientConfig class.
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::config
Namespace of configurations.
Definition
client_config.h:32
status_code.h
Definition of StatusCode enumeration.
uri.h
Definition of URI class.
src
msgpack_rpc
config
client_config.cpp
Generated on
for cpp-msgpack-rpc by
1.18.0