# HG changeset patch # User Jacob Dawid # Date 1302269001 -7200 # Node ID 6fd5e06285da5dd8a9c76a0097e31e89e68a6e70 # Parent 6b3780a781d59665cfa002c1437dfe64ea32b840 Renamed methods, added comments and TODOs. diff -r 6b3780a781d5 -r 6fd5e06285da gui//src/OctaveLink.cpp --- a/gui//src/OctaveLink.cpp Fri Apr 08 14:59:59 2011 +0200 +++ b/gui//src/OctaveLink.cpp Fri Apr 08 15:23:21 2011 +0200 @@ -117,7 +117,7 @@ // TODO: No need to run too quickly. The documentation says it will run // at most 10 times per second. This may be too fast and we will need to // artificially slow it down somehow. Not sure at this time how. - oct_octave_server.process_octave_server_data(); + oct_octave_server.processOctaveServerData(); return 0; } @@ -131,12 +131,12 @@ OctaveLink::OctaveLink() { // Create the mutexes - pthread_mutex_init(&server_mutex,NULL); - pthread_mutex_init(&octave_lock_mutex,NULL); + pthread_mutex_init(&m_serverMutex,NULL); + pthread_mutex_init(&m_octaveLockMutex,NULL); - prevHistLen = 0; + m_previousHistoryLength = 0; - is_processing_server_data = false; + m_isProcessingServerData = false; } @@ -153,166 +153,166 @@ *******************************************************************************/ //************************************************************************* -std::vector OctaveLink::get_variable_info_list(void) +std::vector OctaveLink::variableInfoList(void) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return std::vector(); // Copy the list of variable information - std::vector retval( variable_symtab_list.size() ); - std::copy( variable_symtab_list.begin(), variable_symtab_list.end(), retval.begin() ); - variable_symtab_list = std::vector(); + std::vector retval( m_variableSymbolTableList.size() ); + std::copy( m_variableSymbolTableList.begin(), m_variableSymbolTableList.end(), retval.begin() ); + m_variableSymbolTableList = std::vector(); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return retval; } //************************************************************************* -std::vector OctaveLink::get_requested_variables(void) +std::vector OctaveLink::requestedVariables(void) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return std::vector(); // Copy the list of requested variables - std::vector retval( requested_variables.size() ); - std::copy( requested_variables.begin(), requested_variables.end(), retval.begin() ); - requested_variables = std::vector(); + std::vector retval( m_requestedVariables.size() ); + std::copy( m_requestedVariables.begin(), m_requestedVariables.end(), retval.begin() ); + m_requestedVariables = std::vector(); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return retval; } //************************************************************************* -int OctaveLink::set_requested_variables_names( std::vector variables_names ) +int OctaveLink::setRequestedVariableNames( std::vector variables_names ) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return -1; // Set the list of requested variables - variables_request_list = std::vector( variables_names.size() ); - std::copy( variables_names.begin(), variables_names.end(), variables_request_list.begin() ); + m_variablesRequestList = std::vector( variables_names.size() ); + std::copy( variables_names.begin(), variables_names.end(), m_variablesRequestList.begin() ); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return 0; } //************************************************************************* -string_vector OctaveLink::get_history_list(void) +string_vector OctaveLink::getHistoryList(void) { // Acquire mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return string_vector(); // Copy the list of command history items - string_vector retval( history_list ); - history_list = string_vector(); + string_vector retval( m_historyList ); + m_historyList = string_vector(); // Release mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return retval; } -std::vector OctaveLink::get_breakpoint_list(int& status) +std::vector OctaveLink::breakPointList(int& status) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) { status = -1; return std::vector(); } // Copy the list of variable information - std::vector retval (current_breakpoints.size()); - std::copy( current_breakpoints.begin(), current_breakpoints.end(), retval.begin() ); + std::vector retval (m_currentBreakpoints.size()); + std::copy( m_currentBreakpoints.begin(), m_currentBreakpoints.end(), retval.begin() ); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); status = 0; return retval; } -bool OctaveLink::is_breakpoint_reached (int& status) +bool OctaveLink::isBreakpointReached (int& status) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) { status = -1; return false; } // Copy the list of variable information - bool retval = (breakpoint_reached.size()>0); + bool retval = (m_reachedBreakpoints.size()>0); //if (retval) // octave_stdout << "Breakpoint reached" << std::endl; // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); status = 0; return retval; } -std::vector OctaveLink::get_breakpoint_reached() +std::vector OctaveLink::reachedBreakpoint() { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return std::vector(); // Copy the list of variable information - std::vector retval (breakpoint_reached.size()); - std::copy (breakpoint_reached.begin(), breakpoint_reached.end(), retval.begin() ); + std::vector retval (m_reachedBreakpoints.size()); + std::copy (m_reachedBreakpoints.begin(), m_reachedBreakpoints.end(), retval.begin() ); //if (breakpoint_reached.size()>0) // octave_stdout << "Breakpoint reached" << std::endl; // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return retval; } -int OctaveLink::add_breakpoint( BreakPoint bp_info ) +int OctaveLink::addBreakpoint( BreakPoint bp_info ) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return -1; // Copy the list of variable information - added_breakpoints.push_back (bp_info); + m_addedBreakpoints.push_back (bp_info); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return 0; } -int OctaveLink::remove_breakpoint( BreakPoint bp_info ) +int OctaveLink::removeBreakpoint( BreakPoint bp_info ) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return -1; // Copy the list of variable information - removed_breakpoints.push_back (bp_info); + m_removedBreakpoints.push_back (bp_info); // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return 0; } @@ -321,16 +321,16 @@ status_t modify_breakpoint( bp_info_t old_bp_info, bp_info_t new_bp_info ); */ -int OctaveLink::set_breakpoint_action (BreakPointAction action) +int OctaveLink::setBreakpointAction (BreakPointAction action) { // Acquire the mutex - if( pthread_mutex_trylock( &server_mutex ) != 0 ) + if( pthread_mutex_trylock( &m_serverMutex ) != 0 ) return -1; - bp_action = action; + m_breakPointAction = action; // Release the mutex - pthread_mutex_unlock( &server_mutex ); + pthread_mutex_unlock( &m_serverMutex ); return 0; } @@ -343,7 +343,7 @@ *******************************************************************************/ //************************************************************************* -int OctaveLink::process_octave_server_data(void) +int OctaveLink::processOctaveServerData(void) { struct timeval start, stop; #ifndef __WIN32__ @@ -351,23 +351,23 @@ #endif // Acquire mutex - if( pthread_mutex_lock( &server_mutex ) != 0 ) + if( pthread_mutex_lock( &m_serverMutex ) != 0 ) { octave_stdout << "Error acquiring the octave_server data lock mutex" << std::endl; return -1; } - is_processing_server_data = true; + m_isProcessingServerData = true; process_breakpoint_action(); - process_breakpoint_add_remove_modify(); - process_requested_variables(); - set_variable_info_list(); - set_history_list(); - set_breakpoint_list(); + processBreakpointAndRemoveModify(); + processRequestedVariables(); + setVariableInfoList(); + setHistoryList(); + setBreakPointList(); // Release mutex - pthread_mutex_unlock( &server_mutex ); - is_processing_server_data = false; + pthread_mutex_unlock( &m_serverMutex ); + m_isProcessingServerData = false; #ifndef __WIN32__ gettimeofday(&stop, NULL); @@ -381,7 +381,7 @@ //************************************************************************* -int OctaveLink::set_variable_info_list( void ) +int OctaveLink::setVariableInfoList( void ) { static std::vector lastVars; std::vector currVars; @@ -398,11 +398,11 @@ dim_vector dims = varval.dims (); VariableMetaData tempVar; - tempVar.variable_name = it->name(); - tempVar.size.push_back( varval.rows() ); - tempVar.size.push_back( varval.columns() ); - tempVar.byte_size = varval.byte_size(); - tempVar.type_name = varval.type_name(); + tempVar.variableName = it->name(); + tempVar.dimensionalSize.push_back( varval.rows() ); + tempVar.dimensionalSize.push_back( varval.columns() ); + tempVar.byteSize = varval.byte_size(); + tempVar.typeName = varval.type_name(); currVars.push_back(tempVar); } @@ -412,9 +412,9 @@ lastVars = currVars; // Copy currVars into octave_server::variable_symtab_list - variable_symtab_list = std::vector( currVars.size() ); + m_variableSymbolTableList = std::vector( currVars.size() ); - std::copy( currVars.begin(), currVars.end(), variable_symtab_list.begin() ); + std::copy( currVars.begin(), currVars.end(), m_variableSymbolTableList.begin() ); } @@ -423,7 +423,7 @@ //************************************************************************* -int OctaveLink::process_requested_variables( void ) +int OctaveLink::processRequestedVariables( void ) { /* @@ -482,26 +482,26 @@ //************************************************************************* -int OctaveLink::set_history_list( void ) +int OctaveLink::setHistoryList( void ) { // Build up the current list int currentLen = command_history::length(); - if ( currentLen != prevHistLen ) + if ( currentLen != m_previousHistoryLength ) { - for( int i = prevHistLen ; i < currentLen ; i++ ) - history_list.append( command_history::get_entry(i) ); - prevHistLen = currentLen; + for( int i = m_previousHistoryLength ; i < currentLen ; i++ ) + m_historyList.append( command_history::get_entry(i) ); + m_previousHistoryLength = currentLen; } return 0; } //************************************************************************* -int OctaveLink::set_breakpoint_list( void ) +int OctaveLink::setBreakPointList( void ) { // Set the list of breakpoints - current_breakpoints = std::vector(); + m_currentBreakpoints = std::vector(); octave_value_list zz; @@ -514,15 +514,15 @@ { BreakPoint tmp; - tmp.filename = it->first; - tmp.line_number = m[j]; + tmp.fileName = it->first; + tmp.lineNumber = m[j]; - current_breakpoints.push_back (tmp); + m_currentBreakpoints.push_back (tmp); } } // If in debug mode, set the location of the break - breakpoint_reached = std::vector(); + m_reachedBreakpoints = std::vector(); octave_user_code *dbg_fcn = get_user_code (); @@ -560,12 +560,12 @@ { funcName = shortName.substr (0,dot); } - tmp.filename = funcName; - tmp.line_number = l; + tmp.fileName = funcName; + tmp.lineNumber = l; // octave_stdout << "BP reached at " << tmp.filename << ":" << tmp.line_number << std::endl; - breakpoint_reached.push_back (tmp); + m_reachedBreakpoints.push_back (tmp); } else octave_stdout << " " << std::endl; @@ -582,7 +582,7 @@ if (Vdebugging) { - if (bp_action==StepInto) + if (m_breakPointAction==StepInto) { Vdebugging = false; tree_evaluator::dbstep_flag = -1; @@ -592,7 +592,7 @@ rl_done = 1; rl_forced_update_display (); } - else if (bp_action==StepOver) + else if (m_breakPointAction==StepOver) { Vdebugging = false; tree_evaluator::dbstep_flag = 1; @@ -602,7 +602,7 @@ rl_done = 1; rl_forced_update_display (); } - else if (bp_action==StepOut) + else if (m_breakPointAction==StepOut) { Vdebugging = false; tree_evaluator::dbstep_flag = -2; @@ -614,7 +614,7 @@ } - else if (bp_action==Continue) + else if (m_breakPointAction==Continue) { Vdebugging = false; tree_evaluator::dbstep_flag = 0; @@ -624,7 +624,7 @@ rl_done = 1; rl_forced_update_display (); } - else if (bp_action==Break) + else if (m_breakPointAction==Break) { tree_evaluator::dbstep_flag = 0; octave_throw_interrupt_exception (); @@ -634,37 +634,37 @@ rl_done = 1; rl_forced_update_display (); } - bp_action = None; + m_breakPointAction = None; } return 0; } //************************************************************************* -int OctaveLink::process_breakpoint_add_remove_modify(void) +int OctaveLink::processBreakpointAndRemoveModify(void) { //octave_stdout << "Processing breakpoints changes" << std::endl; // Process added breakpoints - for (int i = 0 ; i < added_breakpoints.size() ; i++) + for (int i = 0 ; i < m_addedBreakpoints.size() ; i++) { - std::string funcName = added_breakpoints[i].filename; + std::string funcName = m_addedBreakpoints[i].fileName; bp_table::intmap lines; - lines[0] = added_breakpoints[i].line_number; + lines[0] = m_addedBreakpoints[i].lineNumber; bp_table::add_breakpoint (funcName,lines); octave_stdout << "Adding breakpoint: " << funcName << " : " << lines[0] << std::endl; } - added_breakpoints = std::vector(); + m_addedBreakpoints = std::vector(); // Process removed breakpoints - for (int i = 0 ; i < removed_breakpoints.size() ; i++) + for (int i = 0 ; i < m_removedBreakpoints.size() ; i++) { - std::string funcName = removed_breakpoints[i].filename; + std::string funcName = m_removedBreakpoints[i].fileName; bp_table::intmap lines; - lines[0] = removed_breakpoints[i].line_number; + lines[0] = m_removedBreakpoints[i].lineNumber; bp_table::remove_breakpoint (funcName,lines); //octave_stdout << "Removing breakpoint: " << funcName << " : " << lines[0] << std::endl; } - removed_breakpoints = std::vector(); + m_removedBreakpoints = std::vector(); // Process modified breakpoints // TODO: diff -r 6b3780a781d5 -r 6fd5e06285da gui//src/OctaveLink.h --- a/gui//src/OctaveLink.h Fri Apr 08 14:59:59 2011 +0200 +++ b/gui//src/OctaveLink.h Fri Apr 08 15:23:21 2011 +0200 @@ -40,19 +40,19 @@ #include #if defined (HAVE_PTHREAD_H) -#include + #include #elif defined (__WIN32__) -#include -typedef CRITICAL_SECTION pthread_mutex_t; -#define pthread_mutex_init(x,a) InitializeCriticalSection(x) -inline int pthread_mutex_trylock(pthread_mutex_t *x) -{ - EnterCriticalSection(x); - return 0; -} -#define pthread_mutex_lock(x) pthread_mutex_trylock(x) -#define pthread_mutex_unlock(x) LeaveCriticalSection(x) -typedef HANDLE pthread_t; + #include + typedef CRITICAL_SECTION pthread_mutex_t; + #define pthread_mutex_init(x,a) InitializeCriticalSection(x) + inline int pthread_mutex_trylock(pthread_mutex_t *x) + { + EnterCriticalSection(x); + return 0; + } + #define pthread_mutex_lock(x) pthread_mutex_trylock(x) + #define pthread_mutex_unlock(x) LeaveCriticalSection(x) + typedef HANDLE pthread_t; #endif /** @@ -85,14 +85,14 @@ /** * The full path and filename where the breakpoint resides. */ - std::string filename; + std::string fileName; /** * The line number where the breakpoint resides. * In the future, -1 can indicate an existing but disabled breakpoint. This * assumes that no one will ever have an M file longer than 2Million lines. */ - int line_number; + int lineNumber; } BreakPoint; typedef struct RequestedVariable @@ -103,75 +103,80 @@ typedef struct VariableMetaData { - /** - * The name of the variable - */ - std::string variable_name; + /** The name of the variable. */ + std::string variableName; - /** - * The dimensional size of the variable. - */ - std::vector size; + /** The dimensional size of the variable. */ + std::vector dimensionalSize; - /** - * The size of the variable in bytes. - */ - unsigned long long byte_size; + /** The size of the variable in bytes. */ + unsigned long long byteSize; - /** - * The name of the variable type. - */ - std::string type_name; + /** The name of the variable type. */ + std::string typeName; friend int operator==(const VariableMetaData& left, - const VariableMetaData& right) - { - return (left.variable_name==right.variable_name) && - (left.size==right.size) && - (left.byte_size==right.byte_size) && - (left.type_name==right.type_name); + const VariableMetaData& right) { + return (left.variableName == right.variableName) && + (left.dimensionalSize == right.dimensionalSize) && + (left.byteSize == right.byteSize) && + (left.typeName == right.typeName); } } VariableMetaData; OctaveLink(); ~OctaveLink(); - bool isProcessing(void) {return is_processing_server_data;}; + bool isProcessing(void) { return m_isProcessingServerData; } // Functions used to access data form the client side. - /** - * Debugging related methods. - */ - std::vector get_breakpoint_list(int& status); - bool is_breakpoint_reached(int& status); - std::vector get_breakpoint_reached(); - int add_breakpoint( BreakPoint bp_info ); - int remove_breakpoint( BreakPoint bp_info ); - int modify_breakpoint( BreakPoint old_bp_info, BreakPoint new_bp_info ); - int set_breakpoint_action( BreakPointAction action ); + /** Debugging related methods. */ + + /** TODO: Describe. */ + std::vector breakPointList(int& status); + + /** TODO: Describe. */ + std::vector reachedBreakpoint(); + + /** TODO: Describe. */ + bool isBreakpointReached(int& status); + + /** TODO: Describe. */ + int addBreakpoint(BreakPoint bp_info); - /** - * Variable related methods. - */ - std::vector get_variable_info_list(void); - std::vector get_requested_variables(void); - int set_requested_variables_names( std::vector variable_names ); + /** TODO: Describe. */ + int removeBreakpoint(BreakPoint bp_info); + + /** TODO: Describe. */ + int modifyBreakpoint(BreakPoint old_bp_info, BreakPoint new_bp_info); + + /** TODO: Describe. */ + int setBreakpointAction(BreakPointAction action); + + /** Variable related methods. */ + std::vector variableInfoList(void); + + /** TODO: Describe. */ + std::vector requestedVariables(void); + + /** TODO: Describe. */ + int setRequestedVariableNames(std::vector variableNames); /** * History related methods. */ - string_vector get_history_list(void); + string_vector getHistoryList(void); -// FUNCTIONS USED TO ACCESS DATA FROM THE OCTAVE SERVER SIDE + // FUNCTIONS USED TO ACCESS DATA FROM THE OCTAVE SERVER SIDE -// NOTE: THIS IMPLIES THAT THESE ARE ONLY CALLED FROM -// OCTAVE DURING A TIME IN WHICH THINGS ARE KNOWN TO -// BE "THREAD-SAFE". PROPOSED LOCATIONS: -// src/toplev.cc - main_loop() at the end of the do...while -// src/pt-bp.h - MAYBE_DO_BREAKPOINT just prior to the do_keyboard -// Most of these will call octave API functions to "pull" the data, rather -// than having octave pass in the data. This will help make changes -// exlusive to this class if/when the Octave API changes. + // NOTE: THIS IMPLIES THAT THESE ARE ONLY CALLED FROM + // OCTAVE DURING A TIME IN WHICH THINGS ARE KNOWN TO + // BE "THREAD-SAFE". PROPOSED LOCATIONS: + // src/toplev.cc - main_loop() at the end of the do...while + // src/pt-bp.h - MAYBE_DO_BREAKPOINT just prior to the do_keyboard + // Most of these will call octave API functions to "pull" the data, rather + // than having octave pass in the data. This will help make changes + // exlusive to this class if/when the Octave API changes. /** * Calls all the appropriate functions that follow to update Octave * according to the data sent from the client in a thread-safe manner. @@ -184,32 +189,36 @@ * ... * Release lock */ - int process_octave_server_data(void); + int processOctaveServerData(void); + + /** Debugging related methods. */ + /** TODO: Describe. */ + int setBreakPointList(void); - /** - * Debugging related methods. - */ - int set_breakpoint_list(void); - int set_current_breakpoint(std::string filename, int line_number); // duplicate of process_breakpoint_action or helper function??? - int process_breakpoint_add_remove_modify(void); + /** TODO: Describe. */ + // duplicate of process_breakpoint_action or helper function??? + int setCurrentBreakpoint(std::string filename, int line_number); + + /** TODO: Describe. */ + int processBreakpointAndRemoveModify(void); + + /** TODO: Describe. */ int process_breakpoint_action(void); - /** - * Variable related methods. - */ - int set_variable_info_list(void); - int process_requested_variables(void); + /** Variable related methods. */ + /** TODO: Describe. */ + int setVariableInfoList(void); - /** - * History related methods. - */ - int set_history_list(void); + /** TODO: Describe. */ + int processRequestedVariables(void); + + /** History related methods. */ + /** TODO: Describe. */ + int setHistoryList(void); private: - /** - * Mutex variable used to protect access to internal class data. - */ - pthread_mutex_t server_mutex; + /** Mutex variable used to protect access to internal class data. */ + pthread_mutex_t m_serverMutex; /** * Mutex variable used to protect access to octave internals on asynchronous requests. @@ -218,34 +227,30 @@ * in a debugger mouse-over, inspection of matrix variables by double-clicking in the * main window, etc. */ - pthread_mutex_t octave_lock_mutex; + pthread_mutex_t m_octaveLockMutex; - std::vector current_breakpoints; - std::vector breakpoint_reached; - std::vector added_breakpoints; - std::vector removed_breakpoints; - std::vector modify_breakpoints_old; - std::vector modify_breakpoints_new; - BreakPointAction bp_action; + std::vector m_currentBreakpoints; + std::vector m_reachedBreakpoints; + std::vector m_addedBreakpoints; + std::vector m_removedBreakpoints; + std::vector m_modifiedBreakpointsOld; + std::vector m_modifiedBreakpointsNew; + BreakPointAction m_breakPointAction; - /** - * Variable related member variables. - */ - std::vector variable_symtab_list; - std::vector variables_request_list; + /** Variable related member variables. */ + std::vector m_variableSymbolTableList; + std::vector m_variablesRequestList; // NOTE: Create an overloaded operator<< for octave_value to do the // flattening. This will allow us to append easily to an ostringstream // for output. - std::vector requested_variables; + std::vector m_requestedVariables; - /** - * History related member variables. - */ - int prevHistLen; - string_vector history_list; + /** History related member variables. */ + string_vector m_historyList; + int m_previousHistoryLength; - bool is_processing_server_data; + bool m_isProcessingServerData; }; int server_rl_event_hook_function(void);