Mercurial > hg > octave-lyh
changeset 13385:0b780509d3ac
Refactored code.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sat, 09 Apr 2011 12:16:57 +0200 |
parents | c834fd0128fb |
children | fc8f53c6994f |
files | gui//src/TerminalMdiSubWindow.cpp gui//src/TerminalMdiSubWindow.h |
diffstat | 2 files changed, 48 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/TerminalMdiSubWindow.cpp +++ b/gui//src/TerminalMdiSubWindow.cpp @@ -3,27 +3,18 @@ #include <QVBoxLayout> #include <QStringListModel> #include <QStringList> -bool is_inside_main_loop = false; -bool is_cleanup_complete = false; -extern bool quit_allowed; -bool threadRunning = true; void * octave_main_wrapper(void *ptr) { //MainWindow *mainWindow = (MainWindow*)ptr; int argc = 3; - const char* argv[] = {"octave", "-i", "--line-editing"}; + const char* argv[] = {"octave", "--interactive", "--line-editing"}; octave_main(argc,(char**)argv,1); switch_to_buffer (create_buffer (get_input_from_stdin ())); - quit_allowed = true; - is_inside_main_loop = true; main_loop(); - is_inside_main_loop = false; - - if (!is_cleanup_complete) - clean_up_and_exit(0); + clean_up_and_exit(0); return 0; } @@ -31,8 +22,8 @@ : QMdiSubWindow(parent), m_terminalWidget(0), isRunning(true) { + constructWindow(); establishOctaveLink(); - constructWindow(); } TerminalMdiSubWindow::~TerminalMdiSubWindow() { @@ -43,24 +34,20 @@ void TerminalMdiSubWindow::establishOctaveLink() { m_octaveLink = new OctaveLink(); pthread_create(&octave_thread, NULL, octave_main_wrapper, (void*)this); - pthread_create(&octave_monitor_thread, 0, TerminalMdiSubWindow::octave_monitor, this); + pthread_create(&octave_monitor_thread, 0, TerminalMdiSubWindow::octaveCallback, this); command_editor::add_event_hook(server_rl_event_hook_function); + + int fdm, fds; + if(openpty(&fdm, &fds, 0, 0, 0) < 0) { + fprintf (stderr, "oops!\n"); + } + dup2 (fds, 0); + dup2 (fds, 1); + dup2 (fds, 2); + m_terminalWidget->openTeletype(fdm); } void TerminalMdiSubWindow::constructWindow() { - - int fdm; - int fds; - - if ( openpty (&fdm, &fds, 0, 0, 0) < 0 ) - { - fprintf (stderr, "oops!\n"); - } - - dup2 (fds, 0); - dup2 (fds, 1); - dup2 (fds, 2); - setWindowTitle("Octave Session"); resize(900, 600); setWidget(new QWidget(this)); @@ -72,9 +59,6 @@ m_terminalWidget = new QTerminalWidget(0, hWidget); m_terminalWidget->setScrollBarPosition(QTerminalWidget::ScrollBarRight); - m_terminalWidget->setShellProgram("octave"); - // m_terminalWidget->startShellProgram(); - m_terminalWidget->openTeletype(fdm); m_terminalWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); m_terminalWidget->setColorScheme(QTerminalWidget::BlackOnLightYellow); @@ -118,70 +102,56 @@ model->setStringList(stringList); } -bool ui_can_interrupt = true; -void* TerminalMdiSubWindow::octave_monitor(void *octaveUI) { - TerminalMdiSubWindow* oui = (TerminalMdiSubWindow*)octaveUI; +void* TerminalMdiSubWindow::octaveCallback(void *window) { + TerminalMdiSubWindow* terminalWindow = (TerminalMdiSubWindow*)window; + + while(terminalWindow->isRunning) { - while ( oui->isRunning ) - { - // collect all the variable info + // Get a full variable list. std::vector<OctaveLink::VariableMetaData> variables = oct_octave_server.variableInfoList(); - if ( variables.size() > 0 ) - { - //qDebug("Update variables."); + if(variables.size()) { + // TODO: Update variable list model data. } - // Check whether any requested variables have been returned + // Check whether any requested variables have been returned. std::vector<OctaveLink::RequestedVariable> reqVars = oct_octave_server.requestedVariables(); - for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin() ; - it != reqVars.end() ; - it++ ) - { - std::cout << "Requested variable returned: " << (*it).name << std::endl; + for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); + it != reqVars.end(); it++ ) { + // TODO: Process requested variables. } - // collect history info + // Collect history list. string_vector historyList = oct_octave_server.getHistoryList(); - if( historyList.length() > 0 ) - { - //qDebug("Update history."); - oui->updateHistory(historyList); + if(historyList.length()) { + terminalWindow->updateHistory(historyList); } - // Put a marker in each buffer at the proper location + // Put a marker in each buffer at the proper location. int status = 0; - std::vector<OctaveLink::BreakPoint> bps = oct_octave_server.breakPointList(status); - if (status==0) - { - //MEditor::GetInstance()->process_breakpoint_list (bps); + std::vector<OctaveLink::BreakPoint> breakPoints = oct_octave_server.breakPointList(status); + if(status==0) { + //MEditor::GetInstance()->process_breakpoint_list (bps); } // Find out if a breakpoint is hit - static bool line_number = -1; - bool is_bp_hit = oct_octave_server.isBreakpointReached(status); - if (status==0 && is_bp_hit) - { - std::vector<OctaveLink::BreakPoint> hit_breakpoint = oct_octave_server.reachedBreakpoint(); - if (hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != line_number)) - { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); - line_number = hit_breakpoint[0].lineNumber; - } + static bool lineNumber = -1; + bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); + if((status==0) && hitBreakPoint) { + std::vector<OctaveLink::BreakPoint> hit_breakpoint = oct_octave_server.reachedBreakpoint(); + + if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + //MEditor::GetInstance()->add_breakpoint_marker(hit_breakpoint[0], BP_MARKER_TYPE_HIT); + lineNumber = hit_breakpoint[0].lineNumber; + } } - else if (status==0 && line_number>0) - { - //MEditor::GetInstance()->remove_hit_breakpoint_marker (); - line_number = -1; + else if((status==0) && lineNumber>0) { + //MEditor::GetInstance()->remove_hit_breakpoint_marker (); + lineNumber = -1; } - if( global_command == 0 ) - ui_can_interrupt = true; + usleep(100000); + } - usleep(100000); - } - - //oui->threadEnded = 1; - std::cout << "Thread ended" << std::endl; - return 0; + return 0; }
--- a/gui//src/TerminalMdiSubWindow.h +++ b/gui//src/TerminalMdiSubWindow.h @@ -56,18 +56,8 @@ class TerminalMdiSubWindow : public QMdiSubWindow { Q_OBJECT public: - /** - * Stops the monitor thread. - */ - void stopMonitorRunning(void) { this->isRunning = false; } - - /** - * Checks if the monitor thread is currently running. - */ - bool isMonitorRunning() { return this->isRunning; } - void updateHistory(string_vector historyEntries); - static void* octave_monitor(void *octaveUI); + static void* octaveCallback(void *octaveUI); TerminalMdiSubWindow(QWidget *parent = 0); ~TerminalMdiSubWindow();