RTOS Support.
Dependents: SerialRPC_rtos_example
Fork of RPCInterface by
RPCVariable.h@5:56fd0b265aba, 2010-11-27 (annotated)
- Committer:
- MichaelW
- Date:
- Sat Nov 27 21:00:02 2010 +0000
- Revision:
- 5:56fd0b265aba
- Parent:
- 4:05f0d66bee57
- Child:
- 6:f15d3610ddbe
Updated Includes to include necessary includes in RPCVariable.h and RPCFunction.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 5:56fd0b265aba | 1 | /** |
MichaelW | 5:56fd0b265aba | 2 | * @section LICENSE |
MichaelW | 5:56fd0b265aba | 3 | *Copyright (c) 2010 ARM Ltd. |
MichaelW | 5:56fd0b265aba | 4 | * |
MichaelW | 5:56fd0b265aba | 5 | *Permission is hereby granted, free of charge, to any person obtaining a copy |
MichaelW | 5:56fd0b265aba | 6 | *of this software and associated documentation files (the "Software"), to deal |
MichaelW | 5:56fd0b265aba | 7 | *in the Software without restriction, including without limitation the rights |
MichaelW | 5:56fd0b265aba | 8 | *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
MichaelW | 5:56fd0b265aba | 9 | *copies of the Software, and to permit persons to whom the Software is |
MichaelW | 5:56fd0b265aba | 10 | *furnished to do so, subject to the following conditions: |
MichaelW | 5:56fd0b265aba | 11 | * |
MichaelW | 5:56fd0b265aba | 12 | *The above copyright notice and this permission notice shall be included in |
MichaelW | 5:56fd0b265aba | 13 | *all copies or substantial portions of the Software. |
MichaelW | 5:56fd0b265aba | 14 | * |
MichaelW | 5:56fd0b265aba | 15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MichaelW | 5:56fd0b265aba | 16 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MichaelW | 5:56fd0b265aba | 17 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MichaelW | 5:56fd0b265aba | 18 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MichaelW | 5:56fd0b265aba | 19 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MichaelW | 5:56fd0b265aba | 20 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MichaelW | 5:56fd0b265aba | 21 | *THE SOFTWARE. |
MichaelW | 5:56fd0b265aba | 22 | * |
MichaelW | 5:56fd0b265aba | 23 | * @section Description |
MichaelW | 5:56fd0b265aba | 24 | *This class provides an object to which a variable can be attached. Any type |
MichaelW | 5:56fd0b265aba | 25 | *for which a parse_args function specilisation exists can be attached. This includes |
MichaelW | 5:56fd0b265aba | 26 | *all of the standard types. |
MichaelW | 5:56fd0b265aba | 27 | * |
MichaelW | 5:56fd0b265aba | 28 | */ |
MichaelW | 5:56fd0b265aba | 29 | #ifndef RPCVARIABLE_H_ |
MichaelW | 5:56fd0b265aba | 30 | #define RPCVARIABLE_H_ |
MichaelW | 5:56fd0b265aba | 31 | /** Includes |
MichaelW | 5:56fd0b265aba | 32 | * |
MichaelW | 5:56fd0b265aba | 33 | */ |
MichaelW | 5:56fd0b265aba | 34 | #include "mbed.h" |
MichaelW | 5:56fd0b265aba | 35 | #include "platform.h" |
MichaelW | 5:56fd0b265aba | 36 | #include "rpc.h" |
MichaelW | 5:56fd0b265aba | 37 | /** |
MichaelW | 5:56fd0b265aba | 38 | *Class to read and set an attached variable using the RPC |
MichaelW | 5:56fd0b265aba | 39 | * |
MichaelW | 5:56fd0b265aba | 40 | */ |
MichaelW | 5:56fd0b265aba | 41 | template<class T> |
MichaelW | 5:56fd0b265aba | 42 | class RPCVariable : public Base{ |
MichaelW | 5:56fd0b265aba | 43 | public: |
MichaelW | 5:56fd0b265aba | 44 | /** |
MichaelW | 5:56fd0b265aba | 45 | * Constructor |
MichaelW | 5:56fd0b265aba | 46 | * |
MichaelW | 5:56fd0b265aba | 47 | *@param ptr Pointer to the variable to make accessible over RPC. Any type of |
MichaelW | 5:56fd0b265aba | 48 | *variable can be connected |
MichaelW | 5:56fd0b265aba | 49 | *@param name The name of that this object will be over RPC |
MichaelW | 5:56fd0b265aba | 50 | */ |
MichaelW | 5:56fd0b265aba | 51 | template<class A> |
MichaelW | 5:56fd0b265aba | 52 | RPCVariable(A * ptr, const char * name) : Base(name){ |
MichaelW | 5:56fd0b265aba | 53 | _ptr = ptr; |
MichaelW | 5:56fd0b265aba | 54 | } |
MichaelW | 5:56fd0b265aba | 55 | /** |
MichaelW | 5:56fd0b265aba | 56 | *Read the variable over RPC. |
MichaelW | 5:56fd0b265aba | 57 | * |
MichaelW | 5:56fd0b265aba | 58 | *@return The value of the variable |
MichaelW | 5:56fd0b265aba | 59 | */ |
MichaelW | 5:56fd0b265aba | 60 | T read(){ |
MichaelW | 5:56fd0b265aba | 61 | return(*_ptr); |
MichaelW | 5:56fd0b265aba | 62 | } |
MichaelW | 5:56fd0b265aba | 63 | /** |
MichaelW | 5:56fd0b265aba | 64 | *Write a value to the variable over RPC |
MichaelW | 5:56fd0b265aba | 65 | * |
MichaelW | 5:56fd0b265aba | 66 | *@param The value to be written to the attached variable. |
MichaelW | 5:56fd0b265aba | 67 | */ |
MichaelW | 5:56fd0b265aba | 68 | void write(T value){ |
MichaelW | 5:56fd0b265aba | 69 | *_ptr = value; |
MichaelW | 5:56fd0b265aba | 70 | } |
MichaelW | 5:56fd0b265aba | 71 | |
MichaelW | 5:56fd0b265aba | 72 | #ifdef MBED_RPC |
MichaelW | 5:56fd0b265aba | 73 | virtual const struct rpc_method *get_rpc_methods(); |
MichaelW | 5:56fd0b265aba | 74 | static struct rpc_class *get_rpc_class(); |
MichaelW | 5:56fd0b265aba | 75 | #endif |
MichaelW | 5:56fd0b265aba | 76 | |
MichaelW | 5:56fd0b265aba | 77 | private: |
MichaelW | 5:56fd0b265aba | 78 | T * _ptr; |
MichaelW | 5:56fd0b265aba | 79 | |
MichaelW | 5:56fd0b265aba | 80 | }; |
MichaelW | 5:56fd0b265aba | 81 | |
MichaelW | 5:56fd0b265aba | 82 | //Set up RPC methods |
MichaelW | 5:56fd0b265aba | 83 | #ifdef MBED_RPC |
MichaelW | 5:56fd0b265aba | 84 | template <class T> |
MichaelW | 5:56fd0b265aba | 85 | const rpc_method *RPCVariable<T>::get_rpc_methods() { |
MichaelW | 5:56fd0b265aba | 86 | static const rpc_method rpc_methods[] = { |
MichaelW | 5:56fd0b265aba | 87 | { "read", rpc_method_caller<T, RPCVariable, &RPCVariable::read> }, |
MichaelW | 5:56fd0b265aba | 88 | { "write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> }, |
MichaelW | 5:56fd0b265aba | 89 | RPC_METHOD_SUPER(Base) |
MichaelW | 5:56fd0b265aba | 90 | }; |
MichaelW | 5:56fd0b265aba | 91 | return rpc_methods; |
MichaelW | 5:56fd0b265aba | 92 | } |
MichaelW | 5:56fd0b265aba | 93 | template <class T> |
MichaelW | 5:56fd0b265aba | 94 | rpc_class *RPCVariable<T>::get_rpc_class() { |
MichaelW | 5:56fd0b265aba | 95 | static const rpc_function funcs[] = {"new", rpc_function_caller<const char*, T,const char* , &Base::construct<RemoteVar, T ,const char*> >,RPC_METHOD_END}; |
MichaelW | 5:56fd0b265aba | 96 | static rpc_class c = { "RPCVariable", funcs, NULL }; |
MichaelW | 5:56fd0b265aba | 97 | return &c; |
MichaelW | 5:56fd0b265aba | 98 | } |
MichaelW | 5:56fd0b265aba | 99 | #endif |
MichaelW | 5:56fd0b265aba | 100 | |
MichaelW | 5:56fd0b265aba | 101 | //There could be specialisation for integer, to also give increment and decrements |
MichaelW | 5:56fd0b265aba | 102 | |
MichaelW | 5:56fd0b265aba | 103 | |
MichaelW | 4:05f0d66bee57 | 104 | #endif //RPCVARIABLE_H_ |