comparison gui/src/octave-adapter/octave-link.h @ 14718:3df7ef0080c7 gui

Added event based processing and implement exit and change directory event. * octave-event-observer.h: Implements observer part for the observer pattern. * main-window.cc: Posting events instead of emulating keypresses. * octave-event.h: Added new event types. * octave-link: Subclassed octave_event_observer and implemented events. * src.pro: Added file for tracking.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 04 Jun 2012 01:42:58 +0200
parents 4ff6c21c18c4
children 89c64340e9ab
comparison
equal deleted inserted replaced
14716:572a707408b2 14718:3df7ef0080c7
70 #include <QVector> 70 #include <QVector>
71 #include <QSemaphore> 71 #include <QSemaphore>
72 #include <QObject> 72 #include <QObject>
73 #include <QStringListModel> 73 #include <QStringListModel>
74 #include <QTimer> 74 #include <QTimer>
75 #include <QQueue>
75 76
76 #include "workspace-model.h" 77 #include "workspace-model.h"
77 #include "octave-main-thread.h" 78 #include "octave-main-thread.h"
78 #include "octave-event.h" 79 #include "octave-event.h"
80 #include "octave-event-observer.h"
79 #include "symbol-information.h" 81 #include "symbol-information.h"
80 82
81 /** 83 /**
82 * \class OctaveLink 84 * \class OctaveLink
83 * \brief Provides threadsafe access to octave. 85 * \brief Provides threadsafe access to octave.
84 * \author Jacob Dawid 86 * \author Jacob Dawid
85 * This class is a wrapper around octave and provides threadsafety by 87 * This class is a wrapper around octave and provides threadsafety by
86 * buffering access operations to octave and executing them in the readline 88 * buffering access operations to octave and executing them in the readline
87 * even hook, which lives in the octave thread. 89 * even hook, which lives in the octave thread.
88 */ 90 */
89 class octave_link : public QObject 91 class octave_link : public QObject, public octave_event_observer
90 { 92 {
91 Q_OBJECT 93 Q_OBJECT
92 public: 94 public:
93 /** Provides a way to access the unique octave_link object. */ 95 /** Provides a way to access the unique octave_link object. */
94 static octave_link * 96 static octave_link *
127 * WARNING: Always acquire the symbol information before actually 129 * WARNING: Always acquire the symbol information before actually
128 * using it and make sure you release it properly afterwards. 130 * using it and make sure you release it properly afterwards.
129 */ 131 */
130 const QList <symbol_information>& get_symbol_information () const; 132 const QList <symbol_information>& get_symbol_information () const;
131 133
134 void process_events ();
135 void post_event (octave_event *e);
136 void event_accepted (octave_event *e) const;
137 void event_ignored (octave_event *e) const;
138
139
140 void request_working_directory_change (std::string directory);
141 void request_octave_exit ();
142
132 signals: 143 signals:
133 /** Emitted, whenever the working directory of octave changed. */ 144 /** Emitted, whenever the working directory of octave changed. */
134 void working_directory_changed (QString directory); 145 void working_directory_changed (QString directory);
135 146
136 private: 147 private:
152 QTimer _update_workspace_model_timer; 163 QTimer _update_workspace_model_timer;
153 164
154 /** Semaphore to lock access to the symbol information. */ 165 /** Semaphore to lock access to the symbol information. */
155 QSemaphore *_symbol_information_semaphore; 166 QSemaphore *_symbol_information_semaphore;
156 167
168 /** Semaphore to lock access to the event queue. */
169 QSemaphore *_event_queue_semaphore;
170
171 /** Buffer for queueing events until they will be processed. */
172 QQueue <octave_event *> _event_queue;
173
157 /** Stores the current symbol information. */ 174 /** Stores the current symbol information. */
158 QList <symbol_information> _symbol_information; 175 QList <symbol_information> _symbol_information;
159 176
160 /** Stores the last known current working directory of octave. */ 177 /** Stores the last known current working directory of octave. */
161 QString _current_working_directory; 178 QString _current_working_directory;