Trial updated library for RPCInterface. The original library by Michael Walker now includes this fix. The trial library here will be deleted shortly...

Dependents:   HTTPServerExample_LR WebServerRPC WebServerRPC_Mai19 12_06_22_correction_probleme

Committer:
hexley
Date:
Fri Feb 04 00:56:43 2011 +0000
Revision:
0:1c61049a0349
Memory leak addressed in RPCFunction.cpp

Who changed what in which revision?

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