blob: 78d1eb424c1257a301ac2a0aecf8e27a962b253b [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous7045c8d2017-04-03 10:04:37 -07003#pragma once
Ed Tanousd7857202025-01-28 15:32:26 -08004#include <boost/url/url_view.hpp>
5
Gunnar Mills1214b7e2020-06-04 10:11:30 -05006#include <functional>
Ed Tanousd7857202025-01-28 15:32:26 -08007#include <memory>
Ed Tanousd7857202025-01-28 15:32:26 -08008#include <string_view>
Ed Tanous1b0044b2018-08-03 14:30:05 -07009
Ed Tanous1abe55e2018-09-05 08:30:59 -070010namespace crow
11{
12namespace websocket
13{
Iwona Klimaszewskac0a1c8a2019-07-12 18:26:38 +020014
Ed Tanous863c1c22022-02-21 21:33:06 -080015enum class MessageType
16{
17 Binary,
18 Text,
19};
20
Ed Tanous1abe55e2018-09-05 08:30:59 -070021struct Connection : std::enable_shared_from_this<Connection>
22{
23 public:
Ed Tanous5ebb9d32023-02-27 18:20:47 -080024 Connection() = default;
Przemyslaw Czarnowski250b0eb2020-02-24 10:23:56 +010025
Ed Tanousecd6a3a2022-01-07 09:18:40 -080026 Connection(const Connection&) = delete;
27 Connection(Connection&&) = delete;
28 Connection& operator=(const Connection&) = delete;
29 Connection& operator=(const Connection&&) = delete;
30
Ed Tanous9eb808c2022-01-25 10:19:23 -080031 virtual void sendBinary(std::string_view msg) = 0;
Ed Tanous863c1c22022-02-21 21:33:06 -080032 virtual void sendEx(MessageType type, std::string_view msg,
33 std::function<void()>&& onDone) = 0;
Ed Tanous9eb808c2022-01-25 10:19:23 -080034 virtual void sendText(std::string_view msg) = 0;
Ed Tanous9eb808c2022-01-25 10:19:23 -080035 virtual void close(std::string_view msg = "quit") = 0;
Ed Tanous863c1c22022-02-21 21:33:06 -080036 virtual void deferRead() = 0;
37 virtual void resumeRead() = 0;
Ed Tanous1abe55e2018-09-05 08:30:59 -070038 virtual ~Connection() = default;
Ninad Palsule052bcbf2023-05-30 11:10:58 -050039 virtual boost::urls::url_view url() = 0;
Ed Tanous7045c8d2017-04-03 10:04:37 -070040};
Ed Tanous1abe55e2018-09-05 08:30:59 -070041} // namespace websocket
42} // namespace crow