blob: 33fdc334a56ec9e295f87eae7ae9f8ce36797817 [file] [log] [blame]
#pragma once
#include "subscription.h"
#include "http_response.hpp"
#include "logging.hpp"
#include "request_stats.hpp"
#include <boost/asio/error.hpp>
#include <boost/asio/io_context.hpp>
#include <functional>
#include <memory>
#include <optional>
namespace bmcweb
{
constexpr const char* BMCWEB_HINT_MAX_AGE_SEC = "BMCWEB_HINT_MAX_AGE_SEC";
// TODO: need to find a better spot for these ^ ?
/**
* AsyncResp
* Gathers data needed for response processing after async calls are done
*/
class AsyncResp
{
public:
enum class ResponseType : std::uint8_t
{
kPolling,
kPollingCustomRefreshInterval,
kSubscription,
kCancelSubscription,
kOriginOfCondition
};
#ifdef UNIT_TEST_BUILD
// Unit tests dont need the strand.
AsyncResp() = default;
#endif
AsyncResp(const std::shared_ptr<boost::asio::io_context::strand>& strand)
: strand_(strand) {};
explicit AsyncResp(
crow::Response&& res,
const std::shared_ptr<boost::asio::io_context::strand>& strand)
: res(std::move(res)), strand_(strand) {}
AsyncResp(const AsyncResp&) = delete;
AsyncResp(AsyncResp&&) = delete;
AsyncResp& operator=(const AsyncResp&) = delete;
AsyncResp& operator=(AsyncResp&&) = delete;
~AsyncResp();
crow::Response res;
int64_t hintMaxAgeSec = 0;
std::optional<int64_t> hintCacheMaxAgeSec;
uint64_t refresh_interval_ms = 0;
ResponseType response_type = ResponseType::kPolling;
std::shared_ptr<boost::asio::io_context::strand> strand_;
// We need to store delegated expand here so that the delgation is accessible via plugins
uint8_t delegatedExpandLevel = 0;
// Collection of EventSourceId objects.
// Optional as eventSourceIds are only used in response to internal
// requests originated by SubscriptionBackend and empty eventSourceIds
// would be a valid response.
std::optional<std::vector<ecclesia::EventSourceId>> eventSourceIds;
// Cancel the managed object subscription.
bool cancel_subscription_ = false;
std::shared_ptr<managedStore::RequestStatsContext> requestStatsContext;
};
} // namespace bmcweb