cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
client_builder.h
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
#pragma once
21
22
#include <cstdint>
23
#include <memory>
24
#include <optional>
25
#include <string_view>
26
#include <utility>
27
28
#include "
msgpack_rpc/addresses/schemes.h
"
29
#include "
msgpack_rpc/addresses/uri.h
"
30
#include "
msgpack_rpc/clients/client.h
"
31
#include "
msgpack_rpc/clients/impl/i_client_builder_impl.h
"
32
#include "
msgpack_rpc/config/client_config.h
"
33
#include "
msgpack_rpc/logging/logger.h
"
34
35
namespace
msgpack_rpc::clients
{
36
40
class
ClientBuilder
{
41
public
:
48
ClientBuilder
() :
ClientBuilder
(
logging
::Logger::create()) {}
49
57
explicit
ClientBuilder
(
const
std::shared_ptr<logging::Logger>& logger)
58
:
ClientBuilder
(
config
::ClientConfig(), logger) {}
59
66
explicit
ClientBuilder
(
config::ClientConfig
client_config,
67
const
std::shared_ptr<logging::Logger>& logger =
68
logging::Logger::create
())
69
:
impl_
(
impl
::create_default_client_builder_impl(
70
std
::move(client_config), logger)) {}
71
78
ClientBuilder
&
connect_to
(
addresses::URI
uri) {
79
impl_
->connect_to(std::move(uri));
80
return
*
this
;
81
}
82
89
ClientBuilder
&
connect_to
(std::string_view uri) {
90
return
connect_to
(
addresses::URI::parse
(uri));
91
}
92
100
ClientBuilder
&
connect_to_tcp
(
101
std::string_view host, std::uint16_t port_number) {
102
return
connect_to
(
103
addresses::URI
(
addresses::TCP_SCHEME
, host, port_number));
104
}
105
111
[[nodiscard]]
Client
build
() {
return
Client
(
impl_
->build()); }
112
113
private
:
115
std::unique_ptr<impl::IClientBuilderImpl>
impl_
;
116
};
117
118
}
// namespace msgpack_rpc::clients
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::clients::ClientBuilder::ClientBuilder
ClientBuilder()
Constructor.
Definition
client_builder.h:48
msgpack_rpc::clients::ClientBuilder::ClientBuilder
ClientBuilder(const std::shared_ptr< logging::Logger > &logger)
Constructor.
Definition
client_builder.h:57
msgpack_rpc::clients::ClientBuilder::ClientBuilder
ClientBuilder(config::ClientConfig client_config, const std::shared_ptr< logging::Logger > &logger=logging::Logger::create())
Constructor.
Definition
client_builder.h:66
msgpack_rpc::clients::ClientBuilder::impl_
std::unique_ptr< impl::IClientBuilderImpl > impl_
Object of the internal implementation.
Definition
client_builder.h:115
msgpack_rpc::clients::ClientBuilder::connect_to_tcp
ClientBuilder & connect_to_tcp(std::string_view host, std::uint16_t port_number)
Add a TCP address to connect to.
Definition
client_builder.h:100
msgpack_rpc::clients::ClientBuilder::connect_to
ClientBuilder & connect_to(std::string_view uri)
Add a URI to connect to.
Definition
client_builder.h:89
msgpack_rpc::clients::ClientBuilder::build
Client build()
Build a client.
Definition
client_builder.h:111
msgpack_rpc::clients::ClientBuilder::connect_to
ClientBuilder & connect_to(addresses::URI uri)
Add a URI to connect to.
Definition
client_builder.h:78
msgpack_rpc::clients::Client
Class of clients.
Definition
client.h:39
msgpack_rpc::clients::Client::Client
Client(std::shared_ptr< impl::IClientImpl > impl)
Constructor.
Definition
client.h:49
msgpack_rpc::config::ClientConfig
Class of configuration of clients.
Definition
client_config.h:38
msgpack_rpc::logging::Logger::create
static std::shared_ptr< Logger > create(const config::LoggingConfig &config=config::LoggingConfig())
Create a logger.
Definition
logger.h:62
client.h
Definition of Client class.
client_config.h
Definition of ClientConfig class.
i_client_builder_impl.h
Definition of IClientBuilderImpl class.
logger.h
Definition of Logger class.
msgpack_rpc::addresses::TCP_SCHEME
constexpr std::string_view TCP_SCHEME
Scheme of TCP.
Definition
schemes.h:27
msgpack_rpc::clients::impl
Namespace of internal implementations.
Definition
i_call_future_impl.h:26
msgpack_rpc::clients
Namespace of clients.
Definition
call_future.h:30
msgpack_rpc::config
Namespace of configurations.
Definition
client_config.h:32
msgpack_rpc::logging
Namespace of logging.
Definition
i_log_sink.h:27
std
STL namespace.
schemes.h
Definition of constants of schemes.
uri.h
Definition of URI class.
include
msgpack_rpc
clients
client_builder.h
Generated on
for cpp-msgpack-rpc by
1.18.0