Move part connection and disconnection code into tqtrla library

master
Timothy Pearson 13 years ago
parent fc455268a5
commit 83ded525e6

@ -75,10 +75,7 @@ bool InstrumentView::queryExit() {
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;
}

@ -54,12 +54,7 @@
#include "floatspinbox.h"
#include "layout.h"
// RAJA UNCOMMENT ME
//#define SERVER_TIMEOUT_MS 10000
// RAJA DEBUG ONLY
#define SERVER_TIMEOUT_MS 100000
#define NETWORK_COMM_TIMEOUT_MS 2500
#define FPGA_DATA_PROCESSING_TIMEOUT_MS 2500
namespace RemoteLab {
@ -68,9 +63,11 @@ typedef KParts::GenericFactory<RemoteLab::FPGAProgramPart> Factory;
K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaprogrammer, RemoteLab::Factory)
FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&)
: RemoteInstrumentPart( parent, name ), m_socket(0), m_base(0), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL),
m_commHandlerState(0), m_connectionActiveAndValid(false), m_tickerState(0)
: RemoteInstrumentPart( parent, name ), m_base(NULL), m_commHandlerState(0), m_connectionActiveAndValid(false), m_tickerState(0)
{
// Initialize important base class variables
m_clientLibraryName = CLIENT_LIBRARY;
// Initialize mutex
m_connectionMutex = new TQMutex(false);
@ -79,8 +76,6 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName,
setWidget(new TQVBox(parentWidget, widgetName));
// Create timers
m_connectionTimer = new TQTimer(this);
connect(m_connectionTimer, SIGNAL(timeout()), this, SLOT(finishConnectingToServer()));
m_updateTimeoutTimer = new TQTimer(this);
connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
m_pingDelayTimer = new TQTimer(this);
@ -161,153 +156,26 @@ bool FPGAProgramPart::closeURL() {
return true;
}
void FPGAProgramPart::disconnectFromServer() {
m_connectionTimer->stop();
void FPGAProgramPart::disconnectFromServerCallback() {
m_updateTimeoutTimer->stop();
if (m_socket) {
m_socket->clearPendingData();
m_socket->close();
delete m_socket;
m_socket = NULL;
}
processLockouts();
}
void FPGAProgramPart::finishConnectingToServer() {
if (!m_socket) {
connToServerState = -1;
connToServerConnecting = false;
processLockouts();
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 << TQString(CLIENT_LIBRARY);
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;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0;
m_commHandlerState = 0;
m_commHandlerMode = 0;
m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
processLockouts();
mainEventLoop();
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 FPGAProgramPart::connectionFinishedCallback() {
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0;
m_commHandlerState = 0;
m_commHandlerMode = 0;
m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
processLockouts();
mainEventLoop();
return;
}
int FPGAProgramPart::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 FPGAProgramPart::connectionStatusChangedCallback() {
processLockouts();
}
void FPGAProgramPart::programRunButtonClicked() {

@ -59,7 +59,6 @@ namespace RemoteLab
virtual bool openFile() { return false; } // pure virtual in the base class
virtual bool closeURL();
static KAboutData *createAboutData();
int connectToServer(TQString server);
public slots:
virtual bool openURL(const KURL &url);
@ -70,24 +69,19 @@ namespace RemoteLab
void mainEventLoop();
void processLockouts();
void connectionClosed();
void disconnectFromServer();
void finishConnectingToServer();
void connectionFinishedCallback();
void disconnectFromServerCallback();
void connectionStatusChangedCallback();
void setTickerMessage(TQString message);
void programRunButtonClicked();
private:
TDEKerberosClientSocket* m_socket;
FPGAProgramBase* m_base;
TQMutex* m_connectionMutex;
TQTimer* m_connectionTimer;
TQTimer* m_pingDelayTimer;
TQTimer* m_updateTimeoutTimer;
bool connToServerConnecting;
int connToServerState;
TQTimer *connToServerTimeoutTimer;
int m_commHandlerState;
int m_commHandlerMode;
int m_commHandlerNextState;

@ -563,12 +563,15 @@ K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaviewer, RemoteLab::Factory)
#define LED_SIZE LED_BASE_SIZE,LED_BASE_SIZE
FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&)
: RemoteInstrumentPart( parent, name ), m_socket(0), m_base(0), connToServerConnecting(false), connToServerState(-1), connToServerTimeoutTimer(NULL), m_interfaceMode(BasicInterfaceMode),
: RemoteInstrumentPart( parent, name ), m_base(NULL), m_interfaceMode(BasicInterfaceMode),
m_commHandlerState(0), m_commHandlerMode(0), m_connectionActiveAndValid(false), m_tickerState(0), m_remoteInputModeEnabled(false), m_4bitInputValue(0), m_4bitOutputValue(0),
m_8bitInputValue(0), m_8bitOutputValue(0), m_16bitInputValue(0), m_16bitOutputValue(0), m_7segDigit3OutputValue(0xffffffff),
m_7segDigit2OutputValue(0xffffffff), m_7segDigit1OutputValue(0xffffffff), m_7segDigit0OutputValue(0xffffffff),
m_batchOutputFile(NULL), m_dataOutputFile(NULL)
{
// Initialize important base class variables
m_clientLibraryName = CLIENT_LIBRARY;
// Initialize mutex
m_connectionMutex = new TQMutex(false);
@ -991,153 +994,25 @@ bool FPGAViewPart::closeURL() {
return true;
}
void FPGAViewPart::disconnectFromServer() {
m_connectionTimer->stop();
void FPGAViewPart::disconnectFromServerCallback() {
m_updateTimer->stop();
if (m_socket) {
m_socket->clearPendingData();
m_socket->close();
delete m_socket;
m_socket = NULL;
}
processLockouts();
}
void FPGAViewPart::finishConnectingToServer() {
if (!m_socket) {
connToServerState = -1;
connToServerConnecting = false;
processLockouts();
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 << TQString(CLIENT_LIBRARY);
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();
printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout);
if (response == "OK") {
connToServerState = 4;
connToServerConnecting = false;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(updateDisplay()));
m_tickerState = 0;
m_commHandlerState = 0;
m_commHandlerMode = 0;
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
processLockouts();
updateDisplay();
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 FPGAViewPart::connectionFinishedCallback() {
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(updateDisplay()));
m_tickerState = 0;
m_commHandlerState = 0;
m_commHandlerMode = 0;
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
processLockouts();
updateDisplay();
return;
}
int FPGAViewPart::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 FPGAViewPart::connectionStatusChangedCallback() {
processLockouts();
}
TQPtrList<KAction> FPGAViewPart::menuActionList() {

@ -147,7 +147,6 @@ namespace RemoteLab
virtual bool openFile() { return false; } // pure virtual in the base class
virtual bool closeURL();
static KAboutData *createAboutData();
int connectToServer(TQString server);
virtual TQPtrList<KAction> menuActionList();
public slots:
@ -159,8 +158,9 @@ namespace RemoteLab
void updateDisplay();
void processLockouts();
void connectionClosed();
void disconnectFromServer();
void finishConnectingToServer();
void connectionFinishedCallback();
void disconnectFromServerCallback();
void connectionStatusChangedCallback();
void switchToBasicMode();
void switchToIntermediateMode();
void switchToAdvancedMode();
@ -183,16 +183,10 @@ namespace RemoteLab
void receiveInputStatesFromRemoteFPGA();
private:
TDEKerberosClientSocket* m_socket;
FPGAViewBase* m_base;
TQMutex* m_connectionMutex;
TQTimer* m_connectionTimer;
TQTimer* m_updateTimer;
bool connToServerConnecting;
int connToServerState;
TQTimer *connToServerTimeoutTimer;
TQPtrList<KAction> m_menuActionList;
KActionMenu* m_modeSubMenu;
KToggleAction* m_modeBasicEnabled;

@ -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)
libtqtrla_la_LDFLAGS = -avoid-version -module -no-undefined $(all_libraries) $(LIB_KPARTS) -ltdekrbsocket

@ -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 ) {

@ -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;

Loading…
Cancel
Save