diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-29 23:02:48 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-29 23:02:48 -0500 |
commit | 4dbe57682c156d76db447d814609424bb7e11aca (patch) | |
tree | fae5d851e0a993ba88ac82d10b6ac7f9261c2198 /clients/tde/src | |
parent | 67f0b146ecc82da4511bfe72bdbe4f850c263d8c (diff) | |
download | ulab-4dbe57682c156d76db447d814609424bb7e11aca.tar.gz ulab-4dbe57682c156d76db447d814609424bb7e11aca.zip |
Get rid of processEvents calls in viewer part
Diffstat (limited to 'clients/tde/src')
-rw-r--r-- | clients/tde/src/app/remotemdi.h | 4 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaview/part.cpp | 198 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaview/part.h | 6 |
3 files changed, 124 insertions, 84 deletions
diff --git a/clients/tde/src/app/remotemdi.h b/clients/tde/src/app/remotemdi.h index d1a8263..ccc1fa4 100644 --- a/clients/tde/src/app/remotemdi.h +++ b/clients/tde/src/app/remotemdi.h @@ -69,7 +69,8 @@ class RemoteMDI : public KMdiMainFrm protected: virtual bool queryClose(); - + + private: unsigned m_children; TQString m_serverHost; @@ -79,7 +80,6 @@ class RemoteMDI : public KMdiMainFrm int connToServerState; TQTimer *connToServerTimeoutTimer; - private: KAction *connect_action; KAction *disconnect_action; KAction *inst_sa_menu; diff --git a/clients/tde/src/part/fpgaview/part.cpp b/clients/tde/src/part/fpgaview/part.cpp index 1ca9b6e..94aca85 100644 --- a/clients/tde/src/part/fpgaview/part.cpp +++ b/clients/tde/src/part/fpgaview/part.cpp @@ -54,7 +54,7 @@ K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaviewer, RemoteLab::Factory) FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&) - : ReadOnlyPart( parent, name ), m_socket(0), m_base(0) + : ReadOnlyPart( parent, name ), m_socket(0), m_base(0), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL) { // Initialize mutex m_connectionMutex = new TQMutex(false); @@ -79,12 +79,7 @@ FPGAViewPart::~FPGAViewPart() { printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout); } - if (m_socket) { - m_socket->clearPendingData(); - m_socket->close(); - delete m_socket; - m_socket = NULL; - } + disconnectFromServer(); delete m_connectionMutex; } @@ -111,38 +106,132 @@ 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() { -printf("[RAJA DEBUG 710.0] In FPGAViewPart::closeURL\n\r"); fflush(stdout); -printf("[RAJA DEBUG 710.1] In FPGAViewPart::closeURL\n\r"); fflush(stdout); + disconnectFromServer(); + m_url = KURL(); + return true; +} + +void FPGAViewPart::disconnectFromServer() { if (m_socket) { m_socket->clearPendingData(); -printf("[RAJA DEBUG 710.2] In FPGAViewPart::closeURL\n\r"); fflush(stdout); m_socket->close(); -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); + delete m_socket; 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(); +void FPGAViewPart::finishConnectingToServer() { + if (connToServerConnecting) { + switch(connToServerState) { + case 0: + if (!connToServerTimeoutTimer) { + connToServerTimeoutTimer = new TQTimer; + connToServerTimeoutTimer->start(5000, TRUE); + } + if ((m_socket->state() == TQSocket::Connecting) || (m_socket->state() == TQSocket::HostLookup)) { + if (!connToServerTimeoutTimer->isActive()) { + connToServerState = -3; + connToServerConnecting = false; + disconnectFromServer(); + KMessageBox::error(0, i18n("<qt>Unable to establish connection to remote server</qt>"), i18n("Connection Failed")); + } + } + else { + if (m_socket->state() == TQSocket::Connected) { + printf("[DEBUG] Initial connection established...\n\r"); fflush(stdout); + m_socket->setDataTimeout(5000); + m_socket->setUsingKerberos(true); + connToServerState = 1; + } + else { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + KMessageBox::error(0, i18n("<qt>Unable to establish connection to remote server</qt>"), i18n("Connection Failed")); + } + } + break; + case 1: + if (m_socket->kerberosStatus() == TDEKerberosClientSocket::KerberosInitializing) { + // Do nothing + } + else { + if (m_socket->kerberosStatus() != TDEKerberosClientSocket::KerberosInUse) { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + 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")); + } + else { + connToServerState = 2; + } + } + break; + case 2: + // Connection established! + // Read magic number and proto version from server + TQDataStream ds(m_socket); + 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); - return true; + // Request connection to backend server + TQString response; + 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") { + connToServerState = 3; + connToServerConnecting = false; + processLockouts(); + return; + } + else if (response == "ERRNOCONN") { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + 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")); + return; + } + else if (response == "ERRNOTAVL") { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + 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")); + return; + } + else if (response == "ERRNOSERV") { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + KMessageBox::error(0, i18n("<qt>The active laboratory workspace does not support the requested service</qt>"), i18n("Service Unavailable")); + return; + } + else { + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + KMessageBox::error(0, i18n("<qt>Unable to establish connection with remote server</qt>"), i18n("Connection Failed")); + return; + } + break; + } + + TQTimer::singleShot(0, this, SLOT(finishConnectingToServer())); + } } 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) { @@ -151,67 +240,12 @@ printf("[RAJA DEBUG 200.1] In FPGAViewPart::connectToServer TRIED TO CONNECT TWI m_socket->setServiceName("remotefpga"); m_socket->setServerFQDN(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; - } - m_socket->setDataTimeout(5000); - m_socket->setUsingKerberos(true); - while (m_socket->kerberosStatus() == TDEKerberosClientSocket::KerberosInitializing) { - 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->kerberosStatus() != TDEKerberosClientSocket::KerberosInUse) { - 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())); - - // 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; - } - 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(); + // Finish connecting when appropriate + connToServerState = 0; + connToServerConnecting = true; + TQTimer::singleShot(0, this, SLOT(finishConnectingToServer())); + return 0; } diff --git a/clients/tde/src/part/fpgaview/part.h b/clients/tde/src/part/fpgaview/part.h index 0b03e4f..d4285e0 100644 --- a/clients/tde/src/part/fpgaview/part.h +++ b/clients/tde/src/part/fpgaview/part.h @@ -61,12 +61,18 @@ namespace RemoteLab void updateDisplay(); void processLockouts(); void connectionClosed(); + void disconnectFromServer(); + void finishConnectingToServer(); private: TDEKerberosClientSocket* m_socket; FPGAViewBase* m_base; TQMutex* m_connectionMutex; TQTimer* m_updateTimer; + + bool connToServerConnecting; + int connToServerState; + TQTimer *connToServerTimeoutTimer; }; } |