Mercurial > octave
changeset 16428:f016a5342e19
Merge in Ed's changes
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 04 Apr 2013 09:22:00 -0400 |
parents | 1df815271885 (current diff) 203976ae18d1 (diff) |
children | 1766d8655006 |
files | libinterp/corefcn/__execute_edit_hook__.cc libinterp/interp-core/octave-link.cc libinterp/interp-core/octave-link.h |
diffstat | 22 files changed, 497 insertions(+), 1048 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/main-window.cc Thu Apr 04 09:22:00 2013 -0400 @@ -42,7 +42,6 @@ #include "file-editor.h" #endif #include "main-window.h" -#include "octave-qt-link.h" #include "settings-dialog.h" #include "builtins.h" @@ -71,6 +70,9 @@ if (_octave_qt_event_listener) delete _octave_qt_event_listener; + octave_link::connect_link (0); + delete _octave_qt_link; + #ifdef HAVE_QSCINTILLA if (_file_editor) delete _file_editor; @@ -493,39 +495,6 @@ } void -main_window::handle_insert_debugger_pointer_request (const QString& file, int line) -{ -#ifdef HAVE_QSCINTILLA - _file_editor->handle_insert_debugger_pointer_request (file, line); -#endif -} - -void -main_window::handle_delete_debugger_pointer_request (const QString& file, int line) -{ -#ifdef HAVE_QSCINTILLA - _file_editor->handle_delete_debugger_pointer_request (file, line); -#endif -} - -void -main_window::handle_update_dbstop_marker_request (bool insert, - const QString& file, int line) -{ -#ifdef HAVE_QSCINTILLA - _file_editor->handle_update_dbstop_marker_request (insert, file, line); -#endif -} - -void -main_window::handle_edit_file_request (const QString& file) -{ -#ifdef HAVE_QSCINTILLA - _file_editor->handle_edit_file_request (file); -#endif -} - -void main_window::debug_continue () { octave_link::post_event (this, &main_window::debug_continue_callback); @@ -1190,27 +1159,31 @@ this, SLOT (handle_quit_debug_mode ())); - connect (_octave_qt_event_listener, - SIGNAL (insert_debugger_pointer_signal (const QString&, int)), this, + // FIXME -- is it possible to eliminate the event_listenter? + + _octave_qt_link = new octave_qt_link (); + + connect (_octave_qt_link, + SIGNAL (update_dbstop_marker_signal (bool, const QString&, int)), + _file_editor, + SLOT (handle_update_dbstop_marker_request (bool, const QString&, int))); + + connect (_octave_qt_link, + SIGNAL (edit_file_signal (const QString&)), + _file_editor, + SLOT (handle_edit_file_request (const QString&))); + + connect (_octave_qt_link, + SIGNAL (insert_debugger_pointer_signal (const QString&, int)), + _file_editor, SLOT (handle_insert_debugger_pointer_request (const QString&, int))); - connect (_octave_qt_event_listener, - SIGNAL (delete_debugger_pointer_signal (const QString&, int)), this, + connect (_octave_qt_link, + SIGNAL (delete_debugger_pointer_signal (const QString&, int)), + _file_editor, SLOT (handle_delete_debugger_pointer_request (const QString&, int))); - connect (_octave_qt_event_listener, - SIGNAL (update_dbstop_marker_signal (bool, const QString&, int)), - this, - SLOT (handle_update_dbstop_marker_request (bool, const QString&, int))); - - connect (_octave_qt_event_listener, - SIGNAL (edit_file_signal (const QString&)), - this, - SLOT (handle_edit_file_request(const QString&))); - - // FIXME -- is it possible to eliminate the event_listenter? - - octave_link::connect (new octave_qt_link ()); + octave_link::connect_link (_octave_qt_link); octave_link::register_event_listener (_octave_qt_event_listener); }
--- a/libgui/src/main-window.h Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/main-window.h Thu Apr 04 09:22:00 2013 -0400 @@ -50,6 +50,7 @@ #include "terminal-dockwidget.h" #include "documentation-dockwidget.h" #include "octave-qt-event-listener.h" +#include "octave-qt-link.h" /** * \class MainWindow @@ -107,10 +108,6 @@ void handle_entered_debug_mode (); void handle_quit_debug_mode (); - void handle_insert_debugger_pointer_request (const QString& file, int line); - void handle_delete_debugger_pointer_request (const QString& file, int line); - void handle_update_dbstop_marker_request (bool insert, const QString& file, int line); - void handle_edit_file_request (const QString& file); void debug_continue (); void debug_step_into (); void debug_step_over (); @@ -178,6 +175,8 @@ octave_qt_event_listener *_octave_qt_event_listener; + octave_qt_link *_octave_qt_link; + // Flag for closing whole application bool _closing; };
--- a/libgui/src/module.mk Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/module.mk Thu Apr 04 09:22:00 2013 -0400 @@ -73,6 +73,7 @@ src/moc-main-window.cc \ src/moc-octave-main-thread.cc \ src/moc-octave-qt-event-listener.cc \ + src/moc-octave-qt-link.cc \ src/moc-settings-dialog.cc \ src/moc-terminal-dockwidget.cc \ src/moc-color-picker.cc \
--- a/libgui/src/octave-gui.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-gui.cc Thu Apr 04 09:22:00 2013 -0400 @@ -80,7 +80,7 @@ int octave_start_gui (int argc, char *argv[]) { - dissociate_terminal (); + // dissociate_terminal (); QApplication application (argc, argv);
--- a/libgui/src/octave-main-thread.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-main-thread.cc Thu Apr 04 09:22:00 2013 -0400 @@ -35,36 +35,6 @@ #include "octave-main-thread.h" #include "octave-link.h" -static octave_value_list -dbstop_hook_fcn (const octave_value_list& args, int) -{ - octave_value_list retval; - - octave_link::update_breakpoint (true, args); - - return retval; -} - -static octave_value_list -dbclear_hook_fcn (const octave_value_list& args, int) -{ - octave_value_list retval; - - octave_link::update_breakpoint (false, args); - - return retval; -} - -static octave_value_list -edit_hook_fcn (const octave_value_list& args, int) -{ - octave_value_list retval; - - octave_link::edit_file (args); - - return retval; -} - octave_main_thread::octave_main_thread () : QThread () { } @@ -80,18 +50,6 @@ octave_initialize_interpreter (octave_cmdline_argc, octave_cmdline_argv, octave_embedded); - octave_value dbstop_fcn (new octave_builtin (dbstop_hook_fcn)); - octave_value dbstop_fcn_handle (new octave_fcn_handle (dbstop_fcn)); - Fadd_dbstop_hook (dbstop_fcn_handle); - - octave_value dbclear_fcn (new octave_builtin (dbclear_hook_fcn)); - octave_value dbclear_fcn_handle (new octave_fcn_handle (dbclear_fcn)); - Fadd_dbclear_hook (dbclear_fcn_handle); - - octave_value edit_fcn (new octave_builtin (edit_hook_fcn)); - octave_value edit_fcn_handle (new octave_fcn_handle (edit_fcn)); - Fadd_edit_hook (edit_fcn_handle); - // Prime the history list. octave_link::update_history ();
--- a/libgui/src/octave-qt-event-listener.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-qt-event-listener.cc Thu Apr 04 09:22:00 2013 -0400 @@ -54,35 +54,6 @@ } void -octave_qt_event_listener::insert_debugger_pointer (const std::string& file, - int line) -{ - emit insert_debugger_pointer_signal (QString::fromStdString (file), line); -} - -void -octave_qt_event_listener::delete_debugger_pointer (const std::string& file, - int line) -{ - emit delete_debugger_pointer_signal (QString::fromStdString (file), line); -} - -void -octave_qt_event_listener::update_dbstop_marker (bool insert, - const std::string& file, - int line) -{ - emit update_dbstop_marker_signal (insert, QString::fromStdString (file), - line); -} - -void -octave_qt_event_listener::edit_file (const std::string& file) -{ - emit edit_file_signal (QString::fromStdString (file)); -} - -void octave_qt_event_listener::about_to_exit () { qApp->quit ();
--- a/libgui/src/octave-qt-event-listener.h Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-qt-event-listener.h Thu Apr 04 09:22:00 2013 -0400 @@ -37,10 +37,6 @@ void current_directory_has_changed (const std::string& directory); void update_workspace (void); void update_history (void); - void insert_debugger_pointer (const std::string& file, int line); - void delete_debugger_pointer (const std::string& file, int line); - void update_dbstop_marker (bool insert, const std::string& file, int line); - void edit_file (const std::string& file); void about_to_exit (); void entered_debug_mode (); @@ -50,10 +46,6 @@ void current_directory_has_changed_signal (const QString& directory); void update_workspace_signal (void); void update_history_signal (void); - void insert_debugger_pointer_signal (const QString& file, int line); - void delete_debugger_pointer_signal (const QString& file, int line); - void update_dbstop_marker_signal (bool insert, const QString& file, int line); - void edit_file_signal (const QString& file); void entered_debug_mode_signal (); void quit_debug_mode_signal (); };
--- a/libgui/src/octave-qt-link.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-qt-link.cc Thu Apr 04 09:22:00 2013 -0400 @@ -26,13 +26,6 @@ #include <config.h> #endif -#include "cmd-edit.h" -#include "oct-env.h" -#include "oct-mutex.h" -#include "singleton-cleanup.h" -#include "symtab.h" -#include "toplev.h" - #include "octave-qt-link.h" octave_qt_link::octave_qt_link (void) @@ -65,74 +58,6 @@ } void -octave_qt_link::do_insert_debugger_pointer (const octave_value_list& args) -{ - if (event_listener) - { - if (args.length () == 1) - { - octave_scalar_map m = args(0).scalar_map_value (); - - if (! error_state) - { - octave_value ov_file = m.getfield ("file"); - octave_value ov_line = m.getfield ("line"); - - std::string file = ov_file.string_value (); - int line = ov_line.int_value (); - - if (! error_state) - { - event_listener->insert_debugger_pointer (file, line); - - do_process_events (); - } - else - ::error ("invalid struct in debug pointer callback"); - } - else - ::error ("expecting struct in debug pointer callback"); - } - else - ::error ("invalid call to debug pointer callback"); - } -} - -void -octave_qt_link::do_delete_debugger_pointer (const octave_value_list& args) -{ - if (event_listener) - { - if (args.length () == 1) - { - octave_scalar_map m = args(0).scalar_map_value (); - - if (! error_state) - { - octave_value ov_file = m.getfield ("file"); - octave_value ov_line = m.getfield ("line"); - - std::string file = ov_file.string_value (); - int line = ov_line.int_value (); - - if (! error_state) - { - event_listener->delete_debugger_pointer (file, line); - - do_process_events (); - } - else - ::error ("invalid struct in debug pointer callback"); - } - else - ::error ("expecting struct in debug pointer callback"); - } - else - ::error ("invalid call to debug pointer callback"); - } -} - -void octave_qt_link::do_pre_input_event (void) { do_update_workspace (); @@ -145,71 +70,40 @@ } void -octave_qt_link::do_enter_debugger_event (const octave_value_list& args) +octave_qt_link::do_enter_debugger_event (const std::string& file, int line) { - do_insert_debugger_pointer (args); + do_insert_debugger_pointer (file, line); } void -octave_qt_link::do_exit_debugger_event (const octave_value_list& args) +octave_qt_link::do_exit_debugger_event (const std::string& file, int line) { - do_delete_debugger_pointer (args); + do_delete_debugger_pointer (file, line); } void octave_qt_link::do_update_breakpoint (bool insert, - const octave_value_list& args) + const std::string& file, int line) { - if (event_listener) - { - if (args.length () == 1) - { - octave_scalar_map m = args(0).scalar_map_value (); - - if (! error_state) - { - octave_value ov_file = m.getfield ("file"); - octave_value ov_line = m.getfield ("line"); - - std::string file = ov_file.string_value (); - int line = ov_line.int_value (); + emit update_dbstop_marker_signal (insert, QString::fromStdString (file), line); +} - if (! error_state) - { - event_listener->update_dbstop_marker (insert, file, line); +bool +octave_qt_link::do_edit_file (const std::string& file) +{ + emit edit_file_signal (QString::fromStdString (file)); - do_process_events (); - } - else - ::error ("invalid struct in dbstop marker callback"); - } - else - ::error ("expecting struct in dbstop marker callback"); - } - else - ::error ("invalid call to dbstop marker callback"); - } + return true; } void -octave_qt_link::do_edit_file (const octave_value_list& args) +octave_qt_link::do_insert_debugger_pointer (const std::string& file, int line) { - if (event_listener) - { - if (args.length () == 1) - { - std::string file = args(0).string_value (); + emit insert_debugger_pointer_signal (QString::fromStdString (file), line); +} - if (! error_state) - { - event_listener->edit_file (file); - do_process_events (); - - } - else - ::error ("expecting file name in edit file callback"); - } - else - ::error ("invalid call to edit file callback"); - } +void +octave_qt_link::do_delete_debugger_pointer (const std::string& file, int line) +{ + emit delete_debugger_pointer_signal (QString::fromStdString (file), line); }
--- a/libgui/src/octave-qt-link.h Wed Apr 03 19:04:08 2013 -0700 +++ b/libgui/src/octave-qt-link.h Thu Apr 04 09:22:00 2013 -0400 @@ -27,15 +27,11 @@ #include <string> -class octave_mutex; - -#include "oct-obj.h" - -#include "event-queue.h" +#include <QObject> +#include <QString> #include "octave-link.h" #include "octave-main-thread.h" -#include "octave-event-listener.h" // \class OctaveLink // \brief Provides threadsafe access to octave. @@ -45,8 +41,10 @@ // buffering access operations to octave and executing them in the // readline event hook, which lives in the octave thread. -class octave_qt_link : public octave_link +class octave_qt_link : public QObject, public octave_link { + Q_OBJECT + public: octave_qt_link (void); @@ -57,18 +55,15 @@ void do_update_history (void); - void do_insert_debugger_pointer (const octave_value_list& args); - void do_delete_debugger_pointer (const octave_value_list& args); - void do_pre_input_event (void); void do_post_input_event (void); - void do_enter_debugger_event (const octave_value_list& args); - void do_exit_debugger_event (const octave_value_list& args); + void do_enter_debugger_event (const std::string& file, int line); + void do_exit_debugger_event (const std::string& file, int line); - void do_update_breakpoint (bool insert, const octave_value_list& args); + void do_update_breakpoint (bool insert, const std::string& file, int line); - void do_edit_file (const octave_value_list& args); + bool do_edit_file (const std::string& file); private: @@ -78,8 +73,22 @@ octave_qt_link& operator = (const octave_qt_link&); + void do_insert_debugger_pointer (const std::string& file, int line); + + void do_delete_debugger_pointer (const std::string& file, int line); + // Thread running octave_main. octave_main_thread *main_thread; + +signals: + + void update_dbstop_marker_signal (bool insert, const QString& file, int line); + + void edit_file_signal (const QString& file); + + void insert_debugger_pointer_signal (const QString&, int); + + void delete_debugger_pointer_signal (const QString&, int); }; -#endif // OCTAVELINK_H +#endif
--- a/libinterp/corefcn/__execute_edit_hook__.cc Wed Apr 03 19:04:08 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,143 +0,0 @@ -/* - -Copyright (C) 2013 John W. Eaton - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or (at -your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "defun.h" -#include "error.h" -#include "defun.h" -#include "hook-fcn.h" -#include "oct-obj.h" - -static hook_function_list edit_hook_functions; - -DEFUN (add_edit_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{id} =} add_edit_hook (@var{fcn})\n\ -@deftypefnx {Built-in Function} {@var{id} =} add_edit_hook (@var{fcn}, @var{data})\n\ -Add the named function or function handle @var{fcn} to the list of functions to call\n\ -to handle editing files. The function should have the form\n\ -\n\ -@example\n\ -@var{fcn} (@var{file}, @var{data})\n\ -@end example\n\ -\n\ -If @var{data} is omitted, Octave calls the function without one argument.\n\ -\n\ -The returned identifier may be used to remove the function handle from\n\ -the list of input hook functions.\n\ -@seealso{remove_edit_hook}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - octave_value user_data; - - if (nargin == 2) - user_data = args(1); - - hook_function hook_fcn (args(0), user_data); - - if (! error_state) - { - edit_hook_functions.insert (hook_fcn.id (), hook_fcn); - - retval = hook_fcn.id (); - } - else - error ("add_edit_hook: expecting string as first arg"); - } - else - print_usage (); - - return retval; -} - -DEFUN (remove_edit_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} remove_edit_hook (@var{name})\n\ -@deftypefnx {Built-in Function} {} remove_input_event_hook (@var{fcn_id})\n\ -Remove the named function or function handle with the given identifier\n\ -from the list of functions to call to handle editing files.\n\ -@seealso{add_edit_hook}\n\ -@end deftypefn") -{ - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - std::string hook_fcn_id = args(0).string_value (); - - bool warn = (nargin < 2); - - if (! error_state) - { - hook_function_list::iterator p - = edit_hook_functions.find (hook_fcn_id); - - if (p != edit_hook_functions.end ()) - edit_hook_functions.erase (p); - else if (warn) - warning ("remove_edit_hook: %s not found in list", - hook_fcn_id.c_str ()); - } - else - error ("remove_edit_hook: argument not valid as a hook function name or id"); - } - else - print_usage (); - - return retval; -} - -DEFUN (__execute_edit_hook__, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{status} =} __execute_edit_hook__ (@var{file})\n\ -Undocumented internal function.\n\ -@end deftypefn") -{ - octave_value retval; - - if (edit_hook_functions.empty ()) - retval = false; - else - { - edit_hook_functions.run (args); - - retval = true; - } - - return retval; -} - -/* -## No test needed for internal helper function. -%!assert (1) -*/
--- a/libinterp/corefcn/module.mk Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/corefcn/module.mk Thu Apr 04 09:22:00 2013 -0400 @@ -27,7 +27,6 @@ COREFCN_SRC = \ corefcn/__contourc__.cc \ corefcn/__dispatch__.cc \ - corefcn/__execute_edit_hook__.cc \ corefcn/__lin_interpn__.cc \ corefcn/__pchip_deriv__.cc \ corefcn/__qp__.cc \
--- a/libinterp/interp-core/module.mk Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interp-core/module.mk Thu Apr 04 09:22:00 2013 -0400 @@ -36,7 +36,6 @@ interp-core/mexproto.h \ interp-core/mxarray.in.h \ interp-core/octave-event-listener.h \ - interp-core/octave-link.h \ interp-core/oct-errno.h \ interp-core/oct-fstrm.h \ interp-core/oct-hdf5.h \ @@ -92,7 +91,6 @@ interp-core/ls-oct-binary.cc \ interp-core/ls-utils.cc \ interp-core/mex.cc \ - interp-core/octave-link.cc \ interp-core/oct-fstrm.cc \ interp-core/oct-iostrm.cc \ interp-core/oct-lvalue.cc \
--- a/libinterp/interp-core/octave-event-listener.h Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interp-core/octave-event-listener.h Thu Apr 04 09:22:00 2013 -0400 @@ -40,17 +40,6 @@ virtual void update_history (void) = 0; - virtual void - insert_debugger_pointer (const std::string& file, int line) = 0; - - virtual void - delete_debugger_pointer (const std::string& file, int line) = 0; - - virtual void - update_dbstop_marker (bool insert, const std::string& file, int line) = 0; - - virtual void edit_file (const std::string& file) = 0; - virtual void about_to_exit () = 0; virtual void entered_debug_mode () = 0;
--- a/libinterp/interp-core/octave-link.cc Wed Apr 03 19:04:08 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - -Copyright (C) 2013 John W. Eaton -Copyright (C) 2011-2012 Jacob Dawid -Copyright (C) 2011-2012 John P. Swensen - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "cmd-edit.h" -#include "oct-env.h" -#include "oct-mutex.h" -#include "singleton-cleanup.h" -#include "symtab.h" -#include "toplev.h" - -#include "octave-link.h" - -static int -octave_readline_hook (void) -{ - octave_link::entered_readline_hook (); - octave_link::generate_events (); - octave_link::process_events (); - octave_link::finished_readline_hook (); - - return 0; -} - -static void -octave_exit_hook (int) -{ - octave_link::about_to_exit (); -} - -octave_link *octave_link::instance = 0; - -octave_link::octave_link (void) - : event_listener (0), event_queue_mutex (new octave_mutex ()), - gui_event_queue (), last_cwd (), debugging (false) -{ - command_editor::add_event_hook (octave_readline_hook); - - octave_exit = octave_exit_hook; -} - -// OBJ should be a new object of a class that is derived from -// the base class octave_link. It will be cleaned up by octave_link. - -void -octave_link::connect (octave_link* obj) -{ - if (instance) - ::error ("octave_link is already linked!"); - else - instance = obj; - - singleton_cleanup_list::add (cleanup_instance); -} - -void -octave_link::do_register_event_listener (octave_event_listener *el) -{ - event_listener = el; -} - -void -octave_link::do_generate_events (void) -{ - std::string current_working_directory = octave_env::get_current_directory (); - - if (current_working_directory != last_cwd) - { - last_cwd = current_working_directory; - - if (event_listener) - event_listener->current_directory_has_changed (last_cwd); - } - - if (debugging != Vdebugging) - { - debugging = Vdebugging; - - if (event_listener) - { - if (debugging) - event_listener->entered_debug_mode (); - else - event_listener->quit_debug_mode (); - } - } -} - -void -octave_link::do_process_events (void) -{ - event_queue_mutex->lock (); - - gui_event_queue.run (); - - event_queue_mutex->unlock (); -} - -void -octave_link::do_about_to_exit (void) -{ - event_queue_mutex->lock (); - - gui_event_queue.discard (); - - event_queue_mutex->unlock (); - - if (event_listener) - event_listener->about_to_exit (); -} - -std::string -octave_link::do_last_working_directory (void) -{ - return last_cwd; -} - -bool -octave_link::instance_ok (void) -{ - return instance != 0; -}
--- a/libinterp/interp-core/octave-link.h Wed Apr 03 19:04:08 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,249 +0,0 @@ -/* - -Copyright (C) 2013 John W. Eaton -Copyright (C) 2011-2012 Jacob Dawid -Copyright (C) 2011-2012 John P. Swensen - -This file is part of Octave. - -Octave is free software; you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the -Free Software Foundation; either version 3 of the License, or (at your -option) any later version. - -Octave is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if !defined (octave_link_h) -#define octave_link_h 1 - -#include <string> - -class octave_mutex; - -#include "oct-obj.h" - -#include "event-queue.h" - -#include "octave-event-listener.h" - -// \class OctaveLink -// \brief Provides threadsafe access to octave. -// \author Jacob Dawid -// -// This class is a wrapper around octave and provides thread safety by -// buffering access operations to octave and executing them in the -// readline event hook, which lives in the octave thread. - -class octave_link -{ -protected: - - octave_link (void); - -public: - - virtual ~octave_link (void) { } - - static void register_event_listener (octave_event_listener *el) - { - if (instance_ok ()) - instance->do_register_event_listener (el); - } - - static void generate_events (void) - { - if (instance_ok ()) - instance->do_generate_events (); - } - - static void process_events (void) - { - if (instance_ok ()) - instance->do_process_events (); - } - - template <class T> - static void post_event (T *obj, void (T::*method) (void)) - { - if (instance_ok ()) - instance->do_post_event (obj, method); - } - - template <class T, class A> - static void post_event (T *obj, void (T::*method) (A), A arg) - { - if (instance_ok ()) - instance->do_post_event (obj, method, arg); - } - - template <class T, class A> - static void post_event (T *obj, void (T::*method) (const A&), const A& arg) - { - if (instance_ok ()) - instance->do_post_event (obj, method, arg); - } - - static void about_to_exit (void) - { - if (instance_ok ()) - instance->do_about_to_exit (); - } - - static void entered_readline_hook (void) - { - if (instance_ok ()) - instance->do_entered_readline_hook (); - } - - static void finished_readline_hook (void) - { - if (instance_ok ()) - instance->do_finished_readline_hook (); - } - - static std::string last_working_directory (void) - { - return instance_ok () - ? instance->do_last_working_directory () : std::string (); - } - - static void update_workspace (void) - { - if (instance_ok ()) - instance->do_update_workspace (); - } - - static void update_history (void) - { - if (instance_ok ()) - instance->do_update_history (); - } - - static void pre_input_event (void) - { - if (instance_ok ()) - instance->do_pre_input_event (); - } - - static void post_input_event (void) - { - if (instance_ok ()) - instance->do_post_input_event (); - } - - static void enter_debugger_event (const octave_value_list& args) - { - if (instance_ok ()) - instance->do_enter_debugger_event (args); - } - - static void exit_debugger_event (const octave_value_list& args) - { - if (instance_ok ()) - instance->do_exit_debugger_event (args); - } - - static void - update_breakpoint (bool insert, const octave_value_list& args) - { - if (instance_ok ()) - instance->do_update_breakpoint (insert, args); - } - - static void - edit_file (const octave_value_list& args) - { - if (instance_ok ()) - instance->do_edit_file (args); - } - - static void connect (octave_link *); - -private: - - static octave_link *instance; - - static void cleanup_instance (void) { delete instance; instance = 0; } - - // No copying! - - octave_link (const octave_link&); - - octave_link& operator = (const octave_link&); - - static bool instance_ok (void); - -protected: - - octave_event_listener *event_listener; - - // Semaphore to lock access to the event queue. - octave_mutex *event_queue_mutex; - - // Event Queue. - event_queue gui_event_queue; - - // Stores the last known current working directory of octave. - std::string last_cwd; - - bool debugging; - - void do_register_event_listener (octave_event_listener *oel); - - void do_generate_events (void); - void do_process_events (void); - - template <class T> - void do_post_event (T *obj, void (T::*method) (void)) - { - gui_event_queue.add_method (obj, method); - } - - template <class T, class A> - void do_post_event (T *obj, void (T::*method) (A), A arg) - { - gui_event_queue.add_method (obj, method, arg); - } - - template <class T, class A> - void do_post_event (T *obj, void (T::*method) (const A&), const A& arg) - { - gui_event_queue.add_method (obj, method, arg); - } - - void do_about_to_exit (void); - - void do_entered_readline_hook (void) { } - void do_finished_readline_hook (void) { } - - std::string do_last_working_directory (void); - - virtual void do_update_workspace (void) = 0; - - virtual void do_update_history (void) = 0; - - virtual void do_insert_debugger_pointer (const octave_value_list& args) = 0; - virtual void do_delete_debugger_pointer (const octave_value_list& args) = 0; - - virtual void do_pre_input_event (void) = 0; - virtual void do_post_input_event (void) = 0; - - virtual void do_enter_debugger_event (const octave_value_list& args) = 0; - virtual void do_exit_debugger_event (const octave_value_list& args) = 0; - - virtual void do_update_breakpoint (bool insert, - const octave_value_list& args) = 0; - - virtual void do_edit_file (const octave_value_list& args) = 0; -}; - -#endif // OCTAVELINK_H
--- a/libinterp/interpfcn/debug.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interpfcn/debug.cc Thu Apr 04 09:22:00 2013 -0400 @@ -37,9 +37,9 @@ #include "defun.h" #include "error.h" #include "help.h" -#include "hook-fcn.h" #include "input.h" #include "pager.h" +#include "octave-link.h" #include "oct-obj.h" #include "utils.h" #include "parse.h" @@ -186,17 +186,6 @@ return dbg_fcn; } -octave_value -location_info (const std::string& fname, int line) -{ - octave_scalar_map location_info_map; - - location_info_map.setfield ("file", fname); - location_info_map.setfield ("line", line); - - return octave_value (location_info_map); -} - static void parse_dbfunction_params (const char *who, const octave_value_list& args, std::string& symbol_name, bp_table::intmap& lines) @@ -285,201 +274,6 @@ return retval; } -static hook_function_list dbstop_hook_functions; -static hook_function_list dbclear_hook_functions; - -DEFUN (add_dbstop_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{id} =} add_dbstop_hook (@var{fcn})\n\ -@deftypefnx {Built-in Function} {@var{id} =} add_dbstop_hook (@var{fcn}, @var{data})\n\ -Add the named function or function handle @var{fcn} to the list of\n\ -functions to call when a debugger breakpoint is set. The function\n\ -should have the form\n\ -\n\ -@example\n\ -@var{fcn} (@var{location}, @var{data})\n\ -@end example\n\ -\n\ -in which @var{location} is a structure containing the following elements:\n\ -\n\ -@table @code\n\ -@item file\n\ -The name of the file where the breakpoint is located.\n\ -@item line\n\ -The line number corresponding to the breakpoint.\n\ -@end table\n\ -\n\ -If @var{data} is omitted when the hook function is added, the hook\n\ -function is called with a single argument.\n\ -\n\ -The returned identifier may be used to remove the function handle from\n\ -the list of input hook functions.\n\ -@seealso{remove_dbstop_hook}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - octave_value user_data; - - if (nargin == 2) - user_data = args(1); - - hook_function hook_fcn (args(0), user_data); - - if (! error_state) - { - dbstop_hook_functions.insert (hook_fcn.id (), hook_fcn); - - retval = hook_fcn.id (); - } - else - error ("add_dbstop_hook: expecting string as first arg"); - } - else - print_usage (); - - return retval; -} - -DEFUN (remove_dbstop_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} remove_dbstop_hook (@var{name})\n\ -@deftypefnx {Built-in Function} {} remove_dbstop_hook (@var{fcn_id})\n\ -Remove the named function or function handle with the given identifier\n\ -from the list of functions to call when a debugger breakpoint is set.\n\ -@seealso{add_dbstop_hook}\n\ -@end deftypefn") -{ - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - std::string hook_fcn_id = args(0).string_value (); - - bool warn = (nargin < 2); - - if (! error_state) - { - hook_function_list::iterator p - = dbstop_hook_functions.find (hook_fcn_id); - - if (p != dbstop_hook_functions.end ()) - dbstop_hook_functions.erase (p); - else if (warn) - warning ("remove_dbstop_hook: %s not found in list", - hook_fcn_id.c_str ()); - } - else - error ("remove_dbstop_hook: argument not valid as a hook function name or id"); - } - else - print_usage (); - - return retval; -} - -DEFUN (add_dbclear_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {@var{id} =} add_dbclear_hook (@var{fcn})\n\ -@deftypefnx {Built-in Function} {@var{id} =} add_dbclear_hook (@var{fcn}, @var{data})\n\ -Add the named function or function handle @var{fcn} to the list of\n\ -functions to call when a debugger breakpoint is cleared. The function\n\ -should have the form\n\ -\n\ -@example\n\ -@var{fcn} (@var{location}, @var{data})\n\ -@end example\n\ -\n\ -in which @var{location} is a structure containing the following elements:\n\ -\n\ -@table @code\n\ -@item file\n\ -The name of the file where the breakpoint is located.\n\ -@item line\n\ -The line number corresponding to the breakpoint.\n\ -@end table\n\ -\n\ -If @var{data} is omitted when the hook function is added, the hook\n\ -function is called with a single argument.\n\ -\n\ -The returned identifier may be used to remove the function handle from\n\ -the list of input hook functions.\n\ -@seealso{remove_dbclear_hook}\n\ -@end deftypefn") -{ - octave_value retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - octave_value user_data; - - if (nargin == 2) - user_data = args(1); - - hook_function hook_fcn (args(0), user_data); - - if (! error_state) - { - dbclear_hook_functions.insert (hook_fcn.id (), hook_fcn); - - retval = hook_fcn.id (); - } - else - error ("add_dbclear_hook: expecting string as first arg"); - } - else - print_usage (); - - return retval; -} - -DEFUN (remove_dbclear_hook, args, , - "-*- texinfo -*-\n\ -@deftypefn {Built-in Function} {} remove_dbclear_hook (@var{name})\n\ -@deftypefnx {Built-in Function} {} remove_dbclear_hook (@var{fcn_id})\n\ -Remove the named function or function handle with the given identifier\n\ -from the list of functions to call when a debugger breakpoint is cleared.\n\ -@seealso{add_dbclear_hook}\n\ -@end deftypefn") -{ - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 1 || nargin == 2) - { - std::string hook_fcn_id = args(0).string_value (); - - bool warn = (nargin < 2); - - if (! error_state) - { - hook_function_list::iterator p - = dbclear_hook_functions.find (hook_fcn_id); - - if (p != dbclear_hook_functions.end ()) - dbclear_hook_functions.erase (p); - else if (warn) - warning ("remove_dbclear_hook: %s not found in list", - hook_fcn_id.c_str ()); - } - else - error ("remove_dbclear_hook: argument not valid as a hook function name or id"); - } - else - print_usage (); - - return retval; -} - bp_table::intmap bp_table::do_add_breakpoint (const std::string& fname, const bp_table::intmap& line) @@ -513,8 +307,7 @@ std::string file = dbg_fcn->fcn_file_name (); if (! file.empty ()) - dbstop_hook_functions.run - (location_info (file, retval[i])); + octave_link::update_breakpoint (true, file, retval[i]); } } } @@ -569,8 +362,7 @@ cmds->delete_breakpoint (lineno); if (! file.empty ()) - dbclear_hook_functions.run - (location_info (file, lineno)); + octave_link::update_breakpoint (false, file, lineno); } } @@ -619,7 +411,7 @@ retval[i] = lineno; if (! file.empty ()) - dbclear_hook_functions.run (location_info (file, lineno)); + octave_link::update_breakpoint (false, file, lineno); } bp_set_iterator it = bp_set.find (fname);
--- a/libinterp/interpfcn/debug.h Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interpfcn/debug.h Thu Apr 04 09:22:00 2013 -0400 @@ -131,6 +131,4 @@ extern std::string get_file_line (const std::string& fname, size_t line); -extern octave_value location_info (const std::string& fname, int line); - #endif
--- a/libinterp/interpfcn/input.cc Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interpfcn/input.cc Thu Apr 04 09:22:00 2013 -0400 @@ -455,6 +455,12 @@ } static void +exit_debugger_handler (const std::pair<std::string, int>& arg) +{ + octave_link::exit_debugger_event (arg.first, arg.second); +} + +static void get_debug_input (const std::string& prompt) { unwind_protect frame; @@ -501,13 +507,10 @@ if (have_file) { - octave_value loc_info = location_info (nm, curr_debug_line); - - octave_value_list args (loc_info); + octave_link::enter_debugger_event (nm, curr_debug_line); - octave_link::enter_debugger_event (args); - - frame.add_fcn (octave_link::exit_debugger_event, args); + frame.add_fcn (exit_debugger_handler, + std::pair<std::string, int> (nm, curr_debug_line)); std::string line_buf = get_file_line (nm, curr_debug_line);
--- a/libinterp/interpfcn/module.mk Wed Apr 03 19:04:08 2013 -0700 +++ b/libinterp/interpfcn/module.mk Thu Apr 04 09:22:00 2013 -0400 @@ -16,6 +16,7 @@ interpfcn/load-path.h \ interpfcn/load-save.h \ interpfcn/ls-oct-ascii.h \ + interpfcn/octave-link.h \ interpfcn/oct-hist.h \ interpfcn/pager.h \ interpfcn/pr-output.h \ @@ -42,6 +43,7 @@ interpfcn/load-path.cc \ interpfcn/load-save.cc \ interpfcn/ls-oct-ascii.cc \ + interpfcn/octave-link.cc \ interpfcn/oct-hist.cc \ interpfcn/pager.cc \ interpfcn/pr-output.cc \
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/interpfcn/octave-link.cc Thu Apr 04 09:22:00 2013 -0400 @@ -0,0 +1,167 @@ +/* + +Copyright (C) 2013 John W. Eaton +Copyright (C) 2011-2012 Jacob Dawid +Copyright (C) 2011-2012 John P. Swensen + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "cmd-edit.h" +#include "defun.h" +#include "oct-env.h" +#include "oct-mutex.h" +#include "singleton-cleanup.h" +#include "symtab.h" +#include "toplev.h" + +#include "octave-link.h" + +static int +octave_readline_hook (void) +{ + octave_link::entered_readline_hook (); + octave_link::generate_events (); + octave_link::process_events (); + octave_link::finished_readline_hook (); + + return 0; +} + +static void +octave_exit_hook (int) +{ + octave_link::about_to_exit (); +} + +octave_link *octave_link::instance = 0; + +octave_link::octave_link (void) + : event_listener (0), event_queue_mutex (new octave_mutex ()), + gui_event_queue (), last_cwd (), debugging (false) +{ + command_editor::add_event_hook (octave_readline_hook); + + octave_exit = octave_exit_hook; +} + +// OBJ should be an object of a class that is derived from the base +// class octave_link, or 0 to disconnect the link. It is the +// responsibility of the caller to delete obj. + +void +octave_link::connect_link (octave_link* obj) +{ + if (obj && instance) + ::error ("octave_link is already linked!"); + else + instance = obj; +} + +void +octave_link::do_register_event_listener (octave_event_listener *el) +{ + event_listener = el; +} + +void +octave_link::do_generate_events (void) +{ + std::string current_working_directory = octave_env::get_current_directory (); + + if (current_working_directory != last_cwd) + { + last_cwd = current_working_directory; + + if (event_listener) + event_listener->current_directory_has_changed (last_cwd); + } + + if (debugging != Vdebugging) + { + debugging = Vdebugging; + + if (event_listener) + { + if (debugging) + event_listener->entered_debug_mode (); + else + event_listener->quit_debug_mode (); + } + } +} + +void +octave_link::do_process_events (void) +{ + event_queue_mutex->lock (); + + gui_event_queue.run (); + + event_queue_mutex->unlock (); +} + +void +octave_link::do_about_to_exit (void) +{ + event_queue_mutex->lock (); + + gui_event_queue.discard (); + + event_queue_mutex->unlock (); + + if (event_listener) + event_listener->about_to_exit (); +} + +std::string +octave_link::do_last_working_directory (void) +{ + return last_cwd; +} + +bool +octave_link::instance_ok (void) +{ + return instance != 0; +} + +DEFUN (__octave_link_edit_file__, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __octave_link_edit_file__ (@var{file})\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + if (args.length () == 1) + { + std::string file = args(0).string_value (); + + if (! error_state) + retval = octave_link::edit_file (file); + else + error ("expecting file name as argument"); + } + + return retval; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/interpfcn/octave-link.h Thu Apr 04 09:22:00 2013 -0400 @@ -0,0 +1,242 @@ +/* + +Copyright (C) 2013 John W. Eaton +Copyright (C) 2011-2012 Jacob Dawid +Copyright (C) 2011-2012 John P. Swensen + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if !defined (octave_link_h) +#define octave_link_h 1 + +#include <string> + +#include "event-queue.h" +#include "octave-event-listener.h" + +class octave_mutex; + +// \class OctaveLink +// \brief Provides threadsafe access to octave. +// \author Jacob Dawid +// +// This class is a wrapper around octave and provides thread safety by +// buffering access operations to octave and executing them in the +// readline event hook, which lives in the octave thread. + +class octave_link +{ +protected: + + octave_link (void); + +public: + + virtual ~octave_link (void) { } + + static void register_event_listener (octave_event_listener *el) + { + if (instance_ok ()) + instance->do_register_event_listener (el); + } + + static void generate_events (void) + { + if (instance_ok ()) + instance->do_generate_events (); + } + + static void process_events (void) + { + if (instance_ok ()) + instance->do_process_events (); + } + + template <class T> + static void post_event (T *obj, void (T::*method) (void)) + { + if (instance_ok ()) + instance->do_post_event (obj, method); + } + + template <class T, class A> + static void post_event (T *obj, void (T::*method) (A), A arg) + { + if (instance_ok ()) + instance->do_post_event (obj, method, arg); + } + + template <class T, class A> + static void post_event (T *obj, void (T::*method) (const A&), const A& arg) + { + if (instance_ok ()) + instance->do_post_event (obj, method, arg); + } + + static void about_to_exit (void) + { + if (instance_ok ()) + instance->do_about_to_exit (); + } + + static void entered_readline_hook (void) + { + if (instance_ok ()) + instance->do_entered_readline_hook (); + } + + static void finished_readline_hook (void) + { + if (instance_ok ()) + instance->do_finished_readline_hook (); + } + + static std::string last_working_directory (void) + { + return instance_ok () + ? instance->do_last_working_directory () : std::string (); + } + + static void update_workspace (void) + { + if (instance_ok ()) + instance->do_update_workspace (); + } + + static void update_history (void) + { + if (instance_ok ()) + instance->do_update_history (); + } + + static void pre_input_event (void) + { + if (instance_ok ()) + instance->do_pre_input_event (); + } + + static void post_input_event (void) + { + if (instance_ok ()) + instance->do_post_input_event (); + } + + static void enter_debugger_event (const std::string& file, int line) + { + if (instance_ok ()) + instance->do_enter_debugger_event (file, line); + } + + static void exit_debugger_event (const std::string& file, int line) + { + if (instance_ok ()) + instance->do_exit_debugger_event (file, line); + } + + static void + update_breakpoint (bool insert, const std::string& file, int line) + { + if (instance_ok ()) + instance->do_update_breakpoint (insert, file, line); + } + + static bool + edit_file (const std::string& file) + { + return instance_ok () ? instance->do_edit_file (file) : false; + } + + static void connect_link (octave_link *); + +private: + + static octave_link *instance; + + static void cleanup_instance (void) { delete instance; instance = 0; } + + // No copying! + + octave_link (const octave_link&); + + octave_link& operator = (const octave_link&); + + static bool instance_ok (void); + +protected: + + octave_event_listener *event_listener; + + // Semaphore to lock access to the event queue. + octave_mutex *event_queue_mutex; + + // Event Queue. + event_queue gui_event_queue; + + // Stores the last known current working directory of octave. + std::string last_cwd; + + bool debugging; + + void do_register_event_listener (octave_event_listener *oel); + + void do_generate_events (void); + void do_process_events (void); + + template <class T> + void do_post_event (T *obj, void (T::*method) (void)) + { + gui_event_queue.add_method (obj, method); + } + + template <class T, class A> + void do_post_event (T *obj, void (T::*method) (A), A arg) + { + gui_event_queue.add_method (obj, method, arg); + } + + template <class T, class A> + void do_post_event (T *obj, void (T::*method) (const A&), const A& arg) + { + gui_event_queue.add_method (obj, method, arg); + } + + void do_about_to_exit (void); + + void do_entered_readline_hook (void) { } + void do_finished_readline_hook (void) { } + + std::string do_last_working_directory (void); + + virtual void do_update_workspace (void) = 0; + + virtual void do_update_history (void) = 0; + + virtual void do_pre_input_event (void) = 0; + virtual void do_post_input_event (void) = 0; + + virtual void do_enter_debugger_event (const std::string& file, int line) = 0; + virtual void do_exit_debugger_event (const std::string& file, int line) = 0; + + virtual void do_update_breakpoint (bool insert, + const std::string& file, int line) = 0; + + virtual bool do_edit_file (const std::string& file) = 0; +}; + +#endif // OCTAVELINK_H
--- a/scripts/miscellaneous/edit.m Wed Apr 03 19:04:08 2013 -0700 +++ b/scripts/miscellaneous/edit.m Thu Apr 04 09:22:00 2013 -0400 @@ -563,7 +563,7 @@ ## Give the hook function a chance. If that fails, fall back ## on running an editor with the system function. - status = __execute_edit_hook__ (file); + status = __octave_link_edit_file__ (file); if (! status) system (sprintf (undo_string_escapes (editor),