Modified to run on Renesas GR Peach
Fork of mbed-rpc by
Embed:
(wiki syntax)
Show/hide line numbers
RPCVariable.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef RPCVARIABLE_H_ 00017 #define RPCVARIABLE_H_ 00018 00019 #include "rpc.h" 00020 00021 namespace mbed { 00022 00023 /** 00024 *Class to read and set an attached variable using the RPC 00025 * 00026 */ 00027 template<class T> 00028 class RPCVariable: public RPC { 00029 public: 00030 /** 00031 * Constructor 00032 * 00033 *@param ptr Pointer to the variable to make accessible over RPC. Any type of 00034 *variable can be connected 00035 *@param name The name of that this object will be over RPC 00036 */ 00037 template<class A> 00038 RPCVariable(A * ptr, const char * name) : RPC(name) { 00039 _ptr = ptr; 00040 } 00041 /** 00042 *Read the variable over RPC. 00043 * 00044 *@return The value of the variable 00045 */ 00046 T read() { 00047 return (*_ptr); 00048 } 00049 /** 00050 *Write a value to the variable over RPC 00051 * 00052 *@param The value to be written to the attached variable. 00053 */ 00054 void write(T value) { 00055 *_ptr = value; 00056 } 00057 00058 virtual const struct rpc_method *get_rpc_methods(); 00059 static struct rpc_class *get_rpc_class(); 00060 00061 private: 00062 T * _ptr; 00063 }; 00064 00065 template<class T> 00066 const rpc_method *RPCVariable<T>::get_rpc_methods() { 00067 static const rpc_method rpc_methods[] = { 00068 {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> }, 00069 {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> }, 00070 RPC_METHOD_SUPER(RPC) 00071 }; 00072 return rpc_methods; 00073 } 00074 00075 template<class T> 00076 rpc_class *RPCVariable<T>::get_rpc_class() { 00077 static const rpc_function funcs[] = { 00078 "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > , 00079 RPC_METHOD_END 00080 }; 00081 static rpc_class c = {"RPCVariable", funcs, NULL}; 00082 return &c; 00083 } 00084 00085 } 00086 00087 #endif //RPCVARIABLE_H_
Generated on Sat Jul 16 2022 20:13:06 by 1.7.2