You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

RPCFunction.h 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 RPCFUNCTION_RPC
  17. #define RPCFUNCTION_RPC
  18. #include "rpc.h"
  19. #define STR_LEN 64
  20. namespace mbed {
  21. /**
  22. *
  23. *Class to call custom functions over RPC
  24. *
  25. */
  26. class RPCFunction: public RPC {
  27. public:
  28. /**
  29. * Constructor
  30. *
  31. *@param f Pointer to the function to call. the function must be of the form void foo(char * input, char * output)
  32. *@param name The name of this object
  33. */
  34. RPCFunction(void (*f)(Arguments*, Reply*), const char* = NULL);
  35. /**
  36. *run
  37. *
  38. *Calls the attached function passing the string in but doesn't return the result.
  39. *@param str The string to be passed into the attached function. This string can consist of any ASCII characters apart from escape codes. The usual limtations on argument content for RPC strings has been removed
  40. *@return A string output from the function
  41. */
  42. void run(Arguments* args, Reply* r);
  43. virtual const struct rpc_method *get_rpc_methods();
  44. private:
  45. void (*_ftr)(Arguments*, Reply*);
  46. char _input[STR_LEN];
  47. char _output[STR_LEN];
  48. };
  49. }
  50. #endif