changeset 13377:8c0d7a1d8e29

Converted C code in OctaveLink to C++ code.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Fri, 08 Apr 2011 11:29:36 +0200
parents 4831a6a620ff
children a49871ff6bd8
files gui//Quint.pro gui//src/OctaveLink.cpp gui//src/OctaveLink.h
diffstat 3 files changed, 152 insertions(+), 153 deletions(-) [+]
line wrap: on
line diff
--- a/gui//Quint.pro	Fri Apr 08 11:04:47 2011 +0200
+++ b/gui//Quint.pro	Fri Apr 08 11:29:36 2011 +0200
@@ -66,7 +66,9 @@
 	src/OctaveLink.h
 
 INCFLAGS = -g3 $$system(mkoctfile -p INCFLAGS)
-LFLAGS = $$system(mkoctfile -p LFLAGS) $$system(mkoctfile -p OCTAVE_LIBS) $$system(mkoctfile -p LIBS)
+LFLAGS = $$system(mkoctfile -p LFLAGS) \
+         $$system(mkoctfile -p OCTAVE_LIBS) \
+         $$system(mkoctfile -p LIBS)
 LIBS    += $$LFLAGS -loctave -loctinterp -lreadline
 QMAKE_CXXFLAGS  += $$INCFLAGS
 
--- a/gui//src/OctaveLink.cpp	Fri Apr 08 11:04:47 2011 +0200
+++ b/gui//src/OctaveLink.cpp	Fri Apr 08 11:29:36 2011 +0200
@@ -83,7 +83,7 @@
 
 #include <QFileInfo>
 
-octave_server oct_octave_server;
+OctaveLink oct_octave_server;
 
 
 static octave_user_code *
@@ -128,7 +128,7 @@
 }
 
 //*************************************************************************
-octave_server::octave_server()
+OctaveLink::OctaveLink()
 {
   // Create the mutexes 
   pthread_mutex_init(&server_mutex,NULL);
@@ -141,7 +141,7 @@
 
 
 //*************************************************************************
-octave_server::~octave_server()
+OctaveLink::~OctaveLink()
 {
 
 }
@@ -153,16 +153,16 @@
  *******************************************************************************/
 
 //*************************************************************************
-std::vector<variable_info_t> octave_server::get_variable_info_list(void)
+std::vector<OctaveLink::VariableMetaData> OctaveLink::get_variable_info_list(void)
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
-    return std::vector<variable_info_t>();
+    return std::vector<VariableMetaData>();
 
   // Copy the list of variable information
-  std::vector<variable_info_t> retval( variable_symtab_list.size() );
+  std::vector<VariableMetaData> retval( variable_symtab_list.size() );
   std::copy( variable_symtab_list.begin(), variable_symtab_list.end(), retval.begin() );
-  variable_symtab_list = std::vector<variable_info_t>();
+  variable_symtab_list = std::vector<VariableMetaData>();
 
   // Release the mutex
   pthread_mutex_unlock( &server_mutex );
@@ -172,16 +172,16 @@
 
 
 //*************************************************************************
-std::vector<requested_variable_t> octave_server::get_requested_variables(void)
+std::vector<OctaveLink::RequestedVariable> OctaveLink::get_requested_variables(void)
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
-    return std::vector<requested_variable_t>();
+    return std::vector<RequestedVariable>();
 
   // Copy the list of requested variables
-  std::vector<requested_variable_t> retval( requested_variables.size() );
+  std::vector<RequestedVariable> retval( requested_variables.size() );
   std::copy( requested_variables.begin(), requested_variables.end(), retval.begin() );
-  requested_variables = std::vector<requested_variable_t>();
+  requested_variables = std::vector<RequestedVariable>();
   
   // Release the mutex
   pthread_mutex_unlock( &server_mutex );
@@ -191,7 +191,7 @@
 
 
 //*************************************************************************
-status_t octave_server::set_requested_variables_names( std::vector<std::string> variables_names )
+int OctaveLink::set_requested_variables_names( std::vector<std::string> variables_names )
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -209,7 +209,7 @@
 
 
 //*************************************************************************
-string_vector octave_server::get_history_list(void)
+string_vector OctaveLink::get_history_list(void)
 {
   // Acquire mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -225,17 +225,17 @@
   return retval;
 }
 
-std::vector<bp_info_t> octave_server::get_breakpoint_list(int& status)
+std::vector<OctaveLink::BreakPoint> OctaveLink::get_breakpoint_list(int& status)
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
   {
     status = -1;
-    return std::vector<bp_info_t>();
+    return std::vector<BreakPoint>();
   }
 
   // Copy the list of variable information
-  std::vector<bp_info_t> retval (current_breakpoints.size());
+  std::vector<BreakPoint> retval (current_breakpoints.size());
   std::copy( current_breakpoints.begin(), current_breakpoints.end(), retval.begin() );
 
   // Release the mutex
@@ -245,7 +245,7 @@
   return retval;
 }
 
-bool octave_server::is_breakpoint_reached (int& status)
+bool OctaveLink::is_breakpoint_reached (int& status)
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -268,14 +268,14 @@
 }
 
 
-std::vector<bp_info_t> octave_server::get_breakpoint_reached()
+std::vector<OctaveLink::BreakPoint> OctaveLink::get_breakpoint_reached()
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
-    return std::vector<bp_info_t>();
+    return std::vector<BreakPoint>();
 
   // Copy the list of variable information
-  std::vector<bp_info_t> retval (breakpoint_reached.size());
+  std::vector<BreakPoint> retval (breakpoint_reached.size());
   std::copy (breakpoint_reached.begin(), breakpoint_reached.end(), retval.begin() );
 
   //if (breakpoint_reached.size()>0)
@@ -287,7 +287,7 @@
   return retval;
 }
 
-status_t octave_server::add_breakpoint( bp_info_t bp_info )
+int OctaveLink::add_breakpoint( BreakPoint bp_info )
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -302,7 +302,7 @@
   return 0;
 }
 
-status_t octave_server::remove_breakpoint( bp_info_t bp_info )
+int OctaveLink::remove_breakpoint( BreakPoint bp_info )
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -321,7 +321,7 @@
     status_t		   modify_breakpoint( bp_info_t old_bp_info, bp_info_t new_bp_info );
 */
 
-status_t octave_server::set_breakpoint_action (bp_action_t action)
+int OctaveLink::set_breakpoint_action (BreakPointAction action)
 {
   // Acquire the mutex
   if( pthread_mutex_trylock( &server_mutex ) != 0 )
@@ -343,7 +343,7 @@
  *******************************************************************************/
 
 //*************************************************************************
-status_t octave_server::process_octave_server_data(void)
+int OctaveLink::process_octave_server_data(void)
 {
   struct timeval start, stop;
 #ifndef __WIN32__
@@ -381,10 +381,10 @@
 
 
 //*************************************************************************
-status_t octave_server::set_variable_info_list( void )
+int OctaveLink::set_variable_info_list( void )
 {
-  static std::vector<variable_info_t> lastVars;
-  std::vector<variable_info_t> currVars;
+  static std::vector<VariableMetaData> lastVars;
+  std::vector<VariableMetaData> currVars;
 
 
   std::list<symbol_table::symbol_record> lvars = symbol_table::all_variables();
@@ -397,7 +397,7 @@
 
     dim_vector dims = varval.dims ();
 
-    variable_info_t tempVar;
+    VariableMetaData tempVar;
     tempVar.variable_name = it->name();
     tempVar.size.push_back( varval.rows() );
     tempVar.size.push_back( varval.columns() );
@@ -412,7 +412,7 @@
     lastVars = currVars;
     
     // Copy currVars into octave_server::variable_symtab_list
-    variable_symtab_list = std::vector<variable_info_t>( currVars.size() );
+    variable_symtab_list = std::vector<VariableMetaData>( currVars.size() );
 
     std::copy( currVars.begin(), currVars.end(), variable_symtab_list.begin() );
   }
@@ -423,7 +423,7 @@
 
 
 //*************************************************************************
-status_t octave_server::process_requested_variables( void )
+int OctaveLink::process_requested_variables( void )
 {
   /*
 
@@ -482,7 +482,7 @@
 
 
 //*************************************************************************
-status_t octave_server::set_history_list( void )
+int OctaveLink::set_history_list( void )
 {
   
   // Build up the current list
@@ -498,10 +498,10 @@
 }
 
 //*************************************************************************
-status_t octave_server::set_breakpoint_list( void )
+int OctaveLink::set_breakpoint_list( void )
 {
   // Set the list of breakpoints
-  current_breakpoints = std::vector<bp_info_t>();
+  current_breakpoints = std::vector<BreakPoint>();
 
   octave_value_list zz;
   
@@ -513,7 +513,7 @@
     for (size_t j = 0; j < nel; j++)
 
     {
-      bp_info_t tmp;
+      BreakPoint tmp;
       tmp.filename = it->first;
       tmp.line_number = m[j];
 
@@ -522,7 +522,7 @@
   }
 
   // If in debug mode, set the location of the break
-  breakpoint_reached = std::vector<bp_info_t>();
+  breakpoint_reached = std::vector<BreakPoint>();
 
   octave_user_code *dbg_fcn = get_user_code ();
 
@@ -546,7 +546,7 @@
       if (l > 0)
         {
 
-	  bp_info_t tmp;
+	  BreakPoint tmp;
 	  QFileInfo pathInfo;
 	  QString qFilePath (name.c_str());
 	  pathInfo.setFile (qFilePath);
@@ -577,12 +577,12 @@
 }
 
 //*************************************************************************
-status_t octave_server::process_breakpoint_action (void)
+int OctaveLink::process_breakpoint_action (void)
 {
 
   if (Vdebugging)
   {
-    if (bp_action==BP_ACTION_STEP_INTO)
+    if (bp_action==StepInto)
     {
       Vdebugging = false;
       tree_evaluator::dbstep_flag = -1;
@@ -592,7 +592,7 @@
       rl_done = 1;
       rl_forced_update_display ();
     }
-    else if (bp_action==BP_ACTION_STEP_OVER)
+    else if (bp_action==StepOver)
     {
       Vdebugging = false;
       tree_evaluator::dbstep_flag = 1;
@@ -602,7 +602,7 @@
       rl_done = 1;
       rl_forced_update_display ();
     }
-    else if (bp_action==BP_ACTION_STEP_OUT)
+    else if (bp_action==StepOut)
     {
       Vdebugging = false;
       tree_evaluator::dbstep_flag = -2;
@@ -614,7 +614,7 @@
 
       
     }
-    else if (bp_action==BP_ACTION_CONTINUE)
+    else if (bp_action==Continue)
     {
       Vdebugging = false;
       tree_evaluator::dbstep_flag = 0;
@@ -624,7 +624,7 @@
       rl_done = 1;
       rl_forced_update_display ();
     }
-    else if (bp_action==BP_ACTION_BREAK)
+    else if (bp_action==Break)
     {
       tree_evaluator::dbstep_flag = 0;
       octave_throw_interrupt_exception ();
@@ -634,14 +634,14 @@
       rl_done = 1;
       rl_forced_update_display ();
     }
-    bp_action = BP_ACTION_NONE;
+    bp_action = None;
   }
 
   return 0;
 }
 
 //*************************************************************************
-status_t octave_server::process_breakpoint_add_remove_modify(void)
+int OctaveLink::process_breakpoint_add_remove_modify(void)
 {
   //octave_stdout << "Processing breakpoints changes" << std::endl;
   // Process added breakpoints
@@ -653,7 +653,7 @@
     bp_table::add_breakpoint (funcName,lines);
     octave_stdout << "Adding breakpoint: " << funcName << " : " << lines[0] << std::endl; 
   }
-  added_breakpoints = std::vector<bp_info_t>();
+  added_breakpoints = std::vector<BreakPoint>();
 
   // Process removed breakpoints
   for (int i = 0 ; i < removed_breakpoints.size() ; i++)
@@ -664,7 +664,7 @@
     bp_table::remove_breakpoint (funcName,lines);
     //octave_stdout << "Removing breakpoint: " << funcName << " : " << lines[0] << std::endl; 
   }
-  removed_breakpoints = std::vector<bp_info_t>();
+  removed_breakpoints = std::vector<BreakPoint>();
 
   // Process modified breakpoints
   // TODO:
--- a/gui//src/OctaveLink.h	Fri Apr 08 11:04:47 2011 +0200
+++ b/gui//src/OctaveLink.h	Fri Apr 08 11:29:36 2011 +0200
@@ -21,8 +21,8 @@
  *
  * */
 
-#if !defined (octave_server_h)
-#define octave_server_h 1
+#ifndef OCTAVELINK_H
+#define OCTAVELINK_H
 
 #undef PACKAGE_BUGREPORT
 #undef PACKAGE_NAME
@@ -59,95 +59,93 @@
 typedef HANDLE pthread_t;
 #endif
 
-
-typedef int status_t;
-
-/**
- * Enumeration used to identify breakpoint actions
- */
-typedef enum bp_action_enum
-{
-  BP_ACTION_NONE	= 0,
-  BP_ACTION_STEP_INTO	= 1,
-  BP_ACTION_STEP_OVER	= 2,
-  BP_ACTION_STEP_OUT    = 3,
-  BP_ACTION_CONTINUE	= 3,
-  BP_ACTION_BREAK	= 4,
-} bp_action_t;
-
-/**
- * Structure used to store breakpoint info.
- *
- * Notes: used for add, remove, list operations, as well as for the BreakpointReached event.
- */
-typedef struct bp_info_struct
-{
-  /**
-   * The full path and filename where the breakpoint resides.
-   */
-  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;
-} bp_info_t;
-
 /**
  * Structure used to store variable information similar to that returned by
  * the 'whos' function.
  */
 typedef struct variable_info_struct variable_info_t;
-typedef struct variable_info_struct
+
+
+class OctaveLink
 {
-  /**
-   * The name of the variable
-   */
-  std::string variable_name;
+public:
+    /**
+     * Enumeration used to identify breakpoint actions
+     */
+    enum BreakPointAction
+    {
+        None,
+        StepInto,
+        StepOver,
+        StepOut,
+        Continue,
+        Break
+    };
 
-  /**
-   * The dimensional size of the variable.
-   */
-  std::vector<int> size;
+    /**
+     * Structure used to store breakpoint info.
+     *
+     * Notes: used for add, remove, list operations, as well as for the BreakpointReached event.
+     */
+    typedef struct BreakPoint
+    {
+      /**
+       * The full path and filename where the breakpoint resides.
+       */
+      std::string filename;
 
-  /**
-   * The size of the variable in bytes.
-   */
-  unsigned long long byte_size;
+      /**
+       * 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;
+    } BreakPoint;
 
-  /**
-   * The name of the variable type.
-   */
-  std::string type_name;
-  
-  friend int operator==(const variable_info_t& left,
-                        const variable_info_t& right)
-  {
-    return (left.variable_name==right.variable_name) &&
-         (left.size==right.size) &&
-         (left.byte_size==right.byte_size) &&
-         (left.type_name==right.type_name);
-  }
-  
-} variable_info_t;
+    typedef struct RequestedVariable
+    {
+        std::string name;
+        octave_value ov;
+    } RequestedVariable;
+
+    typedef struct VariableMetaData
+    {
+        /**
+        * The name of the variable
+        */
+        std::string variable_name;
+
+        /**
+        * The dimensional size of the variable.
+        */
+        std::vector<int> size;
 
-typedef struct requested_variable_struct
-{
-  std::string name;
-  octave_value ov;
-} requested_variable_t;
+        /**
+        * The size of the variable in bytes.
+        */
+        unsigned long long byte_size;
+
+        /**
+        * The name of the variable type.
+        */
+        std::string type_name;
 
-class octave_server
-{
+        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);
+        }
+    } VariableMetaData;
+
   private:
     /**
      * Mutex variable used to protect access to internal class data.
      */
     pthread_mutex_t server_mutex;
     
-    
     /**
      * Mutex variable used to protect access to octave internals on asynchronous requests.
      * 
@@ -156,29 +154,28 @@
      * main window, etc.
      */
     pthread_mutex_t octave_lock_mutex;
-	  
-	  
+
     /***********************************************************************
      * DEBUGGING RELATED VARIABLE
      **********************************************************************/
-    std::vector<bp_info_t> current_breakpoints;
-    std::vector<bp_info_t> breakpoint_reached;
-    std::vector<bp_info_t> added_breakpoints;
-    std::vector<bp_info_t> removed_breakpoints;
-    std::vector<bp_info_t> modify_breakpoints_old;
-    std::vector<bp_info_t> modify_breakpoints_new;
-    bp_action_t 	   bp_action;
+    std::vector<BreakPoint> current_breakpoints;
+    std::vector<BreakPoint> breakpoint_reached;
+    std::vector<BreakPoint> added_breakpoints;
+    std::vector<BreakPoint> removed_breakpoints;
+    std::vector<BreakPoint> modify_breakpoints_old;
+    std::vector<BreakPoint> modify_breakpoints_new;
+    BreakPointAction   	    bp_action;
    
     /***********************************************************************
      * VARIABLE INTERROGATION RELATED VARIABLES
      **********************************************************************/
-    std::vector<variable_info_t> variable_symtab_list;
+    std::vector<VariableMetaData> variable_symtab_list;
     std::vector<std::string>     variables_request_list;
 
     // 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_variable_t>    requested_variables;    
+    std::vector<RequestedVariable>    requested_variables;
     
     /***********************************************************************
      * HISTORY RELATED VARIABLES
@@ -190,8 +187,8 @@
     
   public:
 
-    octave_server();
-    ~octave_server();
+    OctaveLink();
+    ~OctaveLink();
 
     bool isProcessing(void) {return is_processing_server_data;};
 
@@ -204,20 +201,20 @@
     /***********************************************************************
      * DEBUGGING RELATED FUNCTIONS
      **********************************************************************/ 
-    std::vector<bp_info_t> get_breakpoint_list(int& status);
+    std::vector<BreakPoint> get_breakpoint_list(int& status);
     bool                   is_breakpoint_reached(int& status);
-    std::vector<bp_info_t> get_breakpoint_reached();    
-    status_t 		   add_breakpoint( bp_info_t bp_info );
-    status_t		   remove_breakpoint( bp_info_t bp_info );
-    status_t		   modify_breakpoint( bp_info_t old_bp_info, bp_info_t new_bp_info );
-    status_t		   set_breakpoint_action( bp_action_t action );
+    std::vector<BreakPoint> 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 );
    
     /***********************************************************************
      * VARIABLES RELATED FUNCTIONS
      **********************************************************************/
-    std::vector<variable_info_t>	get_variable_info_list(void);
-    std::vector<requested_variable_t>  	get_requested_variables(void);
-    status_t				set_requested_variables_names( std::vector<std::string> variable_names );
+    std::vector<VariableMetaData>	get_variable_info_list(void);
+    std::vector<RequestedVariable>  	get_requested_variables(void);
+    int				set_requested_variables_names( std::vector<std::string> variable_names );
 
     /***********************************************************************
      * HISTORY RELATED FUNCTIONS
@@ -251,33 +248,33 @@
      *   ...
      *   Release lock
      */
-    status_t process_octave_server_data(void);
+    int process_octave_server_data(void);
  
     /***********************************************************************
      * DEBUGGING RELATED FUNCTIONS
      **********************************************************************/   
-    status_t set_breakpoint_list(void);
-    status_t set_current_breakpoint(std::string filename, int line_number); // duplicate of process_breakpoint_action or helper function???
-    status_t process_breakpoint_add_remove_modify(void);
-    status_t process_breakpoint_action(void);
+    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);
+    int process_breakpoint_action(void);
 
     /***********************************************************************
      * VARIABLES INTERROGATION RELATED FUNCTIONS
      **********************************************************************/
-    status_t set_variable_info_list(void);
-    status_t process_requested_variables(void);
+    int set_variable_info_list(void);
+    int process_requested_variables(void);
     
     /***********************************************************************
      * HISTORY RELATED FUNCTIONS
      **********************************************************************/    
-    status_t set_history_list(void);
+    int set_history_list(void);
 
 };
 
 int server_rl_event_hook_function(void);
 bool server_rl_is_processing(void);
 
-extern octave_server oct_octave_server;
+extern OctaveLink oct_octave_server;
 
-#endif // octave_server_h
+#endif // OCTAVELINK_H