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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License versions 2.0 or 3.0 as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information
** to ensure GNU General Public Licensing requirements will be met:
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** Qt for Windows(R) Licensees
** As a special exception, Nokia, as the sole copyright holder for Qt
** Designer, grants users of the Qt/Eclipse Integration plug-in the
** right for the Qt/Eclipse Integration to link to functionality
** provided by Qt Designer and its related libraries.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
****************************************************************************/
#if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_INTEGRITY)
#include "qkbdintegrity_qws.h"
#include <qwindowsystem_qws.h>
#include <qapplication.h>
#include <qtimer.h>
#include <qthread.h>
#include <INTEGRITY.h>
//===========================================================================
QT_BEGIN_NAMESPACE
//
// INTEGRITY keyboard
//
class QIntKeyboardListenThread;
class QWSIntKbPrivate : public QObject
{
Q_OBJECT
friend class QIntKeyboardListenThread;
public:
QWSIntKbPrivate(QWSKeyboardHandler *, const QString &device);
~QWSIntKbPrivate();
void dataReady(int amount) { emit kbdDataAvailable(amount); }
uint8_t scancodebuf[32 /* USB_SCANCODE_BUF_LEN */ ];
uint8_t rxpost;
uint8_t rxack;
Q_SIGNALS:
void kbdDataAvailable(int amount);
private Q_SLOTS:
void readKeyboardData(int amount);
private:
QWSKeyboardHandler *handler;
QIntKeyboardListenThread *kbdthread;
};
class QIntKeyboardListenThread : public QThread
{
protected:
QWSIntKbPrivate *imp;
bool loop;
public:
QIntKeyboardListenThread(QWSIntKbPrivate *im) : QThread(), imp(im) {};
~QIntKeyboardListenThread() {};
void run();
void stoploop() { loop = false; };
};
QWSIntKeyboardHandler::QWSIntKeyboardHandler(const QString &device)
: QWSKeyboardHandler(device)
{
d = new QWSIntKbPrivate(this, device);
}
QWSIntKeyboardHandler::~QWSIntKeyboardHandler()
{
delete d;
}
//void QWSIntKeyboardHandler::processKeyEvent(int keycode, bool isPress,
// bool autoRepeat)
//{
// QWSKeyboardHandler::processKeyEvent(keycode, isPress, autoRepeat);
//}
void QIntKeyboardListenThread::run(void)
{
Error E;
Buffer b;
Connection kbdc;
bool waitforresource = true;
do {
E = RequestResource((Object*)&kbdc,
"USBKeyboardClient", "!systempassword");
if (E == Success) {
loop = false;
} else {
E = RequestResource((Object*)&kbdc,
"KeyboardClient", "!systempassword");
if (E == Success) {
waitforresource = false;
}
}
if (waitforresource)
::sleep(1);
} while (loop && waitforresource);
if (!loop)
return;
b.BufferType = DataBuffer | LastBuffer;
b.Length = sizeof(imp->scancodebuf);
b.TheAddress = (Address)imp->scancodebuf;
do {
b.Transferred = 0;
b.TheAddress = (Address)imp->scancodebuf + imp->rxpost;
CheckSuccess(SynchronousReceive(kbdc, &b));
imp->rxpost += b.Transferred;
if (imp->rxpost >= 32 /* USB_SCANCODE_BUF_LEN */)
imp->rxpost = 0;
if (imp->rxpost == (imp->rxack + b.Transferred) % 32 /* USB_SCANCODE_BUF_LEN */) {
imp->kbdDataAvailable(b.Transferred);
}
} while (loop);
}
void QWSIntKbPrivate::readKeyboardData(int amount)
{
uint16_t keycode;
do {
if (scancodebuf[rxack] == 0xe0) {
keycode = scancodebuf[rxack] << 8;
rxack++;
if (rxack >= 32 /* USB_SCANCODE_BUF_LEN */)
rxack = 0;
} else {
keycode = 0;
}
handler->processKeycode(keycode + (scancodebuf[rxack] & 0x7f),
(scancodebuf[rxack] & 0x80) == 0,
scancodebuf[rxack] == 2);
rxack++;
if (rxack >= 32 /* USB_SCANCODE_BUF_LEN */)
rxack = 0;
} while (rxack != rxpost);
}
QWSIntKbPrivate::QWSIntKbPrivate(QWSKeyboardHandler *h, const QString &device) : handler(h)
{
connect(this, SIGNAL(kbdDataAvailable(int)), this, SLOT(readKeyboardData(int)));
this->handler = handler;
rxack = rxpost = 0;
kbdthread = new QIntKeyboardListenThread(this);
kbdthread->start();
}
QWSIntKbPrivate::~QWSIntKbPrivate()
{
kbdthread->stoploop();
kbdthread->wait();
delete kbdthread;
}
QT_END_NAMESPACE
#include "qkbdintegrity_qws.moc"
#endif // QT_NO_QWS_KEYBOARD || QT_NO_QWS_KBD_TTY
|