blob: 7a06cf9906bbd8dcfcc2ea5a22a79935d3bd382c [file] [log] [blame]
#ifndef THIRD_PARTY_GBMCWEB_PLUGINS_MACROS_H_
#define THIRD_PARTY_GBMCWEB_PLUGINS_MACROS_H_
#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>
#include "boost/beast/http/verb.hpp" // NOLINT
#include "app_singleton.hpp"
#include "privileges.hpp"
// 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
#endif // THIRD_PARTY_GBMCWEB_PLUGINS_MACROS_H_