Learning how to use RPC.
Diff: RPCFunction.cpp
- Revision:
- 1:67aefdc74b32
- Parent:
- 0:9232f9e1178d
- Child:
- 2:1d5b7485f683
diff -r 9232f9e1178d -r 67aefdc74b32 RPCFunction.cpp --- a/RPCFunction.cpp Thu Sep 16 13:27:57 2010 +0000 +++ b/RPCFunction.cpp Mon Sep 20 14:26:52 2010 +0000 @@ -1,5 +1,5 @@ /** -*@section LICENSE +* @section LICENSE *Copyright (c) 2010 ARM Ltd. * *Permission is hereby granted, free of charge, to any person obtaining a copy @@ -20,7 +20,7 @@ *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *THE SOFTWARE. * -*@section Description +* @section Description *This class provides an object which can be called over RPC to run the function which is attached to it. * */ @@ -69,26 +69,15 @@ } return res; } - //Custom rpc method caller for run so that the string will not be delimted by anything, one argument only - //based on code in rpc.h - void rpc_method_caller_run(Base *this_ptr, const char *arguments, char *result) { - const char *next = arguments; - char * arg1 = parse_arg_char(next,NULL); - - (static_cast<RPCFunction*>(this_ptr)->run)(arg1); - - if(result != NULL) { - result[0] = '\0'; - } - } + //Custom rpc method caller for execute so that the string will not be delimited by anything //See line 436 of rpc.h - void rpc_method_caller_execute(Base *this_ptr, const char *arguments, char *result) { + void rpc_method_caller_run(Base *this_ptr, const char *arguments, char *result) { const char *next = arguments; char* arg1 = parse_arg_char(next,NULL); - char * res = (static_cast<RPCFunction*>(this_ptr)->execute)(arg1); + char * res = (static_cast<RPCFunction*>(this_ptr)->run)(arg1); if(result != NULL) { write_result<char*>(res, result); } @@ -98,48 +87,29 @@ _ftr = f; } - //Function call which executes the packet - char* RPCFunction::execute(char * input){ + + //Just run the attached function using the string thats in private memory - or just using null values, + char * RPCFunction::run(char * input){ strcpy(_input, input); (*_ftr)(_input,_output); return(_output); } - - //Just run the attached function using the string thats in private memory - or just using null values, - void RPCFunction::run(char * str){ - strcpy(_input, str); - (*_ftr)(_input,_output); - } //Just read the output string char* RPCFunction::read(){ return(_output); } - //Just set the input string - void RPCFunction::write(char * str){ - strcpy(_input, str); - } #ifdef MBED_RPC const rpc_method *RPCFunction::get_rpc_methods() { static const rpc_method rpc_methods[] = { - {"execute", rpc_method_caller_execute }, //Run using custom caller, all character accepted in string - { "run", rpc_method_caller_run }, //Run using custom caller, all character accepted in string + { "run", rpc_method_caller_run }, //Run using custom caller, all characters accepted in string { "read", rpc_method_caller<char*, RPCFunction, &RPCFunction::read> }, - { "write", rpc_method_caller<RPCFunction, char*, &RPCFunction::write> }, RPC_METHOD_SUPER(Base) }; return rpc_methods; } - //creating a new one has very little meaning over RPC - rpc_class *RPCFunction::get_rpc_class() { - static const rpc_function funcs[] = { - /*"new", rpc_function_caller<const char*, void(*f)(char*, char*), const char*, &Base::construct<Packet,void(*f)(char*, char*),const char*> >,*/ - RPC_METHOD_END - }; - static rpc_class c = { "RPCFunction", funcs, NULL }; - return &c; - } + #endif