unilink  0.4.3
A simple C++ library for unified async communication
channel_factory.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 Jinwoo Sung
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  */
16 
17 #pragma once
18 
19 #include <boost/asio/io_context.hpp>
20 #include <memory>
21 #include <variant>
22 
29 
30 namespace unilink {
31 namespace factory {
32 
39  public:
41  std::variant<config::TcpClientConfig, config::TcpServerConfig, config::SerialConfig, config::UdpConfig>;
42 
43  // Channel creation
44  static std::shared_ptr<interface::Channel> create(const ChannelOptions& options,
45  std::shared_ptr<boost::asio::io_context> external_ioc = nullptr);
46 
47  private:
48  // Creation functions for each Transport type
49  static std::shared_ptr<interface::Channel> create_tcp_server(const config::TcpServerConfig& cfg,
50  std::shared_ptr<boost::asio::io_context> external_ioc);
51  static std::shared_ptr<interface::Channel> create_tcp_client(const config::TcpClientConfig& cfg,
52  std::shared_ptr<boost::asio::io_context> external_ioc);
53  static std::shared_ptr<interface::Channel> create_serial(const config::SerialConfig& cfg,
54  std::shared_ptr<boost::asio::io_context> external_ioc);
55  static std::shared_ptr<interface::Channel> create_udp(const config::UdpConfig& cfg,
56  std::shared_ptr<boost::asio::io_context> external_ioc);
57 };
58 
59 } // namespace factory
60 } // namespace unilink
#define UNILINK_API
Definition: visibility.hpp:37