// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright OpenBMC Authors // SPDX-FileCopyrightText: Copyright 2020 Intel Corporation #pragma once #include "event_logs_object_type.hpp" #include "event_service_store.hpp" #include "filter_expr_parser_ast.hpp" #include "http_client.hpp" #include "http_response.hpp" #include "server_sent_event.hpp" #include "telemetry_readings.hpp" #include #include #include #include #include #include #include #include #include namespace redfish { static constexpr const char* subscriptionTypeSSE = "SSE"; static constexpr const uint8_t maxNoOfSubscriptions = 20; static constexpr const uint8_t maxNoOfSSESubscriptions = 10; struct TestEvent { std::optional eventGroupId; std::optional eventTimestamp; std::optional message; std::optional> messageArgs; std::optional messageId; std::optional originOfCondition; std::optional resolution; std::optional severity; }; class Subscription : public std::enable_shared_from_this { public: Subscription(const Subscription&) = delete; Subscription& operator=(const Subscription&) = delete; Subscription(Subscription&&) = delete; Subscription& operator=(Subscription&&) = delete; Subscription(std::shared_ptr userSubIn, const boost::urls::url_view_base& url, boost::asio::io_context& ioc); explicit Subscription(crow::sse_socket::Connection& connIn); ~Subscription() = default; // callback for subscription sendData void resHandler(const std::shared_ptr& /*self*/, const crow::Response& res); void sendHeartbeatEvent(); void scheduleNextHeartbeatEvent(); void heartbeatParametersChanged(); void onHbTimeout(const std::weak_ptr& weakSelf, const boost::system::error_code& ec); bool sendEventToSubscriber(uint64_t eventId, std::string&& msg); void filterAndSendEventLogs( uint64_t eventId, const std::vector& eventRecords); void filterAndSendReports(uint64_t eventId, const std::string& reportId, const telemetry::TimestampReadings& var); void updateRetryConfig(uint32_t retryAttempts, uint32_t retryTimeoutInterval); bool matchSseId(const crow::sse_socket::Connection& thisConn); // Check used to indicate what response codes are valid as part of our retry // policy. 2XX is considered acceptable static boost::system::error_code retryRespHandler(unsigned int respCode); std::shared_ptr userSub; std::function deleter; private: boost::urls::url host; std::shared_ptr policy; crow::sse_socket::Connection* sseConn = nullptr; boost::asio::steady_timer hbTimer; std::optional client; public: std::optional filter; }; } // namespace redfish