diff --git a/trick_sims/Cannon/models/mongoose_httpd/include/WSSession.hh b/trick_sims/Cannon/models/mongoose_httpd/include/WSSession.hh index ec2ef7a6..fd0fb11a 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/include/WSSession.hh +++ b/trick_sims/Cannon/models/mongoose_httpd/include/WSSession.hh @@ -25,6 +25,8 @@ public: void synchSend(); // This must be called at a frequency greater than or equal to the interval. void pause(); void unpause(); + void clear(); + void exit(); int emitError(const char* fmt, ... ); static int bad_ref_int ; diff --git a/trick_sims/Cannon/models/mongoose_httpd/include/WSSessionVariable.hh b/trick_sims/Cannon/models/mongoose_httpd/include/WSSessionVariable.hh index 96a72de6..09c121d4 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/include/WSSessionVariable.hh +++ b/trick_sims/Cannon/models/mongoose_httpd/include/WSSessionVariable.hh @@ -28,8 +28,6 @@ private: REF2 *varInfo; void *address; int size; - void *buffer_in; - void *buffer_out; bool deref; }; #endif diff --git a/trick_sims/Cannon/models/mongoose_httpd/src/WSSession.cpp b/trick_sims/Cannon/models/mongoose_httpd/src/WSSession.cpp index 8f796f65..f6394bfc 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/src/WSSession.cpp +++ b/trick_sims/Cannon/models/mongoose_httpd/src/WSSession.cpp @@ -99,6 +99,8 @@ void WSsession::addVariable(char* vname){ } if ( new_ref != NULL ) { + // This REF2 object will "belong" to the WSsessionVariable, so it has + // the right and responsibility to free() it in its destructor. WSsessionVariable *sessionVariable = new WSsessionVariable( new_ref ) ; sessionVariables.push_back( sessionVariable ) ; } @@ -131,3 +133,12 @@ void WSsession::synchSend() { // This must be called at a frequency greater than } void WSsession::pause() { enabled = false;} void WSsession::unpause() { enabled = true; } +void WSsession::clear() { + std::vector::iterator it; + it = sessionVariables.begin(); + while (it != sessionVariables.end()) { + delete *it; + it = sessionVariables.erase(it); + } +} +void WSsession::exit() {} diff --git a/trick_sims/Cannon/models/mongoose_httpd/src/WSSessionVariable.cpp b/trick_sims/Cannon/models/mongoose_httpd/src/WSSessionVariable.cpp index 54768312..6fafacec 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/src/WSSessionVariable.cpp +++ b/trick_sims/Cannon/models/mongoose_httpd/src/WSSessionVariable.cpp @@ -3,8 +3,6 @@ #include // for fpclassify #include // for setprecision - - WSsessionVariable::WSsessionVariable(REF2 * ref ) { varInfo = ref; address = varInfo->address; @@ -36,21 +34,13 @@ WSsessionVariable::WSsessionVariable(REF2 * ref ) { size *= get_size((char*)address) ; } } - // handle strings: set a max buffer size, the copy size may vary so will be set in copy_sim_data if (( string_type == TRICK_STRING ) || ( string_type == TRICK_WSTRING )) { size = MAX_ARRAY_LENGTH ; } - - buffer_in = calloc( size, 1 ) ; - buffer_out = calloc( size, 1 ) ; - } WSsessionVariable::~WSsessionVariable() { - - if (buffer_in != NULL) free( buffer_in ); - if (buffer_out != NULL) free( buffer_out ); if (varInfo != NULL) free( varInfo ); } diff --git a/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp b/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp index 7a5612eb..eafd3326 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp +++ b/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp @@ -115,7 +115,6 @@ int handle_JSON_var_server_msg (WSsession* session, const char* client_msg) { printf ("No \"cmd\" member found in client message.\n"); status = 1; } else if (strcmp(cmd, "var_add") == 0) { - //const gchar* var_name = json_object_get_string_member( object, "var_name"); session->addVariable( strdup(var_name) ); printf("session->addVariable(\"%s\")\n", var_name); } else if ( strcmp(cmd, "var_cycle") == 0 ) { @@ -129,15 +128,15 @@ int handle_JSON_var_server_msg (WSsession* session, const char* client_msg) { session->unpause(); printf("session->unpause()\n"); } else if ( strcmp(cmd, "var_send") == 0 ) { - //TODO + session->sendValues(); } else if ( strcmp(cmd, "var_clear") == 0 ) { - //TODO + session->clear(); } else if ( strcmp(cmd, "var_exit") == 0 ) { //TODO } else { printf ("Unknown Command \"%s\".\n", cmd); status = 1; - } + } return status; } #define DEBUG