Michiel Berckvens / Mbed 2 deprecated ProjectHTTP

Dependencies:   DS1307 TextLCD mbed

Committer:
Michielber
Date:
Thu Dec 04 10:36:40 2014 +0000
Revision:
0:f615d151a72c
Berckvens Michiel & Basteyns Jonas 4/12/2014

Who changed what in which revision?

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