diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-27 20:43:57 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-27 20:43:57 -0500 |
commit | 8392c611054a5bb058cd778163a7aa4ef8311c94 (patch) | |
tree | 5703e9d3ff12474fe474d37bb7c2532418c5b8aa /clients/tde/src/part/fpgaview | |
parent | e3bfbdc4e464d057be5095bb5bbd3240beab8ec6 (diff) | |
download | ulab-8392c611054a5bb058cd778163a7aa4ef8311c94.tar.gz ulab-8392c611054a5bb058cd778163a7aa4ef8311c94.zip |
Fix a number of problems
Diffstat (limited to 'clients/tde/src/part/fpgaview')
-rw-r--r-- | clients/tde/src/part/fpgaview/part.cpp | 105 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaview/part.h | 4 |
2 files changed, 87 insertions, 22 deletions
diff --git a/clients/tde/src/part/fpgaview/part.cpp b/clients/tde/src/part/fpgaview/part.cpp index dab2742..4eae27d 100644 --- a/clients/tde/src/part/fpgaview/part.cpp +++ b/clients/tde/src/part/fpgaview/part.cpp @@ -55,14 +55,15 @@ struct exit_exception { namespace RemoteLab { typedef KParts::GenericFactory<RemoteLab::FPGAViewPart> Factory; -K_EXPORT_COMPONENT_FACTORY( libremotelab_fpgaviewer, RemoteLab::Factory ) +#define CLIENT_LIBRARY "libremotelab_fpgaviewer" +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) { // Initialize mutex - m_instrumentMutex = new TQMutex(false); + m_connectionMutex = new TQMutex(false); // Initialize kpart setInstance(Factory::instance()); @@ -74,19 +75,36 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj // Create widgets m_base = new FPGAViewBase(widget()); + processLockouts(); + TQTimer::singleShot(0, this, TQT_SLOT(postInit())); } FPGAViewPart::~FPGAViewPart() { + if (m_connectionMutex->locked()) { + throw exit_exception(-1); + } + if (m_socket) { + m_socket->clearPendingData(); m_socket->close(); - while (m_socket->state() == TQSocket::Closing) { - tqApp->processEvents(); - } delete m_socket; + m_socket = NULL; + } + delete m_connectionMutex; +} + +void FPGAViewPart::processLockouts() { + if ((m_socket) && (m_socket->state() == TQSocket::Connected)) { + widget()->setEnabled(true); + } + else { + widget()->setEnabled(false); } +} - delete m_instrumentMutex; +void FPGAViewPart::connectionClosed() { + closeURL(); } void FPGAViewPart::postInit() { @@ -94,23 +112,27 @@ void FPGAViewPart::postInit() { } bool FPGAViewPart::openURL(const KURL &url) { - return connectToServer(url.url()); + int ret; + ret = connectToServer(url.url()); + processLockouts(); + return (ret != 0); } bool FPGAViewPart::closeURL() { + if (m_connectionMutex->locked()) { + throw exit_exception(-1); + } + if (m_socket) { + m_socket->clearPendingData(); m_socket->close(); - - while (m_socket->state() != TQSocket::Idle) { - tqApp->processEvents(); - } + delete m_socket; + m_socket = NULL; } - m_url = KURL(); + processLockouts(); - if (m_instrumentMutex->locked()) { - throw exit_exception(-1); - } + m_url = KURL(); return true; } @@ -133,13 +155,54 @@ int FPGAViewPart::connectToServer(TQString server) { 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; } - TQDataStream ds(m_socket); - // RAJA FIXME - // How do we know which service to request? -// ds << TQString("SERV"); -// ds << + 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; + } - return 0; + m_connectionMutex->unlock(); + return 0; + } + catch (exit_exception& e) { + m_connectionMutex->unlock(); + return -1; + } } void FPGAViewPart::updateDisplay() { diff --git a/clients/tde/src/part/fpgaview/part.h b/clients/tde/src/part/fpgaview/part.h index ff1a5da..0b03e4f 100644 --- a/clients/tde/src/part/fpgaview/part.h +++ b/clients/tde/src/part/fpgaview/part.h @@ -59,11 +59,13 @@ namespace RemoteLab private slots: void postInit(); void updateDisplay(); + void processLockouts(); + void connectionClosed(); private: TDEKerberosClientSocket* m_socket; FPGAViewBase* m_base; - TQMutex* m_instrumentMutex; + TQMutex* m_connectionMutex; TQTimer* m_updateTimer; }; } |