cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
unix_socket_acceptor_factory.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 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 "msgpack_rpc/config.h"
23
24#if MSGPACK_RPC_HAS_UNIX_SOCKETS
25
26#include <memory>
27#include <string>
28#include <string_view>
29#include <utility>
30#include <vector>
31
32#include <asio/local/basic_endpoint.hpp>
33#include <fmt/format.h>
34
44
45namespace msgpack_rpc::transport::unix_socket {
46
50class UnixSocketAcceptorFactory final : public IAcceptorFactory {
51public:
52 // Change to template when another protocol is implemented.
53
55 using AcceptorType = unix_socket::UnixSocketAcceptor;
56
58 using ConcreteAddress = addresses::UnixSocketAddress;
59
68 UnixSocketAcceptorFactory(std::shared_ptr<executors::IExecutor> executor,
69 const config::MessageParserConfig& message_parser_config,
70 std::shared_ptr<logging::Logger> logger, std::string_view scheme)
71 : executor_(std::move(executor)),
72 message_parser_config_(message_parser_config),
73 scheme_(scheme),
74 log_name_(fmt::format("AcceptorFactory({})", scheme_)),
75 logger_(std::move(logger)) {}
76
78 std::vector<std::shared_ptr<IAcceptor>> create(
79 const addresses::URI& uri) override {
80 const ConcreteAddress local_address(uri.host_or_path());
81 return std::vector<std::shared_ptr<IAcceptor>>{
82 std::make_shared<AcceptorType>(
83 local_address, executor_, message_parser_config_, logger_)};
84 }
85
86private:
88 std::shared_ptr<executors::IExecutor> executor_;
89
91 config::MessageParserConfig message_parser_config_;
92
94 std::string scheme_;
95
97 std::string log_name_;
98
100 std::shared_ptr<logging::Logger> logger_;
101};
102
103} // namespace msgpack_rpc::transport::unix_socket
104
105#endif
Definition of Acceptor class.
Definitions of platform-specific macros.
Definition of IAcceptor class.
Definition of IAcceptorFactory class.
Definition of IExecutor class.
Definition of Logger class.
Definition of MessageParserConfig class.
Definition of UnixSocketAcceptor type.
Definition of UnixSocketAddress class.
Definition of URI class.