blob: 9fb6ba3835e65badb136e3636acb1109efa75e44 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous08bbe112023-04-06 13:10:02 -07003#pragma once
4
Ed Tanousd7857202025-01-28 15:32:26 -08005#include "async_resp.hpp"
Ed Tanous08bbe112023-04-06 13:10:02 -07006#include "baserule.hpp"
7#include "http_request.hpp"
Ed Tanous08bbe112023-04-06 13:10:02 -07008#include "server_sent_event.hpp"
9
Ed Tanousd7857202025-01-28 15:32:26 -080010#include <boost/asio/ip/tcp.hpp>
11#include <boost/asio/ssl/stream.hpp>
Ed Tanous08bbe112023-04-06 13:10:02 -070012
13#include <functional>
14#include <memory>
15#include <string>
Ed Tanousd7857202025-01-28 15:32:26 -080016#include <vector>
Ed Tanous08bbe112023-04-06 13:10:02 -070017
18namespace crow
19{
20
21class SseSocketRule : public BaseRule
22{
23 using self_t = SseSocketRule;
24
25 public:
Ed Tanouse60300a2025-02-23 12:31:53 -080026 explicit SseSocketRule(const std::string& ruleIn);
Ed Tanous08bbe112023-04-06 13:10:02 -070027
Ed Tanouse60300a2025-02-23 12:31:53 -080028 void validate() override;
Ed Tanous08bbe112023-04-06 13:10:02 -070029
30 void handle(const Request& /*req*/,
31 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Ed Tanouse60300a2025-02-23 12:31:53 -080032 const std::vector<std::string>& /*params*/) override;
Ed Tanous08bbe112023-04-06 13:10:02 -070033
Ed Tanousf80a87f2024-06-16 12:10:33 -070034 void handleUpgrade(const Request& req,
Ed Tanous08bbe112023-04-06 13:10:02 -070035 const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
Ed Tanouse60300a2025-02-23 12:31:53 -080036 boost::asio::ip::tcp::socket&& adaptor) override;
Ed Tanousf80a87f2024-06-16 12:10:33 -070037 void handleUpgrade(const Request& req,
Ed Tanous08bbe112023-04-06 13:10:02 -070038 const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/,
Ed Tanous003301a2024-04-16 09:59:19 -070039 boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&&
Ed Tanouse60300a2025-02-23 12:31:53 -080040 adaptor) override;
Ed Tanous08bbe112023-04-06 13:10:02 -070041
42 template <typename Func>
43 self_t& onopen(Func f)
44 {
45 openHandler = f;
46 return *this;
47 }
48
49 template <typename Func>
50 self_t& onclose(Func f)
51 {
52 closeHandler = f;
53 return *this;
54 }
55
56 private:
Ed Tanousf80a87f2024-06-16 12:10:33 -070057 std::function<void(crow::sse_socket::Connection&, const crow::Request&)>
58 openHandler;
Ed Tanous08bbe112023-04-06 13:10:02 -070059 std::function<void(crow::sse_socket::Connection&)> closeHandler;
60};
61
62} // namespace crow