diff --git a/examples/wrapper_example/wrapper_example.ino b/examples/wrapper_example/wrapper_example.ino index 6ed4f26..d94e6d2 100644 --- a/examples/wrapper_example/wrapper_example.ino +++ b/examples/wrapper_example/wrapper_example.ino @@ -55,9 +55,9 @@ void loop() { out_packer.clear(); blink_before(); - int out = wrapped_add(5, 3); + int out = (*wrapped_add)(5, 3); - bool unpack_ok = wrapped_add(unpacker, out_packer); + bool unpack_ok = (*wrapped_add)(unpacker, out_packer); Serial.print("simple call: "); Serial.println(out); @@ -82,7 +82,7 @@ void loop() { unpacker.feed(packer.data(), packer.size()); out_packer.clear(); - bool should_be_false = wrapped_divide(unpacker, out_packer); + bool should_be_false = (*wrapped_divide)(unpacker, out_packer); if (!should_be_false){ Serial.println("RPC error call divide by zero "); @@ -103,7 +103,7 @@ void loop() { unpacker.clear(); unpacker.feed(packer.data(), packer.size()); out_packer.clear(); - wrapped_hello(unpacker, out_packer); + (*wrapped_hello)(unpacker, out_packer); for (size_t i=0; i(f))); - WrapperT* instance = new WrapperT(wrap(std::forward(f))); - _entries[_count++] = {name, tag, instance}; + _entries[_count++] = {name, tag, wrap(std::forward(f))}; return true; } diff --git a/src/wrapper.h b/src/wrapper.h index 9cda668..d2e63f0 100644 --- a/src/wrapper.h +++ b/src/wrapper.h @@ -10,16 +10,15 @@ using namespace RpcUtils::detail; #include #endif +class IFunctionWrapper { +public: + virtual ~IFunctionWrapper() {} + virtual bool operator()(MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) = 0; +}; template class RpcFunctionWrapper; -class IFunctionWrapper { - public: - virtual ~IFunctionWrapper() {} - virtual bool operator()(MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) = 0; - }; - template class RpcFunctionWrapper>: public IFunctionWrapper { public: @@ -100,11 +99,9 @@ class RpcFunctionWrapper>: public IFunctionWrapper { } }; - -template -auto wrap(F&& f) -> RpcFunctionWrapper::type>::function_type> { - using Signature = typename arx::function_traits::type>::function_type; - return RpcFunctionWrapper(std::forward(f)); +template::type>::function_type> +auto wrap(F&& f) -> RpcFunctionWrapper* { + return new RpcFunctionWrapper(std::forward(f)); }; #endif \ No newline at end of file