Mercurial > hg > octave-terminal
changeset 13393:98ff5fbd9312
Converted global octave_server instance into singleton.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 11 Apr 2011 13:57:16 +0200 |
parents | b773f4dce153 |
children | 7a5998cebef3 |
files | gui//src/MainWindow.cpp gui//src/MainWindow.h gui//src/OctaveLink.cpp gui//src/OctaveLink.h |
diffstat | 4 files changed, 17 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/MainWindow.cpp +++ b/gui//src/MainWindow.cpp @@ -47,8 +47,6 @@ void MainWindow::establishOctaveLink() { //QMetaObject::invokeMethod(this, "setStatus", Q_ARG(QString, QString("Establishing Octave link.."))); - m_octaveLink = new OctaveLink(); - m_octaveMainThread = new OctaveMainThread(this); m_octaveMainThread->start();
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -98,7 +98,6 @@ HistoryDockWidget *m_historyDockWidget; // Threads for running octave and managing the data interaction. - OctaveLink *m_octaveLink; OctaveMainThread *m_octaveMainThread; OctaveCallbackThread *m_octaveCallbackThread; bool m_isRunning; @@ -134,36 +133,39 @@ while(m_mainWindow->isRunning()) { // Get a full variable list. - std::vector<OctaveLink::VariableMetaData> variables = oct_octave_server.variableInfoList(); + std::vector<OctaveLink::VariableMetaData> variables + = OctaveLink::instance()->variableInfoList(); if(variables.size()) { // TODO: Update variables view. } // Check whether any requested variables have been returned. - std::vector<OctaveLink::RequestedVariable> reqVars = oct_octave_server.requestedVariables(); + std::vector<OctaveLink::RequestedVariable> reqVars + = OctaveLink::instance()->requestedVariables(); + for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); it != reqVars.end(); it++ ) { // TODO: Process requested variables. } // Collect history list. - string_vector historyList = oct_octave_server.getHistoryList(); + string_vector historyList = OctaveLink::instance()->getHistoryList(); if(historyList.length()) { m_mainWindow->historyDockWidget()->updateHistory(historyList); } // Put a marker in each buffer at the proper location. int status = 0; - std::vector<OctaveLink::BreakPoint> breakPoints = oct_octave_server.breakPointList(status); + std::vector<OctaveLink::BreakPoint> breakPoints = OctaveLink::instance()->breakPointList(status); if(status==0) { //MEditor::GetInstance()->process_breakpoint_list (bps); } // Find out if a breakpoint is hit static bool lineNumber = -1; - bool hitBreakPoint = oct_octave_server.isBreakpointReached(status); + bool hitBreakPoint = OctaveLink::instance()->isBreakpointReached(status); if((status==0) && hitBreakPoint) { - std::vector<OctaveLink::BreakPoint> hit_breakpoint = oct_octave_server.reachedBreakpoint(); + std::vector<OctaveLink::BreakPoint> hit_breakpoint = OctaveLink::instance()->reachedBreakpoint(); if(hit_breakpoint.size() > 0 && (hit_breakpoint[0].lineNumber != lineNumber)) { //MEditor::GetInstance()->remove_hit_breakpoint_marker ();
--- a/gui//src/OctaveLink.cpp +++ b/gui//src/OctaveLink.cpp @@ -83,7 +83,7 @@ #include <QFileInfo> -OctaveLink oct_octave_server; +OctaveLink OctaveLink::m_singleton; static octave_user_code * get_user_code (const std::string& fname = std::string ()) @@ -116,14 +116,14 @@ // TODO: No need to run too quickly. The documentation says it will run // at most 10 times per second. This may be too fast and we will need to // artificially slow it down somehow. Not sure at this time how. - oct_octave_server.processOctaveServerData(); + OctaveLink::instance()->processOctaveServerData(); return 0; } bool server_rl_is_processing(void) { - return oct_octave_server.isProcessing(); + return OctaveLink::instance()->isProcessing(); } //*************************************************************************
--- a/gui//src/OctaveLink.h +++ b/gui//src/OctaveLink.h @@ -46,6 +46,7 @@ class OctaveLink { public: + static OctaveLink *instance() { return &m_singleton; } /** * Enumeration used to identify breakpoint actions */ @@ -108,9 +109,6 @@ } } VariableMetaData; - OctaveLink(); - ~OctaveLink(); - bool isProcessing(void) { return m_isProcessingServerData; } // Functions used to access data form the client side. @@ -201,6 +199,9 @@ int setHistoryList(void); private: + OctaveLink(); + ~OctaveLink(); + /** Mutex variable used to protect access to internal class data. */ pthread_mutex_t m_serverMutex; @@ -235,12 +236,11 @@ int m_previousHistoryLength; bool m_isProcessingServerData; + static OctaveLink m_singleton; }; int server_rl_event_hook_function(void); bool server_rl_is_processing(void); -extern OctaveLink oct_octave_server; - #endif // OCTAVELINK_H