unilink  0.4.3
A simple C++ library for unified async communication
iserver.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_view>
23 #include <vector>
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 ~ServerInterface() = default;
41 
42  // Lifecycle
43  virtual std::future<bool> start() = 0;
44  virtual void stop() = 0;
45  virtual bool is_listening() const = 0;
46 
47  // Transmission
48  virtual bool broadcast(std::string_view data) = 0;
49  virtual bool send_to(size_t client_id, std::string_view data) = 0;
50 
51  // Event handlers
54  virtual ServerInterface& on_data(MessageHandler handler) = 0;
55  virtual ServerInterface& on_error(ErrorHandler handler) = 0;
56 
57  // Management
58  virtual size_t get_client_count() const = 0;
59  virtual std::vector<size_t> get_connected_clients() const = 0;
60 };
61 
62 } // namespace wrapper
63 } // namespace unilink
#define UNILINK_API
Definition: visibility.hpp:37