Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/features/unsupported/rpc/rpc.h@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* mbed Microcontroller Library |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2006-2013 ARM Limited |
marcozecchini | 0:9fca2b23d0ba | 3 | * |
marcozecchini | 0:9fca2b23d0ba | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
marcozecchini | 0:9fca2b23d0ba | 5 | * you may not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 6 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 7 | * |
marcozecchini | 0:9fca2b23d0ba | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 9 | * |
marcozecchini | 0:9fca2b23d0ba | 10 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
marcozecchini | 0:9fca2b23d0ba | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 13 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 14 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 15 | */ |
marcozecchini | 0:9fca2b23d0ba | 16 | #ifndef RPC_H |
marcozecchini | 0:9fca2b23d0ba | 17 | #define RPC_H |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | #include "mbed.h" |
marcozecchini | 0:9fca2b23d0ba | 20 | #include "Arguments.h" |
marcozecchini | 0:9fca2b23d0ba | 21 | |
marcozecchini | 0:9fca2b23d0ba | 22 | namespace mbed { |
marcozecchini | 0:9fca2b23d0ba | 23 | |
marcozecchini | 0:9fca2b23d0ba | 24 | #define RPC_MAX_STRING 128 |
marcozecchini | 0:9fca2b23d0ba | 25 | |
marcozecchini | 0:9fca2b23d0ba | 26 | struct rpc_function { |
marcozecchini | 0:9fca2b23d0ba | 27 | const char *name; |
marcozecchini | 0:9fca2b23d0ba | 28 | void (*function_caller)(Arguments*, Reply*); |
marcozecchini | 0:9fca2b23d0ba | 29 | }; |
marcozecchini | 0:9fca2b23d0ba | 30 | |
marcozecchini | 0:9fca2b23d0ba | 31 | struct rpc_class { |
marcozecchini | 0:9fca2b23d0ba | 32 | const char *name; |
marcozecchini | 0:9fca2b23d0ba | 33 | const rpc_function *static_functions; |
marcozecchini | 0:9fca2b23d0ba | 34 | struct rpc_class *next; |
marcozecchini | 0:9fca2b23d0ba | 35 | }; |
marcozecchini | 0:9fca2b23d0ba | 36 | |
marcozecchini | 0:9fca2b23d0ba | 37 | /* Class RPC |
marcozecchini | 0:9fca2b23d0ba | 38 | * The RPC class for most things |
marcozecchini | 0:9fca2b23d0ba | 39 | */ |
marcozecchini | 0:9fca2b23d0ba | 40 | class RPC { |
marcozecchini | 0:9fca2b23d0ba | 41 | |
marcozecchini | 0:9fca2b23d0ba | 42 | public: |
marcozecchini | 0:9fca2b23d0ba | 43 | |
marcozecchini | 0:9fca2b23d0ba | 44 | RPC(const char *name = NULL); |
marcozecchini | 0:9fca2b23d0ba | 45 | |
marcozecchini | 0:9fca2b23d0ba | 46 | virtual ~RPC(); |
marcozecchini | 0:9fca2b23d0ba | 47 | |
marcozecchini | 0:9fca2b23d0ba | 48 | /* Function get_rpc_methods |
marcozecchini | 0:9fca2b23d0ba | 49 | * Returns a pointer to an array describing the rpc methods |
marcozecchini | 0:9fca2b23d0ba | 50 | * supported by this object, terminated by either |
marcozecchini | 0:9fca2b23d0ba | 51 | * RPC_METHOD_END or RPC_METHOD_SUPER(Superclass). |
marcozecchini | 0:9fca2b23d0ba | 52 | * |
marcozecchini | 0:9fca2b23d0ba | 53 | * Example |
marcozecchini | 0:9fca2b23d0ba | 54 | * > class Example : public RPC { |
marcozecchini | 0:9fca2b23d0ba | 55 | * > int foo(int a, int b) { return a + b; } |
marcozecchini | 0:9fca2b23d0ba | 56 | * > virtual const struct rpc_method *get_rpc_methods() { |
marcozecchini | 0:9fca2b23d0ba | 57 | * > static const rpc_method rpc_methods[] = { |
marcozecchini | 0:9fca2b23d0ba | 58 | * > { "foo", generic_caller<int, Example, int, int, &Example::foo> }, |
marcozecchini | 0:9fca2b23d0ba | 59 | * > RPC_METHOD_SUPER(RPC) |
marcozecchini | 0:9fca2b23d0ba | 60 | * > }; |
marcozecchini | 0:9fca2b23d0ba | 61 | * > return rpc_methods; |
marcozecchini | 0:9fca2b23d0ba | 62 | * > } |
marcozecchini | 0:9fca2b23d0ba | 63 | * > }; |
marcozecchini | 0:9fca2b23d0ba | 64 | */ |
marcozecchini | 0:9fca2b23d0ba | 65 | virtual const struct rpc_method *get_rpc_methods(); |
marcozecchini | 0:9fca2b23d0ba | 66 | |
marcozecchini | 0:9fca2b23d0ba | 67 | static bool call(const char *buf, char *result); |
marcozecchini | 0:9fca2b23d0ba | 68 | |
marcozecchini | 0:9fca2b23d0ba | 69 | /* Function lookup |
marcozecchini | 0:9fca2b23d0ba | 70 | * Lookup and return the object that has the given name. |
marcozecchini | 0:9fca2b23d0ba | 71 | * |
marcozecchini | 0:9fca2b23d0ba | 72 | * Variables |
marcozecchini | 0:9fca2b23d0ba | 73 | * name - the name to lookup. |
marcozecchini | 0:9fca2b23d0ba | 74 | */ |
marcozecchini | 0:9fca2b23d0ba | 75 | static RPC *lookup(const char *name); |
marcozecchini | 0:9fca2b23d0ba | 76 | |
marcozecchini | 0:9fca2b23d0ba | 77 | protected: |
marcozecchini | 0:9fca2b23d0ba | 78 | static RPC *_head; |
marcozecchini | 0:9fca2b23d0ba | 79 | RPC *_next; |
marcozecchini | 0:9fca2b23d0ba | 80 | char *_name; |
marcozecchini | 0:9fca2b23d0ba | 81 | bool _from_construct; |
marcozecchini | 0:9fca2b23d0ba | 82 | |
marcozecchini | 0:9fca2b23d0ba | 83 | private: |
marcozecchini | 0:9fca2b23d0ba | 84 | static rpc_class *_classes; |
marcozecchini | 0:9fca2b23d0ba | 85 | |
marcozecchini | 0:9fca2b23d0ba | 86 | static const rpc_function _RPC_funcs[]; |
marcozecchini | 0:9fca2b23d0ba | 87 | static rpc_class _RPC_class; |
marcozecchini | 0:9fca2b23d0ba | 88 | |
marcozecchini | 0:9fca2b23d0ba | 89 | void delete_self(); |
marcozecchini | 0:9fca2b23d0ba | 90 | static void list_objs(Arguments *args, Reply *result); |
marcozecchini | 0:9fca2b23d0ba | 91 | static void clear(Arguments *args, Reply *result); |
marcozecchini | 0:9fca2b23d0ba | 92 | |
marcozecchini | 0:9fca2b23d0ba | 93 | public: |
marcozecchini | 0:9fca2b23d0ba | 94 | /* Function add_rpc_class |
marcozecchini | 0:9fca2b23d0ba | 95 | * Add the class to the list of classes which can have static |
marcozecchini | 0:9fca2b23d0ba | 96 | * methods called via rpc (the static methods which can be called |
marcozecchini | 0:9fca2b23d0ba | 97 | * are defined by that class' get_rpc_class() static method). |
marcozecchini | 0:9fca2b23d0ba | 98 | */ |
marcozecchini | 0:9fca2b23d0ba | 99 | template<class C> |
marcozecchini | 0:9fca2b23d0ba | 100 | static void add_rpc_class() { |
marcozecchini | 0:9fca2b23d0ba | 101 | rpc_class *c = C::get_rpc_class(); |
marcozecchini | 0:9fca2b23d0ba | 102 | c->next = _classes; |
marcozecchini | 0:9fca2b23d0ba | 103 | _classes = c; |
marcozecchini | 0:9fca2b23d0ba | 104 | } |
marcozecchini | 0:9fca2b23d0ba | 105 | |
marcozecchini | 0:9fca2b23d0ba | 106 | template<class C> |
marcozecchini | 0:9fca2b23d0ba | 107 | static const char *construct() { |
marcozecchini | 0:9fca2b23d0ba | 108 | RPC *p = new C(); |
marcozecchini | 0:9fca2b23d0ba | 109 | p->_from_construct = true; |
marcozecchini | 0:9fca2b23d0ba | 110 | return p->_name; |
marcozecchini | 0:9fca2b23d0ba | 111 | } |
marcozecchini | 0:9fca2b23d0ba | 112 | |
marcozecchini | 0:9fca2b23d0ba | 113 | template<class C, typename A1> |
marcozecchini | 0:9fca2b23d0ba | 114 | static const char *construct(A1 arg1) { |
marcozecchini | 0:9fca2b23d0ba | 115 | RPC *p = new C(arg1); |
marcozecchini | 0:9fca2b23d0ba | 116 | p->_from_construct = true; |
marcozecchini | 0:9fca2b23d0ba | 117 | return p->_name; |
marcozecchini | 0:9fca2b23d0ba | 118 | } |
marcozecchini | 0:9fca2b23d0ba | 119 | |
marcozecchini | 0:9fca2b23d0ba | 120 | template<class C, typename A1, typename A2> |
marcozecchini | 0:9fca2b23d0ba | 121 | static const char *construct(A1 arg1, A2 arg2) { |
marcozecchini | 0:9fca2b23d0ba | 122 | RPC *p = new C(arg1, arg2); |
marcozecchini | 0:9fca2b23d0ba | 123 | p->_from_construct = true; |
marcozecchini | 0:9fca2b23d0ba | 124 | return p->_name; |
marcozecchini | 0:9fca2b23d0ba | 125 | } |
marcozecchini | 0:9fca2b23d0ba | 126 | |
marcozecchini | 0:9fca2b23d0ba | 127 | template<class C, typename A1, typename A2, typename A3> |
marcozecchini | 0:9fca2b23d0ba | 128 | static const char *construct(A1 arg1, A2 arg2, A3 arg3) { |
marcozecchini | 0:9fca2b23d0ba | 129 | RPC *p = new C(arg1, arg2, arg3); |
marcozecchini | 0:9fca2b23d0ba | 130 | p->_from_construct = true; |
marcozecchini | 0:9fca2b23d0ba | 131 | return p->_name; |
marcozecchini | 0:9fca2b23d0ba | 132 | } |
marcozecchini | 0:9fca2b23d0ba | 133 | |
marcozecchini | 0:9fca2b23d0ba | 134 | template<class C, typename A1, typename A2, typename A3, typename A4> |
marcozecchini | 0:9fca2b23d0ba | 135 | static const char *construct(A1 arg1, A2 arg2, A3 arg3, A4 arg4) { |
marcozecchini | 0:9fca2b23d0ba | 136 | RPC *p = new C(arg1, arg2, arg3, arg4); |
marcozecchini | 0:9fca2b23d0ba | 137 | p->_from_construct = true; |
marcozecchini | 0:9fca2b23d0ba | 138 | return p->_name; |
marcozecchini | 0:9fca2b23d0ba | 139 | } |
marcozecchini | 0:9fca2b23d0ba | 140 | }; |
marcozecchini | 0:9fca2b23d0ba | 141 | |
marcozecchini | 0:9fca2b23d0ba | 142 | /* Macro MBED_OBJECT_NAME_MAX |
marcozecchini | 0:9fca2b23d0ba | 143 | * The maximum size of object name (including terminating null byte) |
marcozecchini | 0:9fca2b23d0ba | 144 | * that will be recognised when using fopen to open a FileLike |
marcozecchini | 0:9fca2b23d0ba | 145 | * object, or when using the rpc function. |
marcozecchini | 0:9fca2b23d0ba | 146 | */ |
marcozecchini | 0:9fca2b23d0ba | 147 | #define MBED_OBJECT_NAME_MAX 32 |
marcozecchini | 0:9fca2b23d0ba | 148 | |
marcozecchini | 0:9fca2b23d0ba | 149 | /* Macro MBED_METHOD_NAME_MAX |
marcozecchini | 0:9fca2b23d0ba | 150 | * The maximum size of rpc method name (including terminating null |
marcozecchini | 0:9fca2b23d0ba | 151 | * byte) that will be recognised by the rpc function (in rpc.h). |
marcozecchini | 0:9fca2b23d0ba | 152 | */ |
marcozecchini | 0:9fca2b23d0ba | 153 | #define MBED_METHOD_NAME_MAX 32 |
marcozecchini | 0:9fca2b23d0ba | 154 | |
marcozecchini | 0:9fca2b23d0ba | 155 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 156 | */ |
marcozecchini | 0:9fca2b23d0ba | 157 | template<class T, void(T::*member)(const char *, char *)> |
marcozecchini | 0:9fca2b23d0ba | 158 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 159 | (static_cast<T*>(this_ptr)->*member)(arguments, result); |
marcozecchini | 0:9fca2b23d0ba | 160 | } |
marcozecchini | 0:9fca2b23d0ba | 161 | |
marcozecchini | 0:9fca2b23d0ba | 162 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 163 | */ |
marcozecchini | 0:9fca2b23d0ba | 164 | template<class T, void(T::*member)()> |
marcozecchini | 0:9fca2b23d0ba | 165 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 166 | (static_cast<T*>(this_ptr)->*member)(); |
marcozecchini | 0:9fca2b23d0ba | 167 | } |
marcozecchini | 0:9fca2b23d0ba | 168 | |
marcozecchini | 0:9fca2b23d0ba | 169 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 170 | */ |
marcozecchini | 0:9fca2b23d0ba | 171 | template<class T, typename A1, void(T::*member)(A1)> |
marcozecchini | 0:9fca2b23d0ba | 172 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 173 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 174 | |
marcozecchini | 0:9fca2b23d0ba | 175 | (static_cast<T*>(this_ptr)->*member)(arg1); |
marcozecchini | 0:9fca2b23d0ba | 176 | } |
marcozecchini | 0:9fca2b23d0ba | 177 | |
marcozecchini | 0:9fca2b23d0ba | 178 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 179 | */ |
marcozecchini | 0:9fca2b23d0ba | 180 | template<class T, typename A1, typename A2, void(T::*member)(A1, A2)> |
marcozecchini | 0:9fca2b23d0ba | 181 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 182 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 183 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 184 | |
marcozecchini | 0:9fca2b23d0ba | 185 | (static_cast<T*>(this_ptr)->*member)(arg1, arg2); |
marcozecchini | 0:9fca2b23d0ba | 186 | } |
marcozecchini | 0:9fca2b23d0ba | 187 | |
marcozecchini | 0:9fca2b23d0ba | 188 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 189 | */ |
marcozecchini | 0:9fca2b23d0ba | 190 | template<class T, typename A1, typename A2, typename A3, void(T::*member)(A1, A2, A3)> |
marcozecchini | 0:9fca2b23d0ba | 191 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 192 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 193 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 194 | A3 arg3 = arguments->getArg<A3>(); |
marcozecchini | 0:9fca2b23d0ba | 195 | |
marcozecchini | 0:9fca2b23d0ba | 196 | (static_cast<T*>(this_ptr)->*member)(arg1, arg2, arg3); |
marcozecchini | 0:9fca2b23d0ba | 197 | } |
marcozecchini | 0:9fca2b23d0ba | 198 | |
marcozecchini | 0:9fca2b23d0ba | 199 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 200 | */ |
marcozecchini | 0:9fca2b23d0ba | 201 | template<typename R, class T, R(T::*member)()> |
marcozecchini | 0:9fca2b23d0ba | 202 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 203 | R res = (static_cast<T*>(this_ptr)->*member)(); |
marcozecchini | 0:9fca2b23d0ba | 204 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 205 | } |
marcozecchini | 0:9fca2b23d0ba | 206 | |
marcozecchini | 0:9fca2b23d0ba | 207 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 208 | */ |
marcozecchini | 0:9fca2b23d0ba | 209 | template<typename R, class T, typename A1, R(T::*member)(A1)> |
marcozecchini | 0:9fca2b23d0ba | 210 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 211 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 212 | |
marcozecchini | 0:9fca2b23d0ba | 213 | R res = (static_cast<T*>(this_ptr)->*member)(arg1); |
marcozecchini | 0:9fca2b23d0ba | 214 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 215 | } |
marcozecchini | 0:9fca2b23d0ba | 216 | |
marcozecchini | 0:9fca2b23d0ba | 217 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 218 | */ |
marcozecchini | 0:9fca2b23d0ba | 219 | template<typename R, class T, typename A1, typename A2, R(T::*member)(A1, A2)> |
marcozecchini | 0:9fca2b23d0ba | 220 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 221 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 222 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 223 | |
marcozecchini | 0:9fca2b23d0ba | 224 | R res = (static_cast<T*>(this_ptr)->*member)(arg1, arg2); |
marcozecchini | 0:9fca2b23d0ba | 225 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 226 | } |
marcozecchini | 0:9fca2b23d0ba | 227 | |
marcozecchini | 0:9fca2b23d0ba | 228 | /* Function rpc_method_caller |
marcozecchini | 0:9fca2b23d0ba | 229 | */ |
marcozecchini | 0:9fca2b23d0ba | 230 | template<typename R, class T, typename A1, typename A2, typename A3, R(T::*member)(A1, A2, A3)> |
marcozecchini | 0:9fca2b23d0ba | 231 | void rpc_method_caller(RPC *this_ptr, Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 232 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 233 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 234 | A3 arg3 = arguments->getArg<A3>(); |
marcozecchini | 0:9fca2b23d0ba | 235 | |
marcozecchini | 0:9fca2b23d0ba | 236 | R res = (static_cast<T*>(this_ptr)->*member)(arg1, arg2, arg3); |
marcozecchini | 0:9fca2b23d0ba | 237 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 238 | } |
marcozecchini | 0:9fca2b23d0ba | 239 | |
marcozecchini | 0:9fca2b23d0ba | 240 | /* Function rpc_function caller |
marcozecchini | 0:9fca2b23d0ba | 241 | */ |
marcozecchini | 0:9fca2b23d0ba | 242 | template<typename R, R(*func)()> |
marcozecchini | 0:9fca2b23d0ba | 243 | void rpc_function_caller(Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 244 | R res = (*func)(); |
marcozecchini | 0:9fca2b23d0ba | 245 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 246 | } |
marcozecchini | 0:9fca2b23d0ba | 247 | |
marcozecchini | 0:9fca2b23d0ba | 248 | /* Function rpc_function caller |
marcozecchini | 0:9fca2b23d0ba | 249 | */ |
marcozecchini | 0:9fca2b23d0ba | 250 | template<typename R, typename A1, R(*func)(A1)> |
marcozecchini | 0:9fca2b23d0ba | 251 | void rpc_function_caller(Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 252 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 253 | R res = (*func)(arg1); |
marcozecchini | 0:9fca2b23d0ba | 254 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 255 | } |
marcozecchini | 0:9fca2b23d0ba | 256 | |
marcozecchini | 0:9fca2b23d0ba | 257 | /* Function rpc_function caller |
marcozecchini | 0:9fca2b23d0ba | 258 | */ |
marcozecchini | 0:9fca2b23d0ba | 259 | template<typename R, typename A1, typename A2, R(*func)(A1, A2)> |
marcozecchini | 0:9fca2b23d0ba | 260 | void rpc_function_caller(Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 261 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 262 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 263 | |
marcozecchini | 0:9fca2b23d0ba | 264 | R res = (*func)(arg1, arg2); |
marcozecchini | 0:9fca2b23d0ba | 265 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 266 | } |
marcozecchini | 0:9fca2b23d0ba | 267 | |
marcozecchini | 0:9fca2b23d0ba | 268 | /* Function rpc_function caller |
marcozecchini | 0:9fca2b23d0ba | 269 | */ |
marcozecchini | 0:9fca2b23d0ba | 270 | template<typename R, typename A1, typename A2, typename A3, R(*func)(A1, A2, A3)> |
marcozecchini | 0:9fca2b23d0ba | 271 | void rpc_function_caller(Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 272 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 273 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 274 | A3 arg3 = arguments->getArg<A3>(); |
marcozecchini | 0:9fca2b23d0ba | 275 | |
marcozecchini | 0:9fca2b23d0ba | 276 | R res = (*func)(arg1, arg2, arg3); |
marcozecchini | 0:9fca2b23d0ba | 277 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 278 | } |
marcozecchini | 0:9fca2b23d0ba | 279 | |
marcozecchini | 0:9fca2b23d0ba | 280 | /* Function rpc_function caller |
marcozecchini | 0:9fca2b23d0ba | 281 | */ |
marcozecchini | 0:9fca2b23d0ba | 282 | template<typename R, typename A1, typename A2, typename A3, typename A4, R(*func)(A1, A2, A3, A4)> |
marcozecchini | 0:9fca2b23d0ba | 283 | void rpc_function_caller(Arguments *arguments, Reply *result) { |
marcozecchini | 0:9fca2b23d0ba | 284 | A1 arg1 = arguments->getArg<A1>(); |
marcozecchini | 0:9fca2b23d0ba | 285 | A2 arg2 = arguments->getArg<A2>(); |
marcozecchini | 0:9fca2b23d0ba | 286 | A3 arg3 = arguments->getArg<A3>(); |
marcozecchini | 0:9fca2b23d0ba | 287 | A4 arg4 = arguments->getArg<A4>(); |
marcozecchini | 0:9fca2b23d0ba | 288 | |
marcozecchini | 0:9fca2b23d0ba | 289 | R res = (*func)(arg1, arg2, arg3, arg4); |
marcozecchini | 0:9fca2b23d0ba | 290 | result->putData<R>(res); |
marcozecchini | 0:9fca2b23d0ba | 291 | } |
marcozecchini | 0:9fca2b23d0ba | 292 | |
marcozecchini | 0:9fca2b23d0ba | 293 | struct rpc_method { |
marcozecchini | 0:9fca2b23d0ba | 294 | const char *name; |
marcozecchini | 0:9fca2b23d0ba | 295 | typedef void (*method_caller_t)(RPC*, Arguments*, Reply*); |
marcozecchini | 0:9fca2b23d0ba | 296 | typedef const struct rpc_method *(*super_t)(RPC*); |
marcozecchini | 0:9fca2b23d0ba | 297 | union { |
marcozecchini | 0:9fca2b23d0ba | 298 | method_caller_t method_caller; |
marcozecchini | 0:9fca2b23d0ba | 299 | super_t super; |
marcozecchini | 0:9fca2b23d0ba | 300 | }; |
marcozecchini | 0:9fca2b23d0ba | 301 | }; |
marcozecchini | 0:9fca2b23d0ba | 302 | |
marcozecchini | 0:9fca2b23d0ba | 303 | template<class C> |
marcozecchini | 0:9fca2b23d0ba | 304 | const struct rpc_method *rpc_super(RPC *this_ptr) { |
marcozecchini | 0:9fca2b23d0ba | 305 | return static_cast<C*>(this_ptr)->C::get_rpc_methods(); |
marcozecchini | 0:9fca2b23d0ba | 306 | } |
marcozecchini | 0:9fca2b23d0ba | 307 | |
marcozecchini | 0:9fca2b23d0ba | 308 | #define RPC_METHOD_END { NULL, NULL } |
marcozecchini | 0:9fca2b23d0ba | 309 | #define RPC_METHOD_SUPER(C) { NULL, (rpc_method::method_caller_t)rpc_super<C> } |
marcozecchini | 0:9fca2b23d0ba | 310 | |
marcozecchini | 0:9fca2b23d0ba | 311 | } // namespace mbed |
marcozecchini | 0:9fca2b23d0ba | 312 | |
marcozecchini | 0:9fca2b23d0ba | 313 | #endif |