diff options
author | Ed Tanous <edtanous@google.com> | 2023-06-26 22:47:24 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-06-28 18:14:01 +0300 |
commit | cfe3bc0aaf2589e76924e56232e723b42779b3fe (patch) | |
tree | e847fca25e8530f8116ceee2f7ad069f93ea6761 /http/routing/taggedrule.hpp | |
parent | 8b24275d7696c9df071d11e16a0f905b1e800163 (diff) | |
download | bmcweb-cfe3bc0aaf2589e76924e56232e723b42779b3fe.tar.xz |
Simplify the router
There's a lot of complexity left in the router. The recent decision to
only support string arguments means that this can be significantly
cleaned up.
In some cases, this is done to simply expand the variadic template and
handle all parameter cases up to 5 (which should be the max we ever
see). While this might seem like it's not very DRY friendly (Don't
repeat yourself) this is significantly better than what we had, which
was very tough to deciper.
Tested: Redfish service validator passes
Change-Id: Ic72e54cffd7b9f4a85e6c9d143c45fa20530a2cd
Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'http/routing/taggedrule.hpp')
-rw-r--r-- | http/routing/taggedrule.hpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/http/routing/taggedrule.hpp b/http/routing/taggedrule.hpp index ef62ab08da..5c0fe823bf 100644 --- a/http/routing/taggedrule.hpp +++ b/http/routing/taggedrule.hpp @@ -33,17 +33,14 @@ class TaggedRule : void operator()(Func&& f) { static_assert( - black_magic::CallHelper< - Func, black_magic::S<crow::Request, - std::shared_ptr<bmcweb::AsyncResp>&, - Args...>>::value, + std::is_invocable_v<Func, crow::Request, + std::shared_ptr<bmcweb::AsyncResp>&, Args...>, "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, + std::is_same_v< + void, std::invoke_result_t<Func, crow::Request, + std::shared_ptr<bmcweb::AsyncResp>&, + Args...>>, "Handler function with response argument should have void return type"); handler = std::forward<Func>(f); @@ -53,11 +50,32 @@ class TaggedRule : 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}); + if constexpr (sizeof...(Args) == 0) + { + handler(req, asyncResp); + } + else if constexpr (sizeof...(Args) == 1) + { + handler(req, asyncResp, params[0]); + } + else if constexpr (sizeof...(Args) == 2) + { + handler(req, asyncResp, params[0], params[1]); + } + else if constexpr (sizeof...(Args) == 3) + { + handler(req, asyncResp, params[0], params[1], params[2]); + } + else if constexpr (sizeof...(Args) == 4) + { + handler(req, asyncResp, params[0], params[1], params[2], params[3]); + } + else if constexpr (sizeof...(Args) == 5) + { + handler(req, asyncResp, params[0], params[1], params[2], params[3], + params[4]); + } + static_assert(sizeof...(Args) <= 5, "More args than are supported"); } private: |