diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-23 17:23:49 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-06-23 17:23:49 -0500 |
commit | 8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2 (patch) | |
tree | a0a77ec1d7d7cd826e1f2ba92ea4f96351bae5e3 /clients/tde | |
parent | b48b26b86975d2166a4da7fc41086facefb3c4f2 (diff) | |
download | ulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.tar.gz ulab-8dcfe72c396a6f0c4bafd2ed23ba52a475154ef2.zip |
Fix a number of crashes and generally clean up the code
Diffstat (limited to 'clients/tde')
-rw-r--r-- | clients/tde/src/app/remotemdi.cpp | 67 | ||||
-rw-r--r-- | clients/tde/src/app/remotemdi.h | 3 | ||||
-rw-r--r-- | clients/tde/src/part/commanalyzer/Makefile.am | 5 | ||||
-rw-r--r-- | clients/tde/src/part/commanalyzer/part.cpp | 309 |
4 files changed, 218 insertions, 166 deletions
diff --git a/clients/tde/src/app/remotemdi.cpp b/clients/tde/src/app/remotemdi.cpp index ae06857..1df78df 100644 --- a/clients/tde/src/app/remotemdi.cpp +++ b/clients/tde/src/app/remotemdi.cpp @@ -29,7 +29,7 @@ using namespace std; #include "views/instrumentview.h" RemoteMDI::RemoteMDI() - : KMdiMainFrm(0, "RemoteMDI", KMdi::ChildframeMode), m_children(NULL), m_rsvSvrSocket(NULL) + : KMdiMainFrm(0, "RemoteMDI", KMdi::ChildframeMode), m_children(0), m_rsvSvrSocket(NULL) { setXMLFile("remotelabui.rc"); @@ -42,9 +42,9 @@ RemoteMDI::RemoteMDI() KStdAction::quit(TQT_TQOBJECT(this), TQT_SLOT(close()), ac); KStdAction::configureToolbars(TQT_TQOBJECT(this), TQT_SLOT(configToolbars()), ac); KStdAction::keyBindings(TQT_TQOBJECT(this), TQT_SLOT(configKeys()), ac); - connect_action = new KAction(i18n("Connect to Server"), "connect_creating", NULL, TQT_TQOBJECT(this), TQT_SLOT(connectToServer()), ac, "connect_server"); - disconnect_action = new KAction(i18n("Disconnect from Server"), "connect_no", NULL, TQT_TQOBJECT(this), TQT_SLOT(disconnectFromServer()), ac, "disconnect_server"); - inst_sa_menu = new KAction(i18n("Launch Spectrum Analyzer"), "remote", NULL, TQT_TQOBJECT(this), TQT_SLOT(startSpectrumAnalyzer()), ac, "spectrum_analyzer"); + connect_action = new KAction(i18n("Connect to Server"), "connect_creating", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(connectToServer()), ac, "connect_server"); + disconnect_action = new KAction(i18n("Disconnect from Server"), "connect_no", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(disconnectFromServer()), ac, "disconnect_server"); + inst_sa_menu = new KAction(i18n("Launch Spectrum Analyzer"), "remote", KShortcut(), TQT_TQOBJECT(this), TQT_SLOT(startSpectrumAnalyzer()), ac, "spectrum_analyzer"); // Add Window menu if ( !isFakingSDIApplication() ) { @@ -85,21 +85,24 @@ RemoteMDI::~RemoteMDI() while (m_rsvSvrSocket->state() == TQSocket::Closing) { tqApp->processEvents(); } - delete m_rsvSvrSocket; } } void RemoteMDI::connectToServer() { if (m_rsvSvrSocket) { - return; + if (m_rsvSvrSocket->state() != TQSocket::Idle) { + return; + } } connect_action->setEnabled(false); disconnect_action->setEnabled(false); // Connect to the central reservation/control server - m_rsvSvrSocket = new TDEKerberosClientSocket(this); - connect(m_rsvSvrSocket, SIGNAL(connectionClosed()), this, SLOT(connectionClosedHandler())); + if (!m_rsvSvrSocket) { + m_rsvSvrSocket = new TDEKerberosClientSocket(this); + connect(m_rsvSvrSocket, SIGNAL(connectionClosed()), this, SLOT(connectionClosedHandler())); + } m_rsvSvrSocket->setServiceName("remotefpga"); if (m_serverHost != "") { m_rsvSvrSocket->setServerFQDN(m_serverHost); @@ -116,18 +119,16 @@ void RemoteMDI::connectToServer() { else { // Connection established! // Read magic number and proto version from server - TQDataStream ds(m_rsvSvrSocket); + TQDataStream* ds = new TQDataStream(m_rsvSvrSocket); TQ_UINT32 magicnum; TQ_UINT32 protover; - ds >> magicnum; - ds >> protover; - printf("[RAJA DEBUG 200.0] Got magic %d and proto %d\n\r", magicnum, protover); fflush(stdout); + *ds >> magicnum; + *ds >> protover; + printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout); + delete ds; if ((magicnum == MAGIC_NUMBER) && (protover == PROTOCOL_VERSION)) { disconnect_action->setEnabled(true); - - // Read the next line from the server - TQString str = m_rsvSvrSocket->readLine(); - printf("[RAJA DEBUG 200.1] Got %s\n\r", str.ascii()); fflush(stdout); + promptForStationType(); } else { disconnectFromServer(); @@ -148,6 +149,24 @@ void RemoteMDI::connectToServer() { processLockouts(); } +void RemoteMDI::promptForStationType() { + if (!m_rsvSvrSocket) { + return; + } + if (m_rsvSvrSocket->state() != TQSocket::Connected) { + return; + } + + TQDataStream ds(m_rsvSvrSocket); + + // Request list of laboratory stations + StationList slist; + ds << TQString("LIST"); + ds >> slist; + + printf("[RAJA DEBUG 200.2] Got list of stations, count is %d\n\r", slist.count()); fflush(stdout); +} + void RemoteMDI::disconnectFromServer() { connect_action->setEnabled(false); disconnect_action->setEnabled(false); @@ -157,8 +176,6 @@ void RemoteMDI::disconnectFromServer() { while (m_rsvSvrSocket->state() == TQSocket::Closing) { tqApp->processEvents(); } - delete m_rsvSvrSocket; - m_rsvSvrSocket = 0; } connect_action->setEnabled(true); @@ -239,20 +256,10 @@ void RemoteMDI::openNewWindow(KMdiChildView *view) void RemoteMDI::childWindowCloseRequest(KMdiChildView *pWnd) { RemoteLab::InstrumentView* iview = dynamic_cast<RemoteLab::InstrumentView*>(pWnd); if (iview) { + // Give the child a chance to finish what it was doing and exit cleanly (i.e. without crashing!) iview->closeConnections(); iview->hide(); - // Give the child a chance to finish what it was doing - // FIXME HACK - // There is no nice way to shut down the instrument parts it seems... - // Debug why they crash when this delay is set to zero! - m_closelist.append(pWnd); - TQTimer::singleShot(100, this, SLOT(processCloseList())); - } -} - -void RemoteMDI::processCloseList() { - if (m_closelist.begin() != m_closelist.end()) { - KMdiMainFrm::childWindowCloseRequest(*m_closelist.begin()); + KMdiMainFrm::childWindowCloseRequest(pWnd); } } diff --git a/clients/tde/src/app/remotemdi.h b/clients/tde/src/app/remotemdi.h index 8bd5f2f..9270ee0 100644 --- a/clients/tde/src/app/remotemdi.h +++ b/clients/tde/src/app/remotemdi.h @@ -47,7 +47,6 @@ class RemoteMDI : public KMdiMainFrm public slots: virtual void childWindowCloseRequest(KMdiChildView *pWnd); - void processCloseList(); protected slots: void openNewWindow(KMdiChildView *view=0); @@ -62,6 +61,7 @@ class RemoteMDI : public KMdiMainFrm void configKeys(); void connectToServer(); void disconnectFromServer(); + void promptForStationType(); void connectionClosedHandler(); void processLockouts(); void startSpectrumAnalyzer(); @@ -73,7 +73,6 @@ class RemoteMDI : public KMdiMainFrm TQString m_serverHost; TQValueList<KMdiChildView*> m_window; - TQValueList<KMdiChildView*> m_closelist; KListBox *m_listBox; TDEKerberosClientSocket* m_rsvSvrSocket; diff --git a/clients/tde/src/part/commanalyzer/Makefile.am b/clients/tde/src/part/commanalyzer/Makefile.am index db98e9e..d2db726 100644 --- a/clients/tde/src/part/commanalyzer/Makefile.am +++ b/clients/tde/src/part/commanalyzer/Makefile.am @@ -1,5 +1,6 @@ -INCLUDES = $(all_includes) -I$(top_srcdir)/src -I$(top_srcdir)/src/widgets -METASOURCES = AUTO +INCLUDES = $(all_includes) -I$(top_srcdir)/src -I$(top_srcdir)/src/widgets +KDE_CXXFLAGS = $(USE_EXCEPTIONS) +METASOURCES = AUTO #Part kde_module_LTLIBRARIES = libremotelab_commanalyzer.la diff --git a/clients/tde/src/part/commanalyzer/part.cpp b/clients/tde/src/part/commanalyzer/part.cpp index 592e64d..dbee9be 100644 --- a/clients/tde/src/part/commanalyzer/part.cpp +++ b/clients/tde/src/part/commanalyzer/part.cpp @@ -26,6 +26,12 @@ #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::CommAnalyzerPart> Factory; @@ -88,7 +94,11 @@ bool CommAnalyzerPart::closeURL() { } m_url = KURL(); - + + if (m_instrumentMutex->locked()) { + throw exit_exception(-1); + } + return true; } @@ -97,24 +107,30 @@ TQString CommAnalyzerPart::callServerMethod(int command) { printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return TQString::null; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + cmd.append('\r'); + m_socket->writeBlock(cmd.latin1(), cmd.length()); + // Read from the server + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); + m_instrumentMutex->unlock(); + return serverRet; + } + else { + m_instrumentMutex->unlock(); + return TQString::null; } - m_instrumentMutex->unlock(); - return serverRet; } - else { + catch (exit_exception& e) { m_instrumentMutex->unlock(); return TQString::null; } @@ -125,33 +141,39 @@ int16_t CommAnalyzerPart::callServerMethodInt16(int command) { printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return 0; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - int bytesread = 0; - int16_t data[1]; - while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + cmd.append('\r'); + m_socket->writeBlock(cmd.latin1(), cmd.length()); + // Read from the server + int bytesread = 0; + int16_t data[1]; + while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { + int ret = m_socket->readBlock(((char*)data)+bytesread, 1); + if (ret > 0) { + bytesread += ret; + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); + m_instrumentMutex->unlock(); + return data[0]; + } + else { + m_instrumentMutex->unlock(); + return 0; } - m_instrumentMutex->unlock(); - return data[0]; } - else { + catch (exit_exception& e) { m_instrumentMutex->unlock(); return 0; } @@ -162,33 +184,39 @@ double CommAnalyzerPart::callServerMethodDouble(int command) { printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return 0; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - unsigned int bytesread = 0; - double data[1]; - while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + cmd.append('\r'); + m_socket->writeBlock(cmd.latin1(), cmd.length()); + // Read from the server + unsigned int bytesread = 0; + double data[1]; + while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { + int ret = m_socket->readBlock(((char*)data)+bytesread, 1); + if (ret > 0) { + bytesread += ret; + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); + m_instrumentMutex->unlock(); + return data[0]; + } + else { + m_instrumentMutex->unlock(); + return 0; } - m_instrumentMutex->unlock(); - return data[0]; } - else { + catch (exit_exception& e) { m_instrumentMutex->unlock(); return 0; } @@ -199,23 +227,30 @@ void CommAnalyzerPart::sendServerCommandWithParameter(int command, TQString para printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - param = TQString("%1%2%3").arg(param).arg(TQChar('°')).arg(TQChar('\r')); - cmd += param; - m_socket->writeBlock(cmd.ascii(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + param = TQString("%1%2%3").arg(param).arg(TQChar('°')).arg(TQChar('\r')); + cmd += param; + m_socket->writeBlock(cmd.ascii(), cmd.length()); + // Read from the server + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } + m_instrumentMutex->unlock(); + return; + } + catch (exit_exception& e) { + m_instrumentMutex->unlock(); + return; } - m_instrumentMutex->unlock(); } void CommAnalyzerPart::sendServerCommand(int command) { @@ -223,22 +258,29 @@ void CommAnalyzerPart::sendServerCommand(int command) { printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + cmd.append('\r'); + m_socket->writeBlock(cmd.latin1(), cmd.length()); + // Read from the server + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } + m_instrumentMutex->unlock(); + return; + } + catch (exit_exception& e) { + m_instrumentMutex->unlock(); + return; } - m_instrumentMutex->unlock(); } void CommAnalyzerPart::callServerMethodDoubleArray(int command, double * array, int arrayLen) { @@ -246,62 +288,65 @@ void CommAnalyzerPart::callServerMethodDoubleArray(int command, double * array, printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); return; } - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + try { + m_instrumentMutex->lock(); + if (m_socket->state() == TQSocket::Connected) { + TQString cmd = TQChar(command); + cmd.append('\r'); + m_socket->writeBlock(cmd.latin1(), cmd.length()); + // Read from the server + TQString serverRet; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - unsigned int bytesread = 0; - int16_t data[1]; - while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + unsigned int bytesread = 0; + int16_t data[1]; + while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { + int ret = m_socket->readBlock(((char*)data)+bytesread, 1); + if (ret > 0) { + bytesread += ret; + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - serverRet = ""; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + serverRet = ""; + while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { + char data[1]; + if( m_socket->readBlock(data, 1) > 0) { + serverRet.append(data[0]); + } + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - bytesread = 0; - int elementsread = 0; - for (elementsread=0;elementsread<arrayLen;elementsread++) { bytesread = 0; - while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { - if (m_socket->size() < 1) { - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - int ret = m_socket->readBlock(((char*)array)+bytesread+(elementsread*sizeof(double)), 1); - if (ret > 0) { - bytesread += ret; + int elementsread = 0; + for (elementsread=0;elementsread<arrayLen;elementsread++) { + bytesread = 0; + while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { + if (m_socket->size() < 1) { + tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); + } + int ret = m_socket->readBlock(((char*)array)+bytesread+(elementsread*sizeof(double)), 1); + if (ret > 0) { + bytesread += ret; + } } } } + m_instrumentMutex->unlock(); + return; + } + catch (exit_exception& e) { + m_instrumentMutex->unlock(); + return; } - m_instrumentMutex->unlock(); } int CommAnalyzerPart::connectToServer(TQString server) { if (!m_socket) { m_socket = new TQSocket(this); -// connect(m_socket, SIGNAL(connected()), SLOT(socketConnected())); -// connect(m_socket, SIGNAL(connectionClosed()), SLOT(socketConnectionClosed())); -// connect(m_socket, SIGNAL(readyRead()), SLOT(socketReadyRead())); -// connect(m_socket, SIGNAL(error(int)), SLOT(socketError(int))); } m_socket->connectToHost(server, 4002); while ((m_socket->state() != TQSocket::Connected) && (m_socket->state() != TQSocket::Idle)) { |