Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/features/unsupported/rpc/RPCVariable.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 RPCVARIABLE_H_ |
marcozecchini | 0:9fca2b23d0ba | 17 | #define RPCVARIABLE_H_ |
marcozecchini | 0:9fca2b23d0ba | 18 | |
marcozecchini | 0:9fca2b23d0ba | 19 | #include "rpc.h" |
marcozecchini | 0:9fca2b23d0ba | 20 | |
marcozecchini | 0:9fca2b23d0ba | 21 | namespace mbed { |
marcozecchini | 0:9fca2b23d0ba | 22 | |
marcozecchini | 0:9fca2b23d0ba | 23 | /** |
marcozecchini | 0:9fca2b23d0ba | 24 | *Class to read and set an attached variable using the RPC |
marcozecchini | 0:9fca2b23d0ba | 25 | * |
marcozecchini | 0:9fca2b23d0ba | 26 | */ |
marcozecchini | 0:9fca2b23d0ba | 27 | template<class T> |
marcozecchini | 0:9fca2b23d0ba | 28 | class RPCVariable: public RPC { |
marcozecchini | 0:9fca2b23d0ba | 29 | public: |
marcozecchini | 0:9fca2b23d0ba | 30 | /** |
marcozecchini | 0:9fca2b23d0ba | 31 | * Constructor |
marcozecchini | 0:9fca2b23d0ba | 32 | * |
marcozecchini | 0:9fca2b23d0ba | 33 | *@param ptr Pointer to the variable to make accessible over RPC. Any type of |
marcozecchini | 0:9fca2b23d0ba | 34 | *variable can be connected |
marcozecchini | 0:9fca2b23d0ba | 35 | *@param name The name of that this object will be over RPC |
marcozecchini | 0:9fca2b23d0ba | 36 | */ |
marcozecchini | 0:9fca2b23d0ba | 37 | template<class A> |
marcozecchini | 0:9fca2b23d0ba | 38 | RPCVariable(A * ptr, const char * name) : RPC(name) { |
marcozecchini | 0:9fca2b23d0ba | 39 | _ptr = ptr; |
marcozecchini | 0:9fca2b23d0ba | 40 | } |
marcozecchini | 0:9fca2b23d0ba | 41 | /** |
marcozecchini | 0:9fca2b23d0ba | 42 | *Read the variable over RPC. |
marcozecchini | 0:9fca2b23d0ba | 43 | * |
marcozecchini | 0:9fca2b23d0ba | 44 | *@return The value of the variable |
marcozecchini | 0:9fca2b23d0ba | 45 | */ |
marcozecchini | 0:9fca2b23d0ba | 46 | T read() { |
marcozecchini | 0:9fca2b23d0ba | 47 | return (*_ptr); |
marcozecchini | 0:9fca2b23d0ba | 48 | } |
marcozecchini | 0:9fca2b23d0ba | 49 | /** |
marcozecchini | 0:9fca2b23d0ba | 50 | *Write a value to the variable over RPC |
marcozecchini | 0:9fca2b23d0ba | 51 | * |
marcozecchini | 0:9fca2b23d0ba | 52 | *@param The value to be written to the attached variable. |
marcozecchini | 0:9fca2b23d0ba | 53 | */ |
marcozecchini | 0:9fca2b23d0ba | 54 | void write(T value) { |
marcozecchini | 0:9fca2b23d0ba | 55 | *_ptr = value; |
marcozecchini | 0:9fca2b23d0ba | 56 | } |
marcozecchini | 0:9fca2b23d0ba | 57 | |
marcozecchini | 0:9fca2b23d0ba | 58 | virtual const struct rpc_method *get_rpc_methods(); |
marcozecchini | 0:9fca2b23d0ba | 59 | static struct rpc_class *get_rpc_class(); |
marcozecchini | 0:9fca2b23d0ba | 60 | |
marcozecchini | 0:9fca2b23d0ba | 61 | private: |
marcozecchini | 0:9fca2b23d0ba | 62 | T * _ptr; |
marcozecchini | 0:9fca2b23d0ba | 63 | }; |
marcozecchini | 0:9fca2b23d0ba | 64 | |
marcozecchini | 0:9fca2b23d0ba | 65 | template<class T> |
marcozecchini | 0:9fca2b23d0ba | 66 | const rpc_method *RPCVariable<T>::get_rpc_methods() { |
marcozecchini | 0:9fca2b23d0ba | 67 | static const rpc_method rpc_methods[] = { |
marcozecchini | 0:9fca2b23d0ba | 68 | {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> }, |
marcozecchini | 0:9fca2b23d0ba | 69 | {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> }, |
marcozecchini | 0:9fca2b23d0ba | 70 | RPC_METHOD_SUPER(RPC) |
marcozecchini | 0:9fca2b23d0ba | 71 | }; |
marcozecchini | 0:9fca2b23d0ba | 72 | return rpc_methods; |
marcozecchini | 0:9fca2b23d0ba | 73 | } |
marcozecchini | 0:9fca2b23d0ba | 74 | |
marcozecchini | 0:9fca2b23d0ba | 75 | template<class T> |
marcozecchini | 0:9fca2b23d0ba | 76 | rpc_class *RPCVariable<T>::get_rpc_class() { |
marcozecchini | 0:9fca2b23d0ba | 77 | static const rpc_function funcs[] = { |
marcozecchini | 0:9fca2b23d0ba | 78 | "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > , |
marcozecchini | 0:9fca2b23d0ba | 79 | RPC_METHOD_END |
marcozecchini | 0:9fca2b23d0ba | 80 | }; |
marcozecchini | 0:9fca2b23d0ba | 81 | static rpc_class c = {"RPCVariable", funcs, NULL}; |
marcozecchini | 0:9fca2b23d0ba | 82 | return &c; |
marcozecchini | 0:9fca2b23d0ba | 83 | } |
marcozecchini | 0:9fca2b23d0ba | 84 | |
marcozecchini | 0:9fca2b23d0ba | 85 | } |
marcozecchini | 0:9fca2b23d0ba | 86 | |
marcozecchini | 0:9fca2b23d0ba | 87 | #endif //RPCVARIABLE_H_ |