annotate libgui/src/interpreter-qobject.cc @ 27262:d67f369b3074

use shared_ptr to manage octave_link_events object * octave-link.h, octave-link.cc (octave_link::instance): Now a shared_ptr<octave_link_events> object. Change all uses. (octave_link::enable): (octave_link::connect_link): (octave_link::disconnect_link): Delete. * interpreter-qobject.h, interpreter-qobject.cc (interpreter_qobject::m_qt_link): Now a shared_ptr<octave_qt_link_events> object. Change all uses. (interpreter_qobject::execute): Also enable link after connecting. * interpreter.cc (interpreter::cleanup): Disable m_octave_link instead of disconnecting.
author John W. Eaton <jwe@octave.org>
date Thu, 18 Jul 2019 09:58:41 -0400
parents dccdc3b001a2
children 99aa1bcb8848
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 Copyright (C) 2013-2019 John W. Eaton
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 Copyright (C) 2011-2019 Jacob Dawid
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 This file is part of Octave.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 Octave is free software: you can redistribute it and/or modify it
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 under the terms of the GNU General Public License as published by
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 (at your option) any later version.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 WITHOUT ANY WARRANTY; without even the implied warranty of
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 GNU General Public License for more details.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 along with Octave; see the file COPYING. If not, see
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 <https://www.gnu.org/licenses/>.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 */
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #if defined (HAVE_CONFIG_H)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 # include "config.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #endif
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #include "interpreter-qobject.h"
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
29 #include "octave-qobject.h"
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
30 #include "octave-qt-link.h"
27197
b8c0d5ad024f refactor and rename some qt application objects
John W. Eaton <jwe@octave.org>
parents: 27196
diff changeset
31 #include "qt-application.h"
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "input.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "interpreter.h"
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 namespace octave
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 {
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
38 interpreter_qobject::interpreter_qobject (base_qobject *oct_qobj)
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
39 : QObject (), m_octave_qobject (oct_qobj),
27260
5ac60319575b separate octave_link event queue from events and actions
John W. Eaton <jwe@octave.org>
parents: 27218
diff changeset
40 m_qt_link (new octave_qt_link_events ())
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
41 { }
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
42
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
43 void interpreter_qobject::execute (void)
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
44 {
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
45 // The Octave application context owns the interpreter.
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
46
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
47 qt_application& app_context = m_octave_qobject->app_context ();
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
48
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
49 interpreter& interp = app_context.create_interpreter ();
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
50
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
51 octave_link& olnk = interp.get_octave_link ();
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
52
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27260
diff changeset
53 olnk.connect_link (m_qt_link);
27262
d67f369b3074 use shared_ptr to manage octave_link_events object
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
54 olnk.enable ();
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
55
27262
d67f369b3074 use shared_ptr to manage octave_link_events object
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
56 connect (qt_link (), SIGNAL (confirm_shutdown_signal (void)),
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
57 m_octave_qobject, SLOT (confirm_shutdown_octave (void)));
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
58
27262
d67f369b3074 use shared_ptr to manage octave_link_events object
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
59 connect (qt_link (),
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
60 SIGNAL (copy_image_to_clipboard_signal (const QString&, bool)),
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
61 m_octave_qobject,
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
62 SLOT (copy_image_to_clipboard (const QString&, bool)));
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 int exit_status = 0;
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 try
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 // Final initialization.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 interp.initialize ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
72 if (app_context.start_gui_p ())
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 input_system& input_sys = interp.get_input_system ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 input_sys.PS1 (">> ");
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 input_sys.PS2 ("");
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 if (interp.initialized ())
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 // The interpreter should be completely ready at this point so let
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 // the GUI know.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 emit octave_ready_signal ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 // Start executing commands in the command window.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 exit_status = interp.execute ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 catch (const exit_exception& ex)
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 {
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 exit_status = ex.exit_status ();
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 }
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 // Whether or not initialization succeeds we need to clean up the
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 // interpreter once we are done with it.
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
100 app_context.delete_interpreter ();
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 emit octave_finished_signal (exit_status);
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 }
27218
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
104
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
105 void interpreter_qobject::confirm_shutdown (bool closenow)
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
106 {
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
107 // Wait for link thread to go to sleep state.
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
108 m_qt_link->lock ();
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
109
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
110 m_qt_link->shutdown_confirmation (closenow);
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
111
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
112 m_qt_link->unlock ();
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
113
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
114 // Awake the worker thread so that it continues shutting down (or not).
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
115 m_qt_link->wake_all ();
a044202208af more refactoring of GUI classes that manage the interpreter
John W. Eaton <jwe@octave.org>
parents: 27197
diff changeset
116 }
27196
d993642352d0 rename octave_interpreter object in GUI
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 }