From 1592a021166b9d3d094a19a0ccd19fb81c8290d7 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 23 Jul 2025 11:39:00 +0200 Subject: [PATCH 1/3] Create the RPC function wrapper directly in wrap. This allows a simplified usage in dispatcher. Possibly an IFunctionWrapper* may be directly returned in future refactorings. --- examples/wrapper_example/wrapper_example.ino | 8 ++++---- src/dispatcher.h | 4 +--- src/wrapper.h | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) 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..5f1e436 100644 --- a/src/wrapper.h +++ b/src/wrapper.h @@ -100,11 +100,10 @@ class RpcFunctionWrapper>: public IFunctionWrapper { } }; - template -auto wrap(F&& f) -> RpcFunctionWrapper::type>::function_type> { +auto wrap(F&& f) -> RpcFunctionWrapper::type>::function_type>* { using Signature = typename arx::function_traits::type>::function_type; - return RpcFunctionWrapper(std::forward(f)); + return new RpcFunctionWrapper(std::forward(f)); }; #endif \ No newline at end of file From 17b330261831639e67e2c7865fa97c769b401a1b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 23 Jul 2025 15:31:07 +0200 Subject: [PATCH 2/3] Declare deducted type inside template construct --- src/wrapper.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wrapper.h b/src/wrapper.h index 5f1e436..ef314e3 100644 --- a/src/wrapper.h +++ b/src/wrapper.h @@ -100,9 +100,8 @@ class RpcFunctionWrapper>: public IFunctionWrapper { } }; -template -auto wrap(F&& f) -> RpcFunctionWrapper::type>::function_type>* { - using Signature = typename arx::function_traits::type>::function_type; +template::type>::function_type> +auto wrap(F&& f) -> RpcFunctionWrapper* { return new RpcFunctionWrapper(std::forward(f)); }; From 453e5e4e9c7d92d4d06fbd9263d4ee02edc258c8 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Wed, 23 Jul 2025 16:41:35 +0200 Subject: [PATCH 3/3] Adjust indent and move class definition closer for better readability --- src/wrapper.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/wrapper.h b/src/wrapper.h index ef314e3..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: