Trial updated library for RPCInterface. The original library by Michael Walker now includes this fix. The trial library here will be deleted shortly...

Dependents:   HTTPServerExample_LR WebServerRPC WebServerRPC_Mai19 12_06_22_correction_probleme

Committer:
hexley
Date:
Fri Feb 04 00:56:43 2011 +0000
Revision:
0:1c61049a0349
Memory leak addressed in RPCFunction.cpp

Who changed what in which revision?

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