You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
5.9 KiB
219 lines
5.9 KiB
/*
|
|
* Remote Laboratory FPGA Viewer Part
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*
|
|
* (c) 2012 Timothy Pearson
|
|
* Raptor Engineering
|
|
* http://www.raptorengineeringinc.com
|
|
*/
|
|
|
|
#include "define.h"
|
|
#include "part.h"
|
|
|
|
#include <kaboutdata.h> //::createAboutData()
|
|
#include <kaction.h>
|
|
#include <klocale.h>
|
|
#include <kmessagebox.h> //::start()
|
|
#include <kparts/genericfactory.h>
|
|
#include <kstatusbar.h>
|
|
#include <kstdaction.h>
|
|
#include <tqfile.h> //encodeName()
|
|
#include <tqtimer.h> //postInit() hack
|
|
#include <tqvbox.h>
|
|
#include <tqsocket.h>
|
|
#include <tqmutex.h>
|
|
#include <tqeventloop.h>
|
|
#include <tqapplication.h>
|
|
#include <unistd.h> //access()
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "tracewidget.h"
|
|
#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::FPGAViewPart> 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_connectionMutex = new TQMutex(false);
|
|
|
|
// Initialize kpart
|
|
setInstance(Factory::instance());
|
|
setWidget(new TQVBox(parentWidget, widgetName));
|
|
|
|
// Create timers
|
|
m_updateTimer = new TQTimer(this);
|
|
|
|
// 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();
|
|
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);
|
|
}
|
|
}
|
|
|
|
void FPGAViewPart::connectionClosed() {
|
|
closeURL();
|
|
}
|
|
|
|
void FPGAViewPart::postInit() {
|
|
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
|
|
}
|
|
|
|
bool FPGAViewPart::openURL(const KURL &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();
|
|
delete m_socket;
|
|
m_socket = NULL;
|
|
}
|
|
|
|
processLockouts();
|
|
|
|
m_url = KURL();
|
|
|
|
return true;
|
|
}
|
|
|
|
int FPGAViewPart::connectToServer(TQString server) {
|
|
if (!m_socket) {
|
|
m_socket = new TDEKerberosClientSocket(this);
|
|
}
|
|
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->state() != TQSocket::Connected) {
|
|
return -1;
|
|
}
|
|
if (m_socket->setUsingKerberos(true) != 0) {
|
|
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()));
|
|
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;
|
|
}
|
|
|
|
m_connectionMutex->unlock();
|
|
return 0;
|
|
}
|
|
catch (exit_exception& e) {
|
|
m_connectionMutex->unlock();
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
void FPGAViewPart::updateDisplay() {
|
|
// RAJA FIXME
|
|
}
|
|
|
|
KAboutData* FPGAViewPart::createAboutData() {
|
|
return new KAboutData( APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION );
|
|
}
|
|
|
|
} //namespace RemoteLab
|
|
|
|
#include "part.moc"
|