Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of libMiMic by
Diff: mbed/mod/ModJsonRpc.cpp
- Revision:
- 73:8c7dd6fd462e
- Parent:
- 72:c118a7aa37a3
- Child:
- 75:2a18df0ef111
--- a/mbed/mod/ModJsonRpc.cpp Fri Jun 13 11:06:33 2014 +0000 +++ b/mbed/mod/ModJsonRpc.cpp Sat Jun 14 02:14:20 2014 +0000 @@ -4,7 +4,22 @@ namespace MiMic { - #define NUM_OF_OBJECTS 32 + #define NUM_OF_OBJECTS 3 + void** newObjectArray() + { + void** r=new void*[NUM_OF_OBJECTS]; + memset(r,sizeof(void*)*NUM_OF_OBJECTS,0); + return r; + } + void deleteObjectArray(void** v) + { + for(int i=0;i<NUM_OF_OBJECTS;i++){ + if(v[i]!=NULL){ + delete v[i]; + } + } + delete v; + } ModJsonRpc::ModJsonRpc(const char* i_path,const struct NyLPC_TJsonRpcClassDef** i_rpc_table):ModBaseClass(i_path) { @@ -19,6 +34,8 @@ { if(this->_mod!=NULL){ NyLPC_cModJsonRpc_finalize(this->_mod); + free(this->_mod); + deleteObjectArray(this->_objects); this->_mod=NULL; } } @@ -27,6 +44,7 @@ ModBaseClass::setParam(i_path); this->_rpc_table=i_rpc_table; } + bool ModJsonRpc::execute(HttpdConnection& i_connection) { if(this->_mod!=NULL){ @@ -36,31 +54,28 @@ if(this->_mod==NULL){ return false; } - bool ret=false; - //initialize table - this->_objects=new void*[NUM_OF_OBJECTS]; - memset(this->_objects,sizeof(void*)*NUM_OF_OBJECTS,0); //initialize websocket NyLPC_cModJsonRpc_initialize(this->_mod,this->_path,this->_rpc_table); if(NyLPC_cModJsonRpc_canHandle(this->_mod,i_connection._ref_inst)){ - ret=NyLPC_cModJsonRpc_execute(this->_mod,i_connection._ref_inst)?true:false; + if(NyLPC_cModJsonRpc_execute(this->_mod,i_connection._ref_inst)){ + //initialize object array + this->_objects=newObjectArray(); + return true; + } } NyLPC_cModJsonRpc_finalize(this->_mod); free(this->_mod); this->_mod=NULL; - - for(int i=0;i<NUM_OF_OBJECTS;i++){ - if(this->_objects[i]!=NULL){ - delete this->_objects[i]; - } - } - return ret; + return false; } void ModJsonRpc::dispatchRpcCall() { const union NyLPC_TJsonRpcParserResult* rpc_result; + if(this->_mod==NULL){ + return; + } for(;;){ if(!NyLPC_cModJsonRpc_processRpcMessage(this->_mod)){ break; @@ -84,6 +99,10 @@ } } NyLPC_cModJsonRpc_close(this->_mod,1000); + NyLPC_cModJsonRpc_finalize(this->_mod); + deleteObjectArray(this->_objects); + free(this->_mod); + this->_mod=NULL; return; } bool ModJsonRpc::putResult(unsigned int i_id,const char* i_params_fmt,...)