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>
diff --git a/http/routing/dynamicrule.hpp b/http/routing/dynamicrule.hpp
index 746765c..03452d8 100644
--- a/http/routing/dynamicrule.hpp
+++ b/http/routing/dynamicrule.hpp
@@ -16,160 +16,47 @@
 {
 namespace routing_handler_call_helper
 {
-template <typename T, int Pos>
-struct CallPair
-{
-    using type = T;
-    static const int pos = Pos;
-};
-
-template <typename H1>
-struct CallParams
-{
-    H1& handler;
-    const std::vector<std::string>& params;
-    const Request& req;
-    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp;
-};
-
-template <typename F, int NString, typename S1, typename S2>
-struct Call
-{};
-
-template <typename F, int NString, typename... Args1, typename... Args2>
-struct Call<F, NString, black_magic::S<std::string, Args1...>,
-            black_magic::S<Args2...>>
-{
-    void operator()(F cparams)
-    {
-        using pushed = typename black_magic::S<Args2...>::template push_back<
-            CallPair<std::string, NString>>;
-        Call<F, NString + 1, black_magic::S<Args1...>, pushed>()(cparams);
-    }
-};
-
-template <typename F, int NString, typename... Args1>
-struct Call<F, NString, black_magic::S<>, black_magic::S<Args1...>>
-{
-    void operator()(F cparams)
-    {
-        cparams.handler(cparams.req, cparams.asyncResp,
-                        cparams.params[Args1::pos]...);
-    }
-};
 
 template <typename Func, typename... ArgsWrapped>
 struct Wrapped
 {
     template <typename... Args>
-    void set(
-        Func f,
-        typename std::enable_if<
-            !std::is_same<
-                typename std::tuple_element<0, std::tuple<Args..., void>>::type,
-                const Request&>::value,
-            int>::type /*enable*/
-        = 0)
-    {
-        handler = [f = std::forward<Func>(f)](
-                      const Request&,
-                      const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-                      Args... args) { asyncResp->res.result(f(args...)); };
-    }
-
-    template <typename Req, typename... Args>
-    struct ReqHandlerWrapper
-    {
-        explicit ReqHandlerWrapper(Func fIn) : f(std::move(fIn)) {}
-
-        void operator()(const Request& req,
-                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
-                        Args... args)
-        {
-            asyncResp->res.result(f(req, args...));
-        }
-
-        Func f;
-    };
-
-    template <typename... Args>
-    void set(
-        Func f,
-        typename std::enable_if<
-            std::is_same<
-                typename std::tuple_element<0, std::tuple<Args..., void>>::type,
-                const Request&>::value &&
-                !std::is_same<typename std::tuple_element<
-                                  1, std::tuple<Args..., void, void>>::type,
-                              const std::shared_ptr<bmcweb::AsyncResp>&>::value,
-            int>::type /*enable*/
-        = 0)
-    {
-        handler = ReqHandlerWrapper<Args...>(std::move(f));
-        /*handler = (
-            [f = std::move(f)]
-            (const Request& req, Response& res, Args... args){
-                 res.result(f(req, args...));
-                 res.end();
-            });*/
-    }
-
-    template <typename... Args>
-    void set(
-        Func f,
-        typename std::enable_if<
-            std::is_same<
-                typename std::tuple_element<0, std::tuple<Args..., void>>::type,
-                const Request&>::value &&
-                std::is_same<typename std::tuple_element<
-                                 1, std::tuple<Args..., void, void>>::type,
-                             const std::shared_ptr<bmcweb::AsyncResp>&>::value,
-            int>::type /*enable*/
-        = 0)
+    void set(Func f)
     {
         handler = std::move(f);
     }
 
-    template <typename... Args>
-    struct HandlerTypeHelper
-    {
-        using type = std::function<void(
-            const crow::Request& /*req*/,
-            const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>;
-        using args_type = black_magic::S<Args...>;
-    };
-
-    template <typename... Args>
-    struct HandlerTypeHelper<const Request&, Args...>
-    {
-        using type = std::function<void(
-            const crow::Request& /*req*/,
-            const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>;
-        using args_type = black_magic::S<Args...>;
-    };
-
-    template <typename... Args>
-    struct HandlerTypeHelper<const Request&,
-                             const std::shared_ptr<bmcweb::AsyncResp>&, Args...>
-    {
-        using type = std::function<void(
-            const crow::Request& /*req*/,
-            const std::shared_ptr<bmcweb::AsyncResp>&, Args...)>;
-        using args_type = black_magic::S<Args...>;
-    };
-
-    typename HandlerTypeHelper<ArgsWrapped...>::type handler;
+    std::function<void(ArgsWrapped...)> handler;
 
     void operator()(const Request& req,
                     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                     const std::vector<std::string>& params)
     {
-        detail::routing_handler_call_helper::Call<
-            detail::routing_handler_call_helper::CallParams<decltype(handler)>,
-            0, typename HandlerTypeHelper<ArgsWrapped...>::args_type,
-            black_magic::S<>>()(
-            detail::routing_handler_call_helper::CallParams<decltype(handler)>{
-                handler, params, req, asyncResp});
+        if constexpr (sizeof...(ArgsWrapped) == 2)
+        {
+            handler(req, asyncResp);
+        }
+        else if constexpr (sizeof...(ArgsWrapped) == 3)
+        {
+            handler(req, asyncResp, params[0]);
+        }
+        else if constexpr (sizeof...(ArgsWrapped) == 4)
+        {
+            handler(req, asyncResp, params[0], params[1]);
+        }
+        else if constexpr (sizeof...(ArgsWrapped) == 5)
+        {
+            handler(req, asyncResp, params[0], params[1], params[2]);
+        }
+        else if constexpr (sizeof...(ArgsWrapped) == 6)
+        {
+            handler(req, asyncResp, params[0], params[1], params[2], params[3]);
+        }
+        else if constexpr (sizeof...(ArgsWrapped) == 7)
+        {
+            handler(req, asyncResp, params[0], params[1], params[2], params[3],
+                    params[4]);
+        }
     }
 };
 } // namespace routing_handler_call_helper