Learning how to use RPC.
RPCFunction.h@9:ff67e6abe745, 2012-10-29 (annotated)
- Committer:
- fernandomachado
- Date:
- Mon Oct 29 21:06:55 2012 +0000
- Revision:
- 9:ff67e6abe745
- Parent:
- 5:56fd0b265aba
Learning RPC V0.01
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 5:56fd0b265aba | 1 | /** |
MichaelW | 5:56fd0b265aba | 2 | * @section LICENSE |
MichaelW | 5:56fd0b265aba | 3 | *Copyright (c) 2010 ARM Ltd. |
MichaelW | 5:56fd0b265aba | 4 | * |
MichaelW | 5:56fd0b265aba | 5 | *Permission is hereby granted, free of charge, to any person obtaining a copy |
MichaelW | 5:56fd0b265aba | 6 | *of this software and associated documentation files (the "Software"), to deal |
MichaelW | 5:56fd0b265aba | 7 | *in the Software without restriction, including without limitation the rights |
MichaelW | 5:56fd0b265aba | 8 | *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
MichaelW | 5:56fd0b265aba | 9 | *copies of the Software, and to permit persons to whom the Software is |
MichaelW | 5:56fd0b265aba | 10 | *furnished to do so, subject to the following conditions: |
MichaelW | 5:56fd0b265aba | 11 | * |
MichaelW | 5:56fd0b265aba | 12 | *The above copyright notice and this permission notice shall be included in |
MichaelW | 5:56fd0b265aba | 13 | *all copies or substantial portions of the Software. |
MichaelW | 5:56fd0b265aba | 14 | * |
MichaelW | 5:56fd0b265aba | 15 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
MichaelW | 5:56fd0b265aba | 16 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
MichaelW | 5:56fd0b265aba | 17 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
MichaelW | 5:56fd0b265aba | 18 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
MichaelW | 5:56fd0b265aba | 19 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
MichaelW | 5:56fd0b265aba | 20 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
MichaelW | 5:56fd0b265aba | 21 | *THE SOFTWARE. |
MichaelW | 5:56fd0b265aba | 22 | * |
MichaelW | 5:56fd0b265aba | 23 | * @section Description |
MichaelW | 5:56fd0b265aba | 24 | *This class provides an object which can be called over RPC to run the function which is attached to it. |
MichaelW | 5:56fd0b265aba | 25 | * |
MichaelW | 5:56fd0b265aba | 26 | */ |
MichaelW | 5:56fd0b265aba | 27 | #ifndef RPCFUNCTION_RPC |
MichaelW | 5:56fd0b265aba | 28 | #define RPCFUNCTION_RPC |
MichaelW | 5:56fd0b265aba | 29 | /** |
MichaelW | 5:56fd0b265aba | 30 | *Includes |
MichaelW | 5:56fd0b265aba | 31 | */ |
MichaelW | 5:56fd0b265aba | 32 | #include "mbed.h" |
MichaelW | 5:56fd0b265aba | 33 | #include "platform.h" |
MichaelW | 5:56fd0b265aba | 34 | #include "rpc.h" |
MichaelW | 5:56fd0b265aba | 35 | #define STR_LEN 64 |
MichaelW | 5:56fd0b265aba | 36 | #include "platform.h" |
MichaelW | 5:56fd0b265aba | 37 | |
MichaelW | 5:56fd0b265aba | 38 | #ifdef MBED_RPC |
MichaelW | 5:56fd0b265aba | 39 | #include "rpc.h" |
MichaelW | 5:56fd0b265aba | 40 | #endif |
MichaelW | 5:56fd0b265aba | 41 | /** |
MichaelW | 5:56fd0b265aba | 42 | * |
MichaelW | 5:56fd0b265aba | 43 | *Class to call custom functions over RPC |
MichaelW | 5:56fd0b265aba | 44 | * |
MichaelW | 5:56fd0b265aba | 45 | */ |
MichaelW | 5:56fd0b265aba | 46 | class RPCFunction : public Base{ |
MichaelW | 5:56fd0b265aba | 47 | public: |
MichaelW | 5:56fd0b265aba | 48 | /** |
MichaelW | 5:56fd0b265aba | 49 | * Constructor |
MichaelW | 5:56fd0b265aba | 50 | * |
MichaelW | 5:56fd0b265aba | 51 | *@param f Pointer to the function to call. the function must be of the form void foo(char * input, char * output) |
MichaelW | 5:56fd0b265aba | 52 | *@param name The name of this object |
MichaelW | 5:56fd0b265aba | 53 | */ |
MichaelW | 5:56fd0b265aba | 54 | RPCFunction(void(*f)(char*, char*), const char* = NULL); |
MichaelW | 5:56fd0b265aba | 55 | |
MichaelW | 5:56fd0b265aba | 56 | /** |
MichaelW | 5:56fd0b265aba | 57 | *run |
MichaelW | 5:56fd0b265aba | 58 | * |
MichaelW | 5:56fd0b265aba | 59 | *Calls the attached function passing the string in but doesn't return the result. |
MichaelW | 5:56fd0b265aba | 60 | *@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 |
MichaelW | 5:56fd0b265aba | 61 | *@return A string output from the function |
MichaelW | 5:56fd0b265aba | 62 | */ |
MichaelW | 5:56fd0b265aba | 63 | char * run(char* str); |
MichaelW | 5:56fd0b265aba | 64 | |
MichaelW | 5:56fd0b265aba | 65 | /** |
MichaelW | 5:56fd0b265aba | 66 | *Reads the value of the output string. |
MichaelW | 5:56fd0b265aba | 67 | * |
MichaelW | 5:56fd0b265aba | 68 | *@returns the string outputted from the last time the function was called |
MichaelW | 5:56fd0b265aba | 69 | */ |
MichaelW | 5:56fd0b265aba | 70 | char * read(); |
MichaelW | 5:56fd0b265aba | 71 | |
MichaelW | 5:56fd0b265aba | 72 | |
MichaelW | 5:56fd0b265aba | 73 | #ifdef MBED_RPC |
MichaelW | 5:56fd0b265aba | 74 | virtual const struct rpc_method *get_rpc_methods(); |
MichaelW | 5:56fd0b265aba | 75 | #endif |
MichaelW | 5:56fd0b265aba | 76 | |
MichaelW | 5:56fd0b265aba | 77 | private: |
MichaelW | 5:56fd0b265aba | 78 | void (*_ftr)(char*, char*); |
MichaelW | 5:56fd0b265aba | 79 | |
MichaelW | 5:56fd0b265aba | 80 | char _input[STR_LEN]; |
MichaelW | 5:56fd0b265aba | 81 | char _output[STR_LEN]; |
MichaelW | 5:56fd0b265aba | 82 | |
MichaelW | 5:56fd0b265aba | 83 | }; |
MichaelW | 0:9232f9e1178d | 84 | #endif |