blob: ea18e418ff3f3539f9dc78d021f3b343ceefb3ac [file] [log] [blame]
#include "app_singleton.hpp"
#include "async_resp.hpp"
#include "http_request.hpp"
#include "privileges.hpp"
#include "utility.hpp"
#include <boost/beast/http/verb.hpp>
#include <array>
#include <string_view>
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define REDFISH_HANDLER_ADD(url, verb, privileges, func) \
plugins::addRedfishHandler<crow::black_magic::getParameterTag(url)>( \
url, verb, privileges, func)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define REDFISH_HANDLER_REPLACE(url, verb, func) \
plugins::replaceRedfishHandler<crow::black_magic::getParameterTag(url)>( \
url, verb, func)
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define REDFISH_HANDLER_REMOVE(url, verb) \
plugins::removeRedfishHandler<crow::black_magic::getParameterTag(url)>( \
url, verb);
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define REDFISH_HANDLER_APPEND(url, verb, func) \
plugins::appendRedfishHandler<crow::black_magic::getParameterTag(url)>( \
url, verb, func);
namespace plugins
{
template <uint64_t tag, typename RedfishHandler, size_t N>
void addRedfishHandler(std::string_view url, boost::beast::http::verb verb,
const std::array<redfish::Privileges, N>& p,
RedfishHandler&& func)
{
crow::globalBmcWebApp->addHandler<tag>(url, verb, p, func);
}
template <uint64_t tag, typename RedfishHandler>
void replaceRedfishHandler(std::string_view url, boost::beast::http::verb verb,
RedfishHandler&& func)
{
crow::globalBmcWebApp->replaceHandler<tag>(url, verb, func);
}
template <uint64_t tag>
void removeRedfishHandler(std::string_view url, boost::beast::http::verb verb)
{
crow::globalBmcWebApp->removeHandler<tag>(url, verb);
}
// For a specific route, appending more than one async callbacks should be rarely
// used.
// When multiple callbacks are appended. The order is LIFO: the last appended handler
// will be executed first.
template <uint64_t tag, typename RedfishHandler>
void appendRedfishHandler(std::string_view url, boost::beast::http::verb verb,
RedfishHandler&& func)
{
crow::globalBmcWebApp->appendHandler<tag>(url, verb, func);
}
} // namespace plugins