annotate libinterp/interpfcn/octave-link.cc @ 16485:8b783661e03f

improve exit sequence for GUI * octave-link.h, octave-link.cc (octave_link::accepting_events): Delete variable and all uses. (octave_link::link_enabled): New data member. (octave_link::octave_link): Don't set octave_exit. Initialize link_enabled. (octave_link::do_exit): Delete definition. Now pure virtual. Return bool. (octave_link::exit): Call instance->do_exit. (octave_link::enabled): New function. (ocave_link::process_events): New arg, disable. Optionally disable event processing. Use octave_link::enabled instead of instance_ok everywhere except for octave_link::exit. (octave_link::cleanup_instance): Delete. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::octave_qt_link): Accept thread as argument. Don't connect main_thread::finished signal. (octave_qt_link::~octave_qt_link): Don't delete main_thread. (octave_qt_link::do_exit): Emit exit_signal and return true. (octave_qt_link::exit_signal: New signal. (octave_qt_link::void octave_thread_finished_signal): Delete. * main-window.h, main-window.cc (main_window::_octave_main_thread): New member variable. (main_window::main_window): Initialize _octave_main_thread and _octave_qt_link to 0. (main_window::~main_window): Don't call octave_link::connect_link. Delete _octave_main_thread. (main_window::exit): Accept exit status as argument and call QApplication::exit instead of quit. (main_window::construct): Don't connect qApp::aboutToQuit to main_window::prepare_to_exit. (main_window::construct_octave_qt_link): Create _octave_main_thread and pass to _octave_qt_link. Don't connect _octave_qt_link::octave_thread_finished to main_window::exit. Connect _octave_qt_link::exit_signal to main_window::exit. * toplev.h, toplev.cc (main_loop): If quitting_gracefully, just return exit status instead of calling clean_up_and_exit. (do_octave_atexit): Now static. Call octave_link::process_events with disable arg set to true. (octave_atexit_functions): Now static. (clean_up_and_exit): New argument, safe_to_return. Call octave_link::exit and possibly return or wait for octave_link::exit to terminate the process. * octave.cc (octave_execute_interpreter): Don't alter return value from main_loop. Pass safe_to_return = true to clean_up_and_exit. Return retval instead of 0. (octave_initialize_interpreter): Don't call atexit.
author John W. Eaton <jwe@octave.org>
date Tue, 09 Apr 2013 23:08:24 -0400
parents 7a71ea0b7ae9
children 7f2395651a1c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
1 /*
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
2
16415
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
3 Copyright (C) 2013 John W. Eaton
15204
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
4 Copyright (C) 2011-2012 Jacob Dawid
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
5 Copyright (C) 2011-2012 John P. Swensen
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
6
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
7 This file is part of Octave.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
8
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
9 Octave is free software; you can redistribute it and/or modify it
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
10 under the terms of the GNU General Public License as published by the
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
11 Free Software Foundation; either version 3 of the License, or (at your
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
12 option) any later version.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
13
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
14 Octave is distributed in the hope that it will be useful, but WITHOUT
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
17 for more details.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
18
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
19 You should have received a copy of the GNU General Public License
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
20 along with Octave; see the file COPYING. If not, see
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
21 <http://www.gnu.org/licenses/>.
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
22
359098ad343e update copyright notices in libgui directory
John W. Eaton <jwe@octave.org>
parents: 15196
diff changeset
23 */
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
24
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
25 #ifdef HAVE_CONFIG_H
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
26 #include <config.h>
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
27 #endif
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
28
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
29 #include "cmd-edit.h"
16420
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
30 #include "defun.h"
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
31 #include "oct-env.h"
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
32 #include "oct-mutex.h"
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
33 #include "singleton-cleanup.h"
15155
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
34 #include "toplev.h"
9e62d5a3a45e partial cleanup of include files in gui sources
John W. Eaton <jwe@octave.org>
parents: 15041
diff changeset
35
14707
674740c44c09 Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14703
diff changeset
36 #include "octave-link.h"
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
37
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
38 static int
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
39 octave_readline_hook (void)
14668
6a6733a55982 Removed unused classes and added octave loop hook.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14664
diff changeset
40 {
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
41 octave_link::entered_readline_hook ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
42 octave_link::generate_events ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
43 octave_link::process_events ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
44 octave_link::finished_readline_hook ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
45
14671
f346343654a4 Settings readline event hook and fixed race condition.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14670
diff changeset
46 return 0;
14668
6a6733a55982 Removed unused classes and added octave loop hook.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14664
diff changeset
47 }
6a6733a55982 Removed unused classes and added octave loop hook.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14664
diff changeset
48
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
49 octave_link *octave_link::instance = 0;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
50
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
51 octave_link::octave_link (void)
16479
7a71ea0b7ae9 eliminate event listener class
John W. Eaton <jwe@octave.org>
parents: 16468
diff changeset
52 : event_queue_mutex (new octave_mutex ()), gui_event_queue (),
16485
8b783661e03f improve exit sequence for GUI
John W. Eaton <jwe@octave.org>
parents: 16479
diff changeset
53 debugging (false), link_enabled (true)
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
54 {
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
55 command_editor::add_event_hook (octave_readline_hook);
16415
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
56 }
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
57
16421
40d1ddca4db5 improve use of octave_link
John W. Eaton <jwe@octave.org>
parents: 16420
diff changeset
58 // OBJ should be an object of a class that is derived from the base
40d1ddca4db5 improve use of octave_link
John W. Eaton <jwe@octave.org>
parents: 16420
diff changeset
59 // class octave_link, or 0 to disconnect the link. It is the
40d1ddca4db5 improve use of octave_link
John W. Eaton <jwe@octave.org>
parents: 16420
diff changeset
60 // responsibility of the caller to delete obj.
16415
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
61
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
62 void
16421
40d1ddca4db5 improve use of octave_link
John W. Eaton <jwe@octave.org>
parents: 16420
diff changeset
63 octave_link::connect_link (octave_link* obj)
16415
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
64 {
16421
40d1ddca4db5 improve use of octave_link
John W. Eaton <jwe@octave.org>
parents: 16420
diff changeset
65 if (obj && instance)
16415
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
66 ::error ("octave_link is already linked!");
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
67 else
70032fc70bee move octave-link and octave-event-listener classes to libinterp
John W. Eaton <jwe@octave.org>
parents: 16399
diff changeset
68 instance = obj;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
69 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
70
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
71 void
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
72 octave_link::do_generate_events (void)
14719
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14718
diff changeset
73 {
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14718
diff changeset
74 }
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14718
diff changeset
75
89c64340e9ab Extended event based communication model.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14718
diff changeset
76 void
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
77 octave_link::do_process_events (void)
14718
3df7ef0080c7 Added event based processing and implement exit and change directory event.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
78 {
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
79 event_queue_mutex->lock ();
14875
3fd857c284fe Editor now gets focussed when opening a file.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14804
diff changeset
80
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
81 gui_event_queue.run ();
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
82
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
83 event_queue_mutex->unlock ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
84 }
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
85
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
86 void
16479
7a71ea0b7ae9 eliminate event listener class
John W. Eaton <jwe@octave.org>
parents: 16468
diff changeset
87 octave_link::do_discard_events (void)
14718
3df7ef0080c7 Added event based processing and implement exit and change directory event.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
88 {
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
89 event_queue_mutex->lock ();
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
90
15402
7f423c6111c6 refactor GUI event handling to use new event_queue class
John W. Eaton <jwe@octave.org>
parents: 15388
diff changeset
91 gui_event_queue.discard ();
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
92
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
93 event_queue_mutex->unlock ();
16479
7a71ea0b7ae9 eliminate event listener class
John W. Eaton <jwe@octave.org>
parents: 16468
diff changeset
94 }
15371
eec0d1fcba4f use Octave singleton style for octave_link class
John W. Eaton <jwe@octave.org>
parents: 15204
diff changeset
95
16420
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
96 DEFUN (__octave_link_edit_file__, args, ,
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
97 "-*- texinfo -*-\n\
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
98 @deftypefn {Built-in Function} {} __octave_link_edit_file__ (@var{file})\n\
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
99 Undocumented internal function.\n\
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
100 @end deftypefn")
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
101 {
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
102 octave_value retval;
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
103
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
104 if (args.length () == 1)
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
105 {
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
106 std::string file = args(0).string_value ();
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
107
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
108 if (! error_state)
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
109 retval = octave_link::edit_file (file);
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
110 else
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
111 error ("expecting file name as argument");
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
112 }
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
113
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
114 return retval;
81ec95768520 use octave-link instead of hook for edit function
John W. Eaton <jwe@octave.org>
parents: 16415
diff changeset
115 }