# HG changeset patch # User John W. Eaton # Date 1616708876 14400 # Node ID 76fdbe78884f230aaf821ee24df04e7ada011d83 # Parent 220c6c4a3533e41641d3ea070e0fa776dde7f8b8 allow event manager to handle display of execution exceptions * event-manager.h, event-manager.cc (event_manager::display_exception): New method. (interpreter_events::display_exception): New virtual method with default implementation. * error.cc (error_system::display_exception): Forward exception to event_manager::display_exception instead of diplaying directly on std::cerr stream. # HG changeset patch # User John W. Eaton # Date 1616708876 14400 # Thu Mar 25 17:47:56 2021 -0400 # Node ID 8ceecf4a4e51f8760b925b81c36e252bf4e1d601 # Parent 113c92fa77eb2b03270927812b20a19d10ae563e allow event manager to handle display of execution exceptions * event-manager.h, event-manager.cc (event_manager::display_exception): New method. (interpreter_events::display_exception): New virtual method with default implementation. * error.cc (error_system::display_exception): Forward exception to event_manager::display_exception instead of diplaying directly on std::cerr stream. diff --git a/libinterp/corefcn/error.cc b/libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc +++ b/libinterp/corefcn/error.cc @@ -43,6 +43,7 @@ #include "builtin-defun-decls.h" #include "defun.h" #include "error.h" +#include "event-manager.h" #include "input.h" #include "interpreter-private.h" #include "interpreter.h" @@ -921,8 +922,7 @@ namespace octave void error_system::display_exception (const execution_exception& ee) const { - if (m_beep_on_error) - os << "\a"; + // FIXME: How should we handle beep_on_error? ee.display (octave_diary); @@ -930,7 +930,9 @@ namespace octave // GUI or other client can receive error messages without needing to // capture them from std::cerr or some other stream. - ee.display (std::cerr); + event_manager& evmgr = m_interpreter.get_event_manager (); + + evmgr.display_exception (ee); } } diff --git a/libinterp/corefcn/event-manager.cc b/libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc +++ b/libinterp/corefcn/event-manager.cc @@ -27,6 +27,8 @@ # include "config.h" #endif +#include + #include "builtin-defun-decls.h" #include "cmd-edit.h" #include "defun.h" @@ -39,6 +41,8 @@ #include "pager.h" #include "syminfo.h" +#include "quit.h" + namespace octave { static int readline_event_hook (void) @@ -50,6 +54,11 @@ namespace octave return 0; } + void interpreter_events::display_exception (const execution_exception& ee) + { + ee.display (std::cerr); + } + event_manager::event_manager (interpreter& interp) : m_interpreter (interp), instance (nullptr), event_queue_mutex (new mutex ()), gui_event_queue (), diff --git a/libinterp/corefcn/event-manager.h b/libinterp/corefcn/event-manager.h --- a/libinterp/corefcn/event-manager.h +++ b/libinterp/corefcn/event-manager.h @@ -47,6 +47,7 @@ namespace octave typedef std::function fcn_callback; typedef std::function meth_callback; + class execution_exception; class symbol_info_list; // The methods in this class provide a way to pass signals to the GUI @@ -74,7 +75,7 @@ namespace octave // FIXME: audit this list of functions and determine whether they are // all necessary and whether there might be better names for them. - class interpreter_events + class OCTINTERP_API interpreter_events { public: @@ -198,6 +199,7 @@ namespace octave virtual void interpreter_output (const std::string& /*msg*/) { } + virtual void display_exception (const execution_exception& ee); virtual void gui_status_update (const std::string& /*feature*/, const std::string& /*status*/) { } @@ -514,6 +516,17 @@ namespace octave return false; } + bool display_exception (const execution_exception& ee) + { + if (enabled ()) + { + instance->display_exception (ee); + return true; + } + else + return false; + } + bool gui_status_update (const std::string& feature, const std::string& status) { if (enabled ()) diff -r 220c6c4a3533 -r 76fdbe78884f libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Thu Mar 25 16:25:31 2021 -0400 +++ b/libinterp/corefcn/error.cc Thu Mar 25 17:47:56 2021 -0400 @@ -43,6 +43,7 @@ #include "builtin-defun-decls.h" #include "defun.h" #include "error.h" +#include "event-manager.h" #include "input.h" #include "interpreter-private.h" #include "interpreter.h" @@ -921,8 +922,7 @@ void error_system::display_exception (const execution_exception& ee) const { - if (m_beep_on_error) - os << "\a"; + // FIXME: How should we handle beep_on_error? ee.display (octave_diary); @@ -930,7 +930,9 @@ // GUI or other client can receive error messages without needing to // capture them from std::cerr or some other stream. - ee.display (std::cerr); + event_manager& evmgr = m_interpreter.get_event_manager (); + + evmgr.display_exception (ee, m_beep_on_error); } } diff -r 220c6c4a3533 -r 76fdbe78884f libinterp/corefcn/event-manager.cc --- a/libinterp/corefcn/event-manager.cc Thu Mar 25 16:25:31 2021 -0400 +++ b/libinterp/corefcn/event-manager.cc Thu Mar 25 17:47:56 2021 -0400 @@ -27,6 +27,8 @@ # include "config.h" #endif +#include + #include "builtin-defun-decls.h" #include "cmd-edit.h" #include "defun.h" @@ -39,6 +41,8 @@ #include "pager.h" #include "syminfo.h" +#include "quit.h" + namespace octave { static int readline_event_hook (void) @@ -50,6 +54,15 @@ return 0; } + void interpreter_events::display_exception (const execution_exception& ee, + bool beep) + { + if (beep) + std::cerr << "\a"; + + ee.display (std::cerr); + } + event_manager::event_manager (interpreter& interp) : m_interpreter (interp), instance (nullptr), event_queue_mutex (new mutex ()), gui_event_queue (), diff -r 220c6c4a3533 -r 76fdbe78884f libinterp/corefcn/event-manager.h --- a/libinterp/corefcn/event-manager.h Thu Mar 25 16:25:31 2021 -0400 +++ b/libinterp/corefcn/event-manager.h Thu Mar 25 17:47:56 2021 -0400 @@ -47,6 +47,7 @@ typedef std::function fcn_callback; typedef std::function meth_callback; + class execution_exception; class symbol_info_list; // The methods in this class provide a way to pass signals to the GUI @@ -74,7 +75,7 @@ // FIXME: audit this list of functions and determine whether they are // all necessary and whether there might be better names for them. - class interpreter_events + class OCTINTERP_API interpreter_events { public: @@ -198,6 +199,8 @@ virtual void interpreter_output (const std::string& /*msg*/) { } + virtual void display_exception (const execution_exception& ee, + bool beep = false); virtual void gui_status_update (const std::string& /*feature*/, const std::string& /*status*/) { } @@ -514,6 +517,17 @@ return false; } + bool display_exception (const execution_exception& ee, bool beep = false) + { + if (enabled ()) + { + instance->display_exception (ee, beep); + return true; + } + else + return false; + } + bool gui_status_update (const std::string& feature, const std::string& status) { if (enabled ())