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