mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

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