blob: b2f41737245e621417280b7ebfa88c14a2ceb60e [file] [log] [blame]
#ifndef THIRD_PARTY_GBMCWEB_INCLUDE_ASYNC_RESP_H_
#define THIRD_PARTY_GBMCWEB_INCLUDE_ASYNC_RESP_H_
#include <cstdint>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "boost/asio/error.hpp" // NOLINT
#include "boost/asio/io_context.hpp" // NOLINT
#include "subscription.h"
#include "http_response.hpp"
#include "request_stats.hpp"
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
};
// For unit tests usage only: don't need the strand.
AsyncResp() = default;
explicit 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
#endif // THIRD_PARTY_GBMCWEB_INCLUDE_ASYNC_RESP_H_