1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* 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;
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);
// Initialize kpart
setInstance(Factory::instance());
setWidget(new TQVBox(parentWidget, widgetName));
// Create timers
m_updateTimer = new TQTimer(this);
// Create widgets
m_base = new FPGAViewBase(widget());
TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
}
FPGAViewPart::~FPGAViewPart() {
if (m_socket) {
m_socket->close();
while (m_socket->state() == TQSocket::Closing) {
tqApp->processEvents();
}
delete m_socket;
}
delete m_instrumentMutex;
}
void FPGAViewPart::postInit() {
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateDisplay()));
}
bool FPGAViewPart::openURL(const KURL &url) {
return connectToServer(url.url());
}
bool FPGAViewPart::closeURL() {
if (m_socket) {
m_socket->close();
while (m_socket->state() != TQSocket::Idle) {
tqApp->processEvents();
}
}
m_url = KURL();
if (m_instrumentMutex->locked()) {
throw exit_exception(-1);
}
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;
}
TQDataStream ds(m_socket);
// RAJA FIXME
// How do we know which service to request?
// ds << TQString("SERV");
// ds <<
return 0;
}
void FPGAViewPart::updateDisplay() {
// RAJA FIXME
}
KAboutData* FPGAViewPart::createAboutData() {
return new KAboutData( APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION );
}
} //namespace RemoteLab
#include "part.moc"
|