Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
Это архивный репозиторий. Вы можете его клонировать или просматривать файлы, но не вносить изменения или открывать задачи/запросы на слияние.

RPCVariable.h 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #include "rpc.h"
  19. namespace mbed {
  20. /**
  21. *Class to read and set an attached variable using the RPC
  22. *
  23. */
  24. template<class T>
  25. class RPCVariable: public RPC {
  26. public:
  27. /**
  28. * Constructor
  29. *
  30. *@param ptr Pointer to the variable to make accessible over RPC. Any type of
  31. *variable can be connected
  32. *@param name The name of that this object will be over RPC
  33. */
  34. template<class A>
  35. RPCVariable(A * ptr, const char * name) : RPC(name) {
  36. _ptr = ptr;
  37. }
  38. /**
  39. *Read the variable over RPC.
  40. *
  41. *@return The value of the variable
  42. */
  43. T read() {
  44. return (*_ptr);
  45. }
  46. /**
  47. *Write a value to the variable over RPC
  48. *
  49. *@param The value to be written to the attached variable.
  50. */
  51. void write(T value) {
  52. *_ptr = value;
  53. }
  54. virtual const struct rpc_method *get_rpc_methods();
  55. static struct rpc_class *get_rpc_class();
  56. private:
  57. T * _ptr;
  58. };
  59. template<class T>
  60. const rpc_method *RPCVariable<T>::get_rpc_methods() {
  61. static const rpc_method rpc_methods[] = {
  62. {"read" , rpc_method_caller<T, RPCVariable, &RPCVariable::read> },
  63. {"write", rpc_method_caller<RPCVariable, T, &RPCVariable::write> },
  64. RPC_METHOD_SUPER(RPC)
  65. };
  66. return rpc_methods;
  67. }
  68. template<class T>
  69. rpc_class *RPCVariable<T>::get_rpc_class() {
  70. static const rpc_function funcs[] = {
  71. "new", rpc_function_caller<const char*, T, const char*, &RPC::construct<RPCVariable, T, const char*> > ,
  72. RPC_METHOD_END
  73. };
  74. static rpc_class c = {"RPCVariable", funcs, NULL};
  75. return &c;
  76. }
  77. }
  78. #endif //RPCVARIABLE_H_