annotate libgui/src/octave-cmd.cc @ 27209:ac92aa74fa1a

eliminate some direct access to call stack in gui and octave_base_value * file-editor-tab.cc (file_editor_tab::exit_debug_and_clear): Eliminate direct access to call stack. * main-window.cc (main_window::rename_variable_callback, main_window::open_any_callback, main_window::force_refresh_workspace): Likewise. * octave-cmd.cc (octave_cmd_builtin::execute): Likewise. * octave-link.cc (octave_link::set_workspace): Likewise. * ov-base.cc (called_from_builtin): Likewise.
author John W. Eaton <jwe@octave.org>
date Mon, 01 Apr 2019 20:53:00 +0000
parents 24b7e6326e26
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
1 /*
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26117
diff changeset
3 Copyright (C) 2014-2019 Torsten
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
4
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
5 This file is part of Octave.
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24014
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24014
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
10 (at your option) any later version.
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
15 GNU General Public License for more details.
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
16
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24014
diff changeset
19 <https://www.gnu.org/licenses/>.
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
20
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
21 */
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
22
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
23 // Author: Torsten <ttl@justmail.de>
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
24
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21310
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
26 # include "config.h"
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
27 #endif
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
28
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
29 #include "octave-cmd.h"
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
30
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
31 #include "builtin-defun-decls.h"
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
32 #include "cmd-edit.h"
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
33 #include "interpreter-private.h"
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
34 #include "interpreter.h"
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
35 #include "octave-qt-link.h"
26117
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 25963
diff changeset
36 #include "syminfo.h"
19773
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
37 #include "utils.h"
034bcac0b61c use of C++ API for running a file (bug #42307)
Torsten <ttl@justmail.de>
parents:
diff changeset
38
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
39 namespace octave
21027
8000dacaea98 GUI: no more extra command queue for debug commands
Torsten <ttl@justmail.de>
parents: 20483
diff changeset
40 {
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
41 void octave_cmd_exec::execute (interpreter&)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
42 {
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
43 std::string pending_input = command_editor::get_current_line ();
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
44
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
45 command_editor::set_initial_input (pending_input);
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
46 command_editor::replace_line (m_cmd.toStdString ());
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
47 command_editor::redisplay ();
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
48 command_editor::accept_line ();
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
49 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
50
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
51 void octave_cmd_eval::execute (interpreter&)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
52 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
53 QString function_name = m_info.fileName ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
54 function_name.chop (m_info.suffix ().length () + 1);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
55 std::string file_path = m_info.absoluteFilePath ().toStdString ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
56
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
57 std::string pending_input = command_editor::get_current_line ();
21027
8000dacaea98 GUI: no more extra command queue for debug commands
Torsten <ttl@justmail.de>
parents: 20483
diff changeset
58
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
59 if (valid_identifier (function_name.toStdString ()))
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
60 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
61 // valid identifier: call as function with possibility to debug
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
62 std::string path = m_info.absolutePath ().toStdString ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
63 if (octave_qt_link::file_in_path (file_path, path))
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
64 command_editor::replace_line (function_name.toStdString ());
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
65 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
66 else
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
67 {
27017
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
68 interpreter& interp = __get_interpreter__ ("octave_cmd_eval::execute");
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
69 // no valid identifier: use equivalent of Fsource (), no debug possible
24b7e6326e26 move parse_fcn_file to interpreter; source_file to evaluator
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
70 interp.source_file (file_path);
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
71 command_editor::replace_line ("");
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
72 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
73
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
74 command_editor::set_initial_input (pending_input);
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
75 command_editor::redisplay ();
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
76
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
77 command_editor::accept_line ();
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
78 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
79
25701
9a385fab138e allow the gui to insert builtin functions into the cmd queue
Torsten <mttl@mailbox.org>
parents: 25402
diff changeset
80 void octave_cmd_builtin::execute (interpreter& interp)
9a385fab138e allow the gui to insert builtin functions into the cmd queue
Torsten <mttl@mailbox.org>
parents: 25402
diff changeset
81 {
25923
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
82 octave_value_list argout;
25703
7b4e99fbe9d4 include builtin functions without interpreter argument being into octave_cmd
Torsten <mttl@mailbox.org>
parents: 25701
diff changeset
83 if (m_callback_fi)
25923
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
84 argout = m_callback_fi (interp, m_argin, m_nargout);
25703
7b4e99fbe9d4 include builtin functions without interpreter argument being into octave_cmd
Torsten <mttl@mailbox.org>
parents: 25701
diff changeset
85 else if (m_callback_f)
25923
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
86 argout = m_callback_f (m_argin, m_nargout);
25723
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
87
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
88 switch (m_update)
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
89 {
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
90 case CMD_UPD_WORKSPACE:
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
91 {
27209
ac92aa74fa1a eliminate some direct access to call stack in gui and octave_base_value
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
92 tree_evaluator& tw
ac92aa74fa1a eliminate some direct access to call stack in gui and octave_base_value
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
93 = __get_evaluator__ ("octave_cmd_builtin::execute");
26117
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 25963
diff changeset
94
27209
ac92aa74fa1a eliminate some direct access to call stack in gui and octave_base_value
John W. Eaton <jwe@octave.org>
parents: 27017
diff changeset
95 octave_link::set_workspace (true, tw.get_symbol_info ());
25723
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
96 }
26117
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 25963
diff changeset
97 break;
25723
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
98
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
99 default:
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
100 break;
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
101 }
22544083fe2c use common callback for workspace actions initiated by gui
Torsten <mttl@mailbox.org>
parents: 25703
diff changeset
102
25923
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
103 if (m_nargout) // Return value expected: connect the related value
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
104 emit argout_signal (argout);
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
105 }
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
106
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
107 void octave_cmd_builtin::init_cmd_retval ()
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
108 {
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
109 if (m_nargout)
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
110 connect (this, SIGNAL (argout_signal (const octave_value_list&)),
a7511a1489b8 call octave functions with return value from GUI (bug #47585)
Torsten <mttl@mailbox.org>
parents: 25915
diff changeset
111 m_argout_receiver, m_argout_handler, Qt::QueuedConnection);
25701
9a385fab138e allow the gui to insert builtin functions into the cmd queue
Torsten <mttl@mailbox.org>
parents: 25402
diff changeset
112 }
9a385fab138e allow the gui to insert builtin functions into the cmd queue
Torsten <mttl@mailbox.org>
parents: 25402
diff changeset
113
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
114 void octave_cmd_debug::execute (interpreter& interp)
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
115 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
116 if (m_cmd == "step")
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
117 {
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25360
diff changeset
118 F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
119 Fdbstep (interp);
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
120 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
121 else if (m_cmd == "cont")
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
122 {
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25360
diff changeset
123 F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
124 Fdbcont (interp);
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
125 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
126 else if (m_cmd == "quit")
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
127 Fdbquit (interp);
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
128 else
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
129 {
25402
ef2b9d4abf4a eliminate some global variables from tree_evaluator
John W. Eaton <jwe@octave.org>
parents: 25360
diff changeset
130 F__db_next_breakpoint_quiet__ (interp, ovl (m_suppress_dbg_location));
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
131 Fdbstep (interp, ovl (m_cmd.toStdString ()));
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
132 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
133
25336
389757b7b6af eliminate redundant octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
134 command_editor::interrupt (true);
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
135 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
136
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
137 // add a command to the queue
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
138
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
139 void octave_command_queue::add_cmd (octave_cmd *cmd)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
140 {
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
141 // Get a guarded pointer from the pointer to the command object
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
142 QPointer<octave_cmd> cmd_gp (cmd);
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
143
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
144 // And add it to the command queue
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
145 m_queue_mutex.lock ();
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
146 m_queue.append (cmd_gp);
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
147 m_queue_mutex.unlock ();
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
148
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
149 if (m_processing.tryAcquire ()) // if callback not processing, post event
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
150 octave_link::post_event (this, &octave_command_queue::execute_command_callback);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
151 }
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
152
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
153 // callback for executing the command by the worker thread
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
154
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
155 void octave_command_queue::execute_command_callback (void)
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
156 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
157 bool repost = false; // flag for reposting event for this callback
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
158
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
159 if (! m_queue.isEmpty ()) // list can not be empty here, just to make sure
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
160 {
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
161 m_queue_mutex.lock (); // critical path
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
162
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
163 QPointer<octave_cmd> cmd_gp = m_queue.takeFirst ();
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
164
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
165 if (m_queue.isEmpty ())
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
166 m_processing.release (); // cmd queue empty, processing will stop
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
167 else
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
168 repost = true; // not empty, repost at end
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
169 m_queue_mutex.unlock ();
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
170
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
171 if (! cmd_gp.isNull ())
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
172 {
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
173 // The pointer to the command object is still valid
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
174
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
175 // FIXME: Could we store a reference to the interpreter in the
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
176 // octave_command_queue object? If so, where is the proper
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
177 // place to initialize that?
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
178 interpreter& interp = __get_interpreter__ ("octave_command_queue::execute_command_callback");
25360
bc5f225bc578 eliminate some global accesses to the breakpoint table
John W. Eaton <jwe@octave.org>
parents: 25336
diff changeset
179
25913
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
180 cmd_gp->execute (interp);
acce85499a46 check command objects in gui command queue if still valid before executing
Torsten <mttl@mailbox.org>
parents: 25723
diff changeset
181 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
182
25963
69050723c9bd destroy octave_cmd object after its execution (bug ##54882)
Torsten <mttl@mailbox.org>
parents: 25923
diff changeset
183 delete cmd_gp; // destroy the referred octave_cmd object
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
184 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
185
24718
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
186 if (repost) // queue not empty, so repost event for further processing
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
187 octave_link::post_event (this, &octave_command_queue::execute_command_callback);
ea1c88bd4430 move more GUI classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
188 }
21028
4a7d9c335402 GUI: move the command queue into a separate class
Torsten <ttl@justmail.de>
parents: 21027
diff changeset
189 }