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
25
#include "
unilink/base/visibility.hpp
"
26
#include "
unilink/wrapper/context.hpp
"
27
28
namespace
unilink
{
29
namespace
wrapper {
30
34
class
UNILINK_API
ChannelInterface
{
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;
53
virtual
ChannelInterface
&
on_connect
(
ConnectionHandler
handler) = 0;
54
virtual
ChannelInterface
&
on_disconnect
(
ConnectionHandler
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
unilink::wrapper::ChannelInterface
Common interface for 1:1 point-to-point communication (e.g., TcpClient, Serial, Udp)
Definition:
ichannel.hpp:34
unilink::wrapper::ChannelInterface::start
virtual std::future< bool > start()=0
unilink::wrapper::ChannelInterface::send_line
virtual void send_line(std::string_view line)=0
unilink::wrapper::ChannelInterface::send
virtual void send(std::string_view data)=0
unilink::wrapper::ChannelInterface::ErrorHandler
std::function< void(const ErrorContext &)> ErrorHandler
Definition:
ichannel.hpp:38
unilink::wrapper::ChannelInterface::on_disconnect
virtual ChannelInterface & on_disconnect(ConnectionHandler handler)=0
unilink::wrapper::ChannelInterface::on_data
virtual ChannelInterface & on_data(MessageHandler handler)=0
unilink::wrapper::ChannelInterface::~ChannelInterface
virtual ~ChannelInterface()=default
unilink::wrapper::ChannelInterface::MessageHandler
std::function< void(const MessageContext &)> MessageHandler
Definition:
ichannel.hpp:36
unilink::wrapper::ChannelInterface::auto_manage
virtual ChannelInterface & auto_manage(bool manage=true)=0
unilink::wrapper::ChannelInterface::stop
virtual void stop()=0
unilink::wrapper::ChannelInterface::ConnectionHandler
std::function< void(const ConnectionContext &)> ConnectionHandler
Definition:
ichannel.hpp:37
unilink::wrapper::ChannelInterface::on_error
virtual ChannelInterface & on_error(ErrorHandler handler)=0
unilink::wrapper::ChannelInterface::on_connect
virtual ChannelInterface & on_connect(ConnectionHandler handler)=0
unilink::wrapper::ChannelInterface::is_connected
virtual bool is_connected() const =0
unilink::wrapper::ConnectionContext
Context for connection/disconnection events.
Definition:
context.hpp:54
unilink::wrapper::ErrorContext
Context for error events.
Definition:
context.hpp:70
unilink::wrapper::MessageContext
Context for data/message related events.
Definition:
context.hpp:33
context.hpp
unilink
Definition:
common.hpp:37
visibility.hpp
UNILINK_API
#define UNILINK_API
Definition:
visibility.hpp:37
unilink
wrapper
ichannel.hpp
Generated on Wed Mar 25 2026 21:38:57 for unilink by
1.9.1