cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
client_builder_impl.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 <memory>
23#include <utility>
24
36
38
42class ClientBuilderImpl final : public IClientBuilderImpl {
43public:
52 ClientBuilderImpl(std::shared_ptr<executors::IAsyncExecutor> executor,
53 std::shared_ptr<logging::Logger> logger, config::ClientConfig config,
55 : executor_(std::move(executor)),
56 logger_(std::move(logger)),
57 config_(std::move(config)),
58 backends_(std::move(backends)) {}
59
62 std::shared_ptr<transport::IBackend> backend) override {
63 backends_.append(backend);
64 }
65
67 void connect_to(addresses::URI uri) override {
68 config_.add_uri(std::move(uri));
69 }
70
72 [[nodiscard]] std::shared_ptr<clients::impl::IClientImpl> build() override {
73 const auto connector = std::make_shared<ClientConnector>(executor_,
74 backends_, config_.uris(), config_.reconnection(), logger_);
75
76 const auto call_list = std::make_shared<CallList>(
77 config_.call_timeout(), executor_, logger_);
78
79 auto client = std::make_shared<ClientImpl>(
80 connector, call_list, executor_, logger_);
81 client->start();
82
83 return client;
84 }
85
86private:
88 std::shared_ptr<executors::IAsyncExecutor> executor_;
89
91 std::shared_ptr<logging::Logger> logger_;
92
95
98};
99
100} // namespace msgpack_rpc::clients::impl
Definition of BackendList class.
Definition of CallList class.
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition uri.h:38
ClientBuilderImpl(std::shared_ptr< executors::IAsyncExecutor > executor, std::shared_ptr< logging::Logger > logger, config::ClientConfig config, transport::BackendList backends)
Constructor.
std::shared_ptr< logging::Logger > logger_
Logger.
void connect_to(addresses::URI uri) override
Add a URI to connect to.
std::shared_ptr< executors::IAsyncExecutor > executor_
Executor.
config::ClientConfig config_
Configuration.
void register_protocol(std::shared_ptr< transport::IBackend > backend) override
Register a protocol.
std::shared_ptr< clients::impl::IClientImpl > build() override
Build a client.
Class of configuration of clients.
Class of lists of backends of protocols.
Definition of ClientConfig class.
Definition of ClientConnector class.
Definition of ClientImpl class.
Definition of IAsyncExecutor class.
Definition of IBackend class.
Definition of IClientBuilderImpl class.
Definition of IClientImpl class.
Definition of Logger class.
Namespace of internal implementations.
Namespace of configurations.
STL namespace.
Definition of URI class.