diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-28 18:28:19 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-28 18:28:19 -0500 |
commit | 65ea633f475c7ab2b524dc1ffb369f6607df3e6b (patch) | |
tree | 8fac782af0723eba4e3110cafe59cb521444eaa2 /clients | |
parent | 8392c611054a5bb058cd778163a7aa4ef8311c94 (diff) | |
download | ulab-65ea633f475c7ab2b524dc1ffb369f6607df3e6b.tar.gz ulab-65ea633f475c7ab2b524dc1ffb369f6607df3e6b.zip |
Convert servers to cooperative multitasking
Diffstat (limited to 'clients')
-rw-r--r-- | clients/tde/src/app/remotemdi.cpp | 11 | ||||
-rw-r--r-- | clients/tde/src/app/views/instrumentview.cpp | 28 | ||||
-rw-r--r-- | clients/tde/src/app/views/instrumentview.h | 5 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaview/part.cpp | 119 |
4 files changed, 97 insertions, 66 deletions
diff --git a/clients/tde/src/app/remotemdi.cpp b/clients/tde/src/app/remotemdi.cpp index 11ab75e..3ecf181 100644 --- a/clients/tde/src/app/remotemdi.cpp +++ b/clients/tde/src/app/remotemdi.cpp @@ -343,7 +343,12 @@ void RemoteMDI::childWindowCloseRequest(KMdiChildView *pWnd) { // Give the child a chance to finish what it was doing and exit cleanly (i.e. without crashing!) iview->closeConnections(); iview->hide(); - KMdiMainFrm::childWindowCloseRequest(pWnd); + + // RAJA FIXME + // Executing KMdiMainFrm::childWindowCloseRequest(pWnd) here will probably cause a crash + // We need to call this AFTER control has been returned to the main event loop at least once + // This is related to my lack of proper returning to the event loop, which MUST BE FIXED +// KMdiMainFrm::childWindowCloseRequest(pWnd); // RAJA UNCOMMENT ME } } @@ -363,11 +368,11 @@ void RemoteMDI::closeSpecifiedWindow(KMdiChildView *window) { if (window) { // Notify the status bar of the removal of the window statusBar()->message(i18n("%1 removed").arg(window->tabCaption())); - + // We could also call removeWindowFromMdi, but it doesn't delete the // pointer. This way, we're sure that the view will get deleted. closeWindow(window); - + // Synchronize combo box if (m_pCurrentWindow) { currentChanged(m_pCurrentWindow); diff --git a/clients/tde/src/app/views/instrumentview.cpp b/clients/tde/src/app/views/instrumentview.cpp index 68b469a..ca3c853 100644 --- a/clients/tde/src/app/views/instrumentview.cpp +++ b/clients/tde/src/app/views/instrumentview.cpp @@ -15,6 +15,7 @@ InstrumentView::InstrumentView(const TQString &library, TQWidget *parentWidget, : KMdiChildView(parentWidget, name, f) , m_libraryName(library) , m_instrumentPart( 0 ) + , m_canary( NULL ) { init(); } @@ -23,12 +24,15 @@ InstrumentView::InstrumentView(const TQString &library, const TQString &caption, : KMdiChildView(caption, parentWidget, name, f) , m_libraryName(library) , m_instrumentPart( 0 ) + , m_canary( NULL ) { init(); } InstrumentView::~InstrumentView() { - // + if (m_canary) { + *m_canary = true; + } } void InstrumentView::init() { @@ -44,10 +48,13 @@ void InstrumentView::init() { } bool InstrumentView::queryExit() { - if( !m_instrumentPart ) //apparently std::exit() still calls this function, and abort() causes a crash.. + if (!m_instrumentPart) { // apparently std::exit() still calls this function, and abort() causes a crash.. return true; + } +printf("[RAJA DEBUG 700.0] In InstrumentView::queryExit\n\r"); fflush(stdout); m_instrumentPart->closeURL(); +printf("[RAJA DEBUG 700.1] In InstrumentView::queryExit\n\r"); fflush(stdout); return true; } @@ -57,11 +64,24 @@ void InstrumentView::closeConnections() { } void InstrumentView::connectServer(TQString server) { + if (!m_canary) { + m_canary = new bool; + *m_canary = false; + } + bool* canary = m_canary; + if (m_instrumentPart) { - if (m_instrumentPart->openURL(KURL(server))) { - close(); + if (m_instrumentPart->openURL(KURL(server))) { // This can call processEvents, therefore this object may not exist when it returns! + if (*canary == true) { + delete canary; + return; + } + TQTimer::singleShot(0, this, SLOT(close())); } } + + delete m_canary; + m_canary = NULL; } /********************************************** diff --git a/clients/tde/src/app/views/instrumentview.h b/clients/tde/src/app/views/instrumentview.h index c9df8d2..64d4d5d 100644 --- a/clients/tde/src/app/views/instrumentview.h +++ b/clients/tde/src/app/views/instrumentview.h @@ -26,14 +26,15 @@ class InstrumentView : public KMdiChildView void closeConnections(); protected: - virtual void saveProperties( KConfig * ); - virtual void readProperties( KConfig * ); + virtual void saveProperties(KConfig *); + virtual void readProperties(KConfig *); virtual bool queryExit(); private: void init(); TQString m_libraryName; RemoteLab::InstrumentPart *m_instrumentPart; + bool* m_canary; }; } // namespace RemoteLab diff --git a/clients/tde/src/part/fpgaview/part.cpp b/clients/tde/src/part/fpgaview/part.cpp index 4eae27d..52a1d92 100644 --- a/clients/tde/src/part/fpgaview/part.cpp +++ b/clients/tde/src/part/fpgaview/part.cpp @@ -46,12 +46,6 @@ #include "floatspinbox.h" #include "layout.h" -/* exception handling */ -struct exit_exception { - int c; - exit_exception(int c):c(c) { } -}; - namespace RemoteLab { typedef KParts::GenericFactory<RemoteLab::FPGAViewPart> Factory; @@ -82,7 +76,7 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj FPGAViewPart::~FPGAViewPart() { if (m_connectionMutex->locked()) { - throw exit_exception(-1); + printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout); } if (m_socket) { @@ -95,11 +89,14 @@ FPGAViewPart::~FPGAViewPart() { } void FPGAViewPart::processLockouts() { - if ((m_socket) && (m_socket->state() == TQSocket::Connected)) { - widget()->setEnabled(true); - } - else { - widget()->setEnabled(false); + TQWidget* mainWidget = widget(); + if (mainWidget) { + if ((m_socket) && (m_socket->state() == TQSocket::Connected)) { + mainWidget->setEnabled(true); + } + else { + mainWidget->setEnabled(false); + } } } @@ -114,22 +111,27 @@ void FPGAViewPart::postInit() { bool FPGAViewPart::openURL(const KURL &url) { int ret; ret = connectToServer(url.url()); + // RAJA FIXME + // Need canary? processLockouts(); return (ret != 0); } bool FPGAViewPart::closeURL() { - if (m_connectionMutex->locked()) { - throw exit_exception(-1); - } - +printf("[RAJA DEBUG 710.0] In FPGAViewPart::closeURL\n\r"); fflush(stdout); +printf("[RAJA DEBUG 710.1] In FPGAViewPart::closeURL\n\r"); fflush(stdout); if (m_socket) { m_socket->clearPendingData(); +printf("[RAJA DEBUG 710.2] In FPGAViewPart::closeURL\n\r"); fflush(stdout); m_socket->close(); - delete m_socket; +printf("[RAJA DEBUG 710.3] In FPGAViewPart::closeURL\n\r"); fflush(stdout); + m_socket->deleteLater(); +printf("[RAJA DEBUG 710.4] In FPGAViewPart::closeURL\n\r"); fflush(stdout); m_socket = NULL; +printf("[RAJA DEBUG 710.5] In FPGAViewPart::closeURL\n\r"); fflush(stdout); } +printf("[RAJA DEBUG 710.6] In FPGAViewPart::closeURL\n\r"); fflush(stdout); processLockouts(); m_url = KURL(); @@ -138,6 +140,11 @@ bool FPGAViewPart::closeURL() { } int FPGAViewPart::connectToServer(TQString server) { +printf("[RAJA DEBUG 200.0] In FPGAViewPart::connectToServer\n\r"); fflush(stdout); + if (m_socket) { +printf("[RAJA DEBUG 200.1] In FPGAViewPart::connectToServer TRIED TO CONNECT TWICE!!!\n\r"); fflush(stdout); + return -1; + } if (!m_socket) { m_socket = new TDEKerberosClientSocket(this); } @@ -146,63 +153,61 @@ int FPGAViewPart::connectToServer(TQString server) { m_socket->connectToHost(server, 4004); while ((m_socket->state() != TQSocket::Connected) && (m_socket->state() != TQSocket::Idle)) { tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); + if (!m_socket) return -1; // Any entry into the event loop could end up deleting the socket object depending on user interaction } if (m_socket->state() != TQSocket::Connected) { return -1; } if (m_socket->setUsingKerberos(true) != 0) { + if (!m_socket) return -1; // Any entry into the event loop could end up deleting the socket object depending on user interaction m_socket->close(); KMessageBox::error(0, i18n("<qt>Unable to establish Kerberos protocol with remote server<p>Please verify that you currently hold a valid Kerberos ticket</qt>"), i18n("Connection Failed")); return -1; } connect(m_socket, SIGNAL(connectionClosed()), this, SLOT(connectionClosed())); - try { - m_connectionMutex->lock(); - TQString response; - TQDataStream ds(m_socket); - // Read magic number and proto version from server - TQ_UINT32 magicnum; - TQ_UINT32 protover; - ds >> magicnum; - ds >> protover; - printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout); - // Request connection to backend server - ds << TQString("SERV"); - ds << TQString(CLIENT_LIBRARY); - ds >> response; -printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout); - if (response == "OK") { - m_connectionMutex->unlock(); - return 0; - } - else if (response == "ERRNOCONN") { - KMessageBox::error(0, i18n("<qt>Unable to establish connection with backend server<p>Please verify that you are currently connected to a workspace</qt>"), i18n("Connection Failed")); - m_connectionMutex->unlock(); - return -1; - } - else if (response == "ERRNOTAVL") { - KMessageBox::error(0, i18n("<qt>The backend server is not available at this time<p>Please try a different workspace, or try again later</qt>"), i18n("Connection Failed")); - m_connectionMutex->unlock(); - return -1; - } - else if (response == "ERRNOSERV") { - KMessageBox::error(0, i18n("<qt>The active laboratory workspace does not support the requested service</qt>"), i18n("Service Unavailable")); - m_connectionMutex->unlock(); - return -1; - } - else { - KMessageBox::error(0, i18n("<qt>Unable to establish connection with remote server</qt>"), i18n("Connection Failed")); - m_connectionMutex->unlock(); - return -1; - } + // Kerberos connection established! + m_connectionMutex->lock(); + TQString response; + TQDataStream ds(m_socket); + // Read magic number and proto version from server + TQ_UINT32 magicnum; + TQ_UINT32 protover; + ds >> magicnum; + ds >> protover; + printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout); + // Request connection to backend server + ds << TQString("SERV"); + ds << TQString(CLIENT_LIBRARY); + ds >> response; +printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout); + if (response == "OK") { m_connectionMutex->unlock(); return 0; } - catch (exit_exception& e) { + else if (response == "ERRNOCONN") { + KMessageBox::error(0, i18n("<qt>Unable to establish connection with backend server<p>Please verify that you are currently connected to a workspace</qt>"), i18n("Connection Failed")); + m_connectionMutex->unlock(); + return -1; + } + else if (response == "ERRNOTAVL") { + KMessageBox::error(0, i18n("<qt>The backend server is not available at this time<p>Please try a different workspace, or try again later</qt>"), i18n("Connection Failed")); m_connectionMutex->unlock(); return -1; } + else if (response == "ERRNOSERV") { + KMessageBox::error(0, i18n("<qt>The active laboratory workspace does not support the requested service</qt>"), i18n("Service Unavailable")); + m_connectionMutex->unlock(); + return -1; + } + else { + KMessageBox::error(0, i18n("<qt>Unable to establish connection with remote server</qt>"), i18n("Connection Failed")); + m_connectionMutex->unlock(); + return -1; + } + + m_connectionMutex->unlock(); + return 0; } void FPGAViewPart::updateDisplay() { |