Committer:
PA
Date:
Thu Jun 14 08:55:27 2012 +0000
Revision:
0:a7276b35b90b

        

Who changed what in which revision?

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