diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-09 18:42:52 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-09 18:42:52 -0500 |
commit | 83ded525e622feb0318c93d64012882e649568f6 (patch) | |
tree | ce2b13b9b54af601adf71c0b91a331cb0d5ce743 /lib | |
parent | fc455268a511d91113f59c04b50fa08b7c37b554 (diff) | |
download | ulab-83ded525e622feb0318c93d64012882e649568f6.tar.gz ulab-83ded525e622feb0318c93d64012882e649568f6.zip |
Move part connection and disconnection code into tqtrla library
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libtqtrla/src/Makefile.am | 4 | ||||
-rw-r--r-- | lib/libtqtrla/src/tqtrla.cpp | 166 | ||||
-rw-r--r-- | lib/libtqtrla/src/tqtrla.h | 21 |
3 files changed, 188 insertions, 3 deletions
diff --git a/lib/libtqtrla/src/Makefile.am b/lib/libtqtrla/src/Makefile.am index bf4c571..286507d 100644 --- a/lib/libtqtrla/src/Makefile.am +++ b/lib/libtqtrla/src/Makefile.am @@ -1,4 +1,4 @@ -INCLUDES = $(all_includes) +INCLUDES = $(all_includes) $(KDE_INCLUDES)/tde METASOURCES = AUTO # Create a shared library file @@ -8,4 +8,4 @@ include_HEADERS = tqtrla.h libtqtrla_la_SOURCES = tqtrla.cpp libtqtrla_la_LIBADD = -lkio $(LIB_TDEUI) -libtqtrla_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries) $(LIB_KPARTS)
\ No newline at end of file +libtqtrla_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries) $(LIB_KPARTS) -ltdekrbsocket
\ No newline at end of file diff --git a/lib/libtqtrla/src/tqtrla.cpp b/lib/libtqtrla/src/tqtrla.cpp index 376a9d9..4e024d3 100644 --- a/lib/libtqtrla/src/tqtrla.cpp +++ b/lib/libtqtrla/src/tqtrla.cpp @@ -23,6 +23,13 @@ #include <tqwidget.h> #include <klocale.h> +#include <kmessagebox.h> + +// RAJA UNCOMMENT ME +//#define SERVER_TIMEOUT_MS 10000 +// RAJA DEBUG ONLY +#define SERVER_TIMEOUT_MS 100000 +#define FPGA_DATA_PROCESSING_TIMEOUT_MS 2500 namespace KParts { @@ -39,9 +46,14 @@ namespace KParts }; RemoteInstrumentPart::RemoteInstrumentPart(TQObject *parent, const char *name) - : Part( parent, name ) + : Part( parent, name ), + m_socket(NULL), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL) { d = new RemoteInstrumentPartPrivate; + + // Create timers + m_connectionTimer = new TQTimer(this); + connect(m_connectionTimer, SIGNAL(timeout()), this, SLOT(finishConnectingToServer())); } RemoteInstrumentPart::~RemoteInstrumentPart() { @@ -108,6 +120,158 @@ namespace KParts return ret; } + + int RemoteInstrumentPart::connectToServer(TQString server) { + if (m_socket) { + return -1; + } + if (!m_socket) { + m_socket = new TDEKerberosClientSocket(this); + connect(m_socket, TQT_SIGNAL(statusMessageUpdated(const TQString&)), this, TQT_SLOT(setStatusMessage(const TQString&) )); + } + m_socket->setServiceName("remotefpga"); + m_socket->setServerFQDN(server); + m_socket->connectToHost(server, 4004); + + // Finish connecting when appropriate + connToServerState = 0; + connToServerConnecting = true; + m_connectionTimer->start(100, TRUE); + + return 0; + } + + void RemoteInstrumentPart::disconnectFromServer() { + disconnectFromServerCallback(); + m_connectionTimer->stop(); + if (m_socket) { + m_socket->clearPendingData(); + m_socket->close(); + delete m_socket; + m_socket = NULL; + } + connectionStatusChangedCallback(); + } + + void RemoteInstrumentPart::finishConnectingToServer() { + if (!m_socket) { + connToServerState = -1; + connToServerConnecting = false; + connectionStatusChangedCallback(); + return; + } + + if (connToServerConnecting) { + switch(connToServerState) { + case 0: + if (!connToServerTimeoutTimer) { + connToServerTimeoutTimer = new TQTimer; + connToServerTimeoutTimer->start(SERVER_TIMEOUT_MS, 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(SERVER_TIMEOUT_MS); + 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 + m_socket->processPendingData(); + if (m_socket->canReadFrame()) { + TQDataStream ds(m_socket); + ds.setPrintableData(true); + TQ_UINT32 magicnum; + TQ_UINT32 protover; + ds >> magicnum; + ds >> protover; + m_socket->clearFrameTail(); + printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout); + + // Request connection to backend server + ds << TQString("SERV"); + m_socket->writeEndOfFrame(); + ds << m_clientLibraryName; + m_socket->writeEndOfFrame(); + connToServerState = 3; + } + break; + case 3: + // Read response from server + m_socket->processPendingData(); + if (m_socket->bytesAvailable() > 0) { + TQDataStream ds(m_socket); + ds.setPrintableData(true); + TQString response; + ds >> response; + m_socket->clearFrameTail(); + if (response == "OK") { + connToServerState = 4; + connToServerConnecting = false; + connectionFinishedCallback(); + return; + } + else { + TQStringList errorStrings = textForServerError(response); + connToServerState = -1; + connToServerConnecting = false; + disconnectFromServer(); + KMessageBox::error(0, errorStrings[0], errorStrings[1]); + close(); + return; + } + } + break; + } + + m_connectionTimer->start(100, TRUE); + } + } + + void RemoteInstrumentPart::connectionFinishedCallback() { + // + } + + void RemoteInstrumentPart::disconnectFromServerCallback() { + // + } + + void RemoteInstrumentPart::connectionStatusChangedCallback() { + // + } } bool operator==( const ServiceType &s1, const ServiceType &s2 ) { diff --git a/lib/libtqtrla/src/tqtrla.h b/lib/libtqtrla/src/tqtrla.h index c1c88e2..2db5cc0 100644 --- a/lib/libtqtrla/src/tqtrla.h +++ b/lib/libtqtrla/src/tqtrla.h @@ -23,11 +23,14 @@ #include <tqobject.h> #include <tqptrlist.h> +#include <tqtimer.h> #include <kaction.h> #include <kparts/part.h> +#include <tdekrbclientsocket.h> + // ============================================================================= namespace KParts @@ -54,6 +57,16 @@ namespace KParts TQStringList textForServerError(TQString shortError); TQ_ULONG maximumSocketDataChunkSize(); + public: + int connectToServer(TQString server); + void disconnectFromServer(); + + private slots: + void finishConnectingToServer(); + virtual void connectionFinishedCallback(); + virtual void disconnectFromServerCallback(); + virtual void connectionStatusChangedCallback(); + protected slots: void close(); void resize(TQSize size); @@ -64,6 +77,14 @@ namespace KParts protected: KURL m_url; + TQString m_clientLibraryName; + + protected: + TDEKerberosClientSocket* m_socket; + TQTimer* m_connectionTimer; + bool connToServerConnecting; + int connToServerState; + TQTimer *connToServerTimeoutTimer; private: RemoteInstrumentPartPrivate *d; |