RPCInterface

Fork of RPCInterface by Michael Walker

Committer:
MichaelW
Date:
Thu Sep 16 13:27:57 2010 +0000
Revision:
0:9232f9e1178d
Child:
1:67aefdc74b32
Changed to RPCFunction and RPCVariable.

Who changed what in which revision?

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