Skip to content

Commit c3321fd

Browse files
committed
Auto-detect RpcFunctionWrapper type using std::function guides (c++17)
1 parent 14b7580 commit c3321fd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/wrapper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ using namespace RpcUtils::detail;
2020
#ifdef HANDLE_RPC_ERRORS
2121
#include <stdexcept>
2222
#endif
23+
#ifdef ARDUINO_ARCH_ZEPHYR
24+
#include <functional>
25+
#endif
2326

2427
class IFunctionWrapper {
2528
public:
2629
virtual ~IFunctionWrapper() {}
2730
virtual bool operator()(MsgPack::Unpacker& unpacker, MsgPack::Packer& packer) = 0;
2831
};
2932

33+
#ifdef ARDUINO_ARCH_ZEPHYR
34+
class RpcFunctionWrapper: public IFunctionWrapper {
35+
#else
3036
template<typename F>
3137
class RpcFunctionWrapper;
3238

3339
template<typename R, typename... Args>
3440
class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
41+
#endif
3542
public:
3643
RpcFunctionWrapper(std::function<R(Args...)> func) : _func(func) {}
3744

@@ -110,9 +117,16 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
110117
}
111118
};
112119

120+
#ifdef ARDUINO_ARCH_ZEPHYR
121+
template<typename F>
122+
auto wrap(F&& f) {
123+
return new RpcFunctionWrapper(std::function(std::forward<F>(f)));
124+
};
125+
#else
113126
template<typename F, typename Signature = typename arx::function_traits<typename std::decay<F>::type>::function_type>
114127
auto wrap(F&& f) -> RpcFunctionWrapper<Signature>* {
115128
return new RpcFunctionWrapper<Signature>(std::forward<F>(f));
116129
};
130+
#endif
117131

118132
#endif

0 commit comments

Comments
 (0)