diff options
author | Ed Tanous <edtanous@google.com> | 2023-04-06 23:10:02 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-06-09 22:13:40 +0300 |
commit | 08bbe1199f02d09f908cd3adcf4329e4bd67fd52 (patch) | |
tree | 9824a615569928f65523f13a876a0def301562dd /http/routing/taggedrule.hpp | |
parent | b90d14f220cba6de26dcf8749b2f8df062487d72 (diff) | |
download | bmcweb-08bbe1199f02d09f908cd3adcf4329e4bd67fd52.tar.xz |
Break up router into separate files
The router is a giant behemoth. Start breaking it down into pieces.
Tested: Redfish service validator passes.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I9d04f53a58ffce3ecbd88dded1aa6e9648d2a762
Diffstat (limited to 'http/routing/taggedrule.hpp')
-rw-r--r-- | http/routing/taggedrule.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/http/routing/taggedrule.hpp b/http/routing/taggedrule.hpp new file mode 100644 index 0000000000..ef62ab08da --- /dev/null +++ b/http/routing/taggedrule.hpp @@ -0,0 +1,68 @@ +#pragma once +#include "baserule.hpp" +#include "dynamicrule.hpp" +#include "ruleparametertraits.hpp" + +#include <boost/beast/http/verb.hpp> + +#include <memory> +#include <string> +#include <vector> + +namespace crow +{ +template <typename... Args> +class TaggedRule : + public BaseRule, + public RuleParameterTraits<TaggedRule<Args...>> +{ + public: + using self_t = TaggedRule<Args...>; + + explicit TaggedRule(const std::string& ruleIn) : BaseRule(ruleIn) {} + + void validate() override + { + if (!handler) + { + throw std::runtime_error("no handler for url " + rule); + } + } + + template <typename Func> + void operator()(Func&& f) + { + static_assert( + black_magic::CallHelper< + Func, black_magic::S<crow::Request, + std::shared_ptr<bmcweb::AsyncResp>&, + Args...>>::value, + "Handler type is mismatched with URL parameters"); + static_assert( + std::is_same< + void, + decltype(f(std::declval<crow::Request>(), + std::declval<std::shared_ptr<bmcweb::AsyncResp>&>(), + std::declval<Args>()...))>::value, + "Handler function with response argument should have void return type"); + + handler = std::forward<Func>(f); + } + + void handle(const Request& req, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const std::vector<std::string>& params) override + { + detail::routing_handler_call_helper::Call< + detail::routing_handler_call_helper::CallParams<decltype(handler)>, + 0, black_magic::S<Args...>, black_magic::S<>>()( + detail::routing_handler_call_helper::CallParams<decltype(handler)>{ + handler, params, req, asyncResp}); + } + + private: + std::function<void(const crow::Request&, + const std::shared_ptr<bmcweb::AsyncResp>&, Args...)> + handler; +}; +} // namespace crow |