Skip to content

Commit e5b575f

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

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/wrapper.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,26 @@ 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+
template<typename R, typename... Args>
35+
class RpcFunctionWrapper: public IFunctionWrapper {
36+
#else
3037
template<typename F>
3138
class RpcFunctionWrapper;
3239

3340
template<typename R, typename... Args>
3441
class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
42+
#endif
3543
public:
3644
RpcFunctionWrapper(std::function<R(Args...)> func) : _func(func) {}
3745

@@ -110,9 +118,16 @@ class RpcFunctionWrapper<std::function<R(Args...)>>: public IFunctionWrapper {
110118
}
111119
};
112120

121+
#ifdef ARDUINO_ARCH_ZEPHYR
122+
template<typename F>
123+
auto wrap(F&& f) {
124+
return new RpcFunctionWrapper(std::function(std::forward<F>(f)));
125+
};
126+
#else
113127
template<typename F, typename Signature = typename arx::function_traits<typename std::decay<F>::type>::function_type>
114128
auto wrap(F&& f) -> RpcFunctionWrapper<Signature>* {
115129
return new RpcFunctionWrapper<Signature>(std::forward<F>(f));
116130
};
131+
#endif
117132

118133
#endif

0 commit comments

Comments
 (0)