cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
i_connection.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 <functional>
23
28
29namespace msgpack_rpc::transport {
30
34class IConnection {
35public:
44 std::function<void(messages::ParsedMessage)>;
45
50 using MessageSentCallback = std::function<void()>;
51
59 using ConnectionClosedCallback = std::function<void(const Status&)>;
60
71 virtual void start(MessageReceivedCallback on_received,
72 MessageSentCallback on_sent, ConnectionClosedCallback on_closed) = 0;
73
79 virtual void async_send(const messages::SerializedMessage& message) = 0;
80
84 virtual void async_close() = 0;
85
91 [[nodiscard]] virtual const addresses::IAddress& local_address()
92 const noexcept = 0;
93
99 [[nodiscard]] virtual const addresses::IAddress& remote_address()
100 const noexcept = 0;
101
102 IConnection(const IConnection&) = delete;
103 IConnection(IConnection&&) = delete;
104 IConnection& operator=(const IConnection&) = delete;
105 IConnection& operator=(IConnection&&) = delete;
106
108 virtual ~IConnection() noexcept = default;
109
110protected:
112 IConnection() noexcept = default;
113};
114
115} // namespace msgpack_rpc::transport
Interface of addresses.
Definition i_address.h:31
Class of statuses.
Definition status.h:34
Class of serialized message data.
virtual void start(MessageReceivedCallback on_received, MessageSentCallback on_sent, ConnectionClosedCallback on_closed)=0
Start process of this connection.
std::function< void(messages::ParsedMessage)> MessageReceivedCallback
Type of callback functions called when a message is received.
virtual const addresses::IAddress & remote_address() const noexcept=0
Get the address of the remote endpoint.
std::function< void(const Status &)> ConnectionClosedCallback
Type of callback functions called when a connection is closed.
std::function< void()> MessageSentCallback
Type of callback functions called when a message is successfully sent.
virtual void async_close()=0
Asynchronously close this connection.
virtual const addresses::IAddress & local_address() const noexcept=0
Get the address of the local endpoint.
virtual void async_send(const messages::SerializedMessage &message)=0
Asynchronously send a message.
Definition of IAddress.
Namespace of addresses.
Definition i_address.h:26
std::variant< ParsedRequest, ParsedResponse, ParsedNotification > ParsedMessage
Type of parsed messages.
Namespace of transport of messages.
Definition backends.h:31
Definition of ParsedMessage type.
Definition of SerializedMessage class.
Definition of Status class.