1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "async_resp.hpp" 6 #include "baserule.hpp" 7 #include "http_request.hpp" 8 #include "server_sent_event.hpp" 9 10 #include <boost/asio/ip/tcp.hpp> 11 #include <boost/asio/ssl/stream.hpp> 12 13 #include <functional> 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 namespace crow 19 { 20 21 class SseSocketRule : public BaseRule 22 { 23 using self_t = SseSocketRule; 24 25 public: 26 explicit SseSocketRule(const std::string& ruleIn); 27 28 void validate() override; 29 30 void handle(const Request& /*req*/, 31 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 32 const std::vector<std::string>& /*params*/) override; 33 34 void handleUpgrade(const Request& req, 35 const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, 36 boost::asio::ip::tcp::socket&& adaptor) override; 37 void handleUpgrade(const Request& req, 38 const std::shared_ptr<bmcweb::AsyncResp>& /*asyncResp*/, 39 boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&& 40 adaptor) override; 41 42 template <typename Func> onopen(Func f)43 self_t& onopen(Func f) 44 { 45 openHandler = f; 46 return *this; 47 } 48 49 template <typename Func> onclose(Func f)50 self_t& onclose(Func f) 51 { 52 closeHandler = f; 53 return *this; 54 } 55 56 private: 57 std::function<void(crow::sse_socket::Connection&, const crow::Request&)> 58 openHandler; 59 std::function<void(crow::sse_socket::Connection&)> closeHandler; 60 }; 61 62 } // namespace crow 63