nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
mbd_os/libraries/rpc/RPCVariable.h@7:3a65ef12ba31, 2016-11-04 (annotated)
- Committer:
- nitsshukla
- Date:
- Fri Nov 04 12:06:04 2016 +0000
- Revision:
- 7:3a65ef12ba31
- Parent:
- 1:55a6170b404f
kghj;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 1:55a6170b404f | 1 | /* mbed Microcontroller Library |
nexpaq | 1:55a6170b404f | 2 | * Copyright (c) 2006-2013 ARM Limited |
nexpaq | 1:55a6170b404f | 3 | * |
nexpaq | 1:55a6170b404f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 1:55a6170b404f | 5 | * you may not use this file except in compliance with the License. |
nexpaq | 1:55a6170b404f | 6 | * You may obtain a copy of the License at |
nexpaq | 1:55a6170b404f | 7 | * |
nexpaq | 1:55a6170b404f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 1:55a6170b404f | 9 | * |
nexpaq | 1:55a6170b404f | 10 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 1:55a6170b404f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 1:55a6170b404f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 1:55a6170b404f | 13 | * See the License for the specific language governing permissions and |
nexpaq | 1:55a6170b404f | 14 | * limitations under the License. |
nexpaq | 1:55a6170b404f | 15 | */ |
nexpaq | 1:55a6170b404f | 16 | #ifndef RPCVARIABLE_H_ |
nexpaq | 1:55a6170b404f | 17 | #define RPCVARIABLE_H_ |
nexpaq | 1:55a6170b404f | 18 | |
nexpaq | 1:55a6170b404f | 19 | #include "rpc.h" |
nexpaq | 1:55a6170b404f | 20 | |
nexpaq | 1:55a6170b404f | 21 | namespace mbed { |
nexpaq | 1:55a6170b404f | 22 | |
nexpaq | 1:55a6170b404f | 23 | /** |
nexpaq | 1:55a6170b404f | 24 | *Class to read and set an attached variable using the RPC |
nexpaq | 1:55a6170b404f | 25 | * |
nexpaq | 1:55a6170b404f | 26 | */ |
nexpaq | 1:55a6170b404f | 27 | template<class T> |
nexpaq | 1:55a6170b404f | 28 | class RPCVariable: public RPC { |
nexpaq | 1:55a6170b404f | 29 | public: |
nexpaq | 1:55a6170b404f | 30 | /** |
nexpaq | 1:55a6170b404f | 31 | * Constructor |
nexpaq | 1:55a6170b404f | 32 | * |
nexpaq | 1:55a6170b404f | 33 | *@param ptr Pointer to the variable to make accessible over RPC. Any type of |
nexpaq | 1:55a6170b404f | 34 | *variable can be connected |
nexpaq | 1:55a6170b404f | 35 | *@param name The name of that this object will be over RPC |
nexpaq | 1:55a6170b404f | 36 | */ |
nexpaq | 1:55a6170b404f | 37 | template<class A> |
nexpaq | 1:55a6170b404f | 38 | RPCVariable(A * ptr, const char * name) : RPC(name) { |
nexpaq | 1:55a6170b404f | 39 | _ptr = ptr; |
nexpaq | 1:55a6170b404f | 40 | } |
nexpaq | 1:55a6170b404f | 41 | /** |
nexpaq | 1:55a6170b404f | 42 | *Read the variable over RPC. |
nexpaq | 1:55a6170b404f | 43 | * |
nexpaq | 1:55a6170b404f | 44 | *@return The value of the variable |
nexpaq | 1:55a6170b404f | 45 | */ |
nexpaq | 1:55a6170b404f | 46 | T read() { |
nexpaq | 1:55a6170b404f | 47 | return (*_ptr); |
nexpaq | 1:55a6170b404f | 48 | } |
nexpaq | 1:55a6170b404f | 49 | /** |
nexpaq | 1:55a6170b404f | 50 | *Write a value to the variable over RPC |
nexpaq | 1:55a6170b404f | 51 | * |
nexpaq | 1:55a6170b404f | 52 | *@param The value to be written to the attached variable. |
nexpaq | 1:55a6170b404f | 53 | */ |
nexpaq | 1:55a6170b404f | 54 | void write(T value) { |
nexpaq | 1:55a6170b404f | 55 | *_ptr = value; |
nexpaq | 1:55a6170b404f | 56 | } |
nexpaq | 1:55a6170b404f | 57 | |
nexpaq | 1:55a6170b404f | 58 | virtual const struct rpc_method *get_rpc_methods(); |
nexpaq | 1:55a6170b404f | 59 | static struct rpc_class *get_rpc_class(); |
nexpaq | 1:55a6170b404f | 60 | |
nexpaq | 1:55a6170b404f | 61 | private: |
nexpaq | 1:55a6170b404f | 62 | T * _ptr; |
nexpaq | 1:55a6170b404f | 63 | }; |
nexpaq | 1:55a6170b404f | 64 | |
nexpaq | 1:55a6170b404f | 65 | template<class T> |
nexpaq | 1:55a6170b404f | 66 | const rpc_method *RPCVariable<T>::get_rpc_methods() { |
nexpaq | 1:55a6170b404f | 67 | static const rpc_method rpc_methods[] = { |
nexpaq | 1:55a6170b404f | 68 | {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> }, |
nexpaq | 1:55a6170b404f | 69 | {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> }, |
nexpaq | 1:55a6170b404f | 70 | RPC_METHOD_SUPER(RPC) |
nexpaq | 1:55a6170b404f | 71 | }; |
nexpaq | 1:55a6170b404f | 72 | return rpc_methods; |
nexpaq | 1:55a6170b404f | 73 | } |
nexpaq | 1:55a6170b404f | 74 | |
nexpaq | 1:55a6170b404f | 75 | template<class T> |
nexpaq | 1:55a6170b404f | 76 | rpc_class *RPCVariable<T>::get_rpc_class() { |
nexpaq | 1:55a6170b404f | 77 | static const rpc_function funcs[] = { |
nexpaq | 1:55a6170b404f | 78 | "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > , |
nexpaq | 1:55a6170b404f | 79 | RPC_METHOD_END |
nexpaq | 1:55a6170b404f | 80 | }; |
nexpaq | 1:55a6170b404f | 81 | static rpc_class c = {"RPCVariable", funcs, NULL}; |
nexpaq | 1:55a6170b404f | 82 | return &c; |
nexpaq | 1:55a6170b404f | 83 | } |
nexpaq | 1:55a6170b404f | 84 | |
nexpaq | 1:55a6170b404f | 85 | } |
nexpaq | 1:55a6170b404f | 86 | |
nexpaq | 1:55a6170b404f | 87 | #endif //RPCVARIABLE_H_ |