unilink  0.4.3
A simple C++ library for unified async communication
ichannel.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 <functional>
20 #include <future>
21 #include <memory>
22 #include <string>
23 #include <string_view>
24 
27 
28 namespace unilink {
29 namespace wrapper {
30 
35  public:
36  using MessageHandler = std::function<void(const MessageContext&)>;
37  using ConnectionHandler = std::function<void(const ConnectionContext&)>;
38  using ErrorHandler = std::function<void(const ErrorContext&)>;
39 
40  virtual ~ChannelInterface() = default;
41 
42  // Lifecycle
43  virtual std::future<bool> start() = 0;
44  virtual void stop() = 0;
45  virtual bool is_connected() const = 0;
46 
47  // Transmission
48  virtual void send(std::string_view data) = 0;
49  virtual void send_line(std::string_view line) = 0;
50 
51  // Event handlers
52  virtual ChannelInterface& on_data(MessageHandler handler) = 0;
55  virtual ChannelInterface& on_error(ErrorHandler handler) = 0;
56 
57  // Management
58  virtual ChannelInterface& auto_manage(bool manage = true) = 0;
59 };
60 
61 } // namespace wrapper
62 } // namespace unilink
#define UNILINK_API
Definition: visibility.hpp:37