cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
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
34
35namespace msgpack_rpc::clients {
36
41public:
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 =
69 : impl_(impl::create_default_client_builder_impl(
70 std::move(client_config), logger)) {}
71
79 impl_->connect_to(std::move(uri));
80 return *this;
81 }
82
89 ClientBuilder& connect_to(std::string_view uri) {
91 }
92
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
113private:
115 std::unique_ptr<impl::IClientBuilderImpl> impl_;
116};
117
118} // namespace msgpack_rpc::clients
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
ClientBuilder(const std::shared_ptr< logging::Logger > &logger)
Constructor.
ClientBuilder(config::ClientConfig client_config, const std::shared_ptr< logging::Logger > &logger=logging::Logger::create())
Constructor.
std::unique_ptr< impl::IClientBuilderImpl > impl_
Object of the internal implementation.
ClientBuilder & connect_to_tcp(std::string_view host, std::uint16_t port_number)
Add a TCP address to connect to.
ClientBuilder & connect_to(std::string_view uri)
Add a URI to connect to.
ClientBuilder & connect_to(addresses::URI uri)
Add a URI to connect to.
Class of clients.
Definition client.h:39
Class of configuration of clients.
static std::shared_ptr< Logger > create(const config::LoggingConfig &config=config::LoggingConfig())
Create a logger.
Definition logger.h:62
Definition of Client class.
Definition of ClientConfig class.
Definition of IClientBuilderImpl class.
Definition of Logger class.
constexpr std::string_view TCP_SCHEME
Scheme of TCP.
Definition schemes.h:27
Namespace of internal implementations.
Namespace of clients.
Definition call_future.h:30
Namespace of configurations.
Namespace of logging.
Definition i_log_sink.h:27
STL namespace.
Definition of constants of schemes.
Definition of URI class.