7#include <QtCore/QDebug>
8#include <QtCore/QSocketNotifier>
9#include <QtCore/private/qcore_unix_p.h>
44 qCDebug(lcQpaQnxVirtualKeyboard) <<
"Starting keyboard event processing";
51 delete m_readNotifier;
60 pps_decoder_cleanup(m_decoder);
66 pps_encoder_cleanup(m_encoder);
79 m_encoder =
new pps_encoder_t;
80 m_decoder =
new pps_decoder_t;
82 pps_encoder_initialize(m_encoder,
false);
83 pps_decoder_initialize(m_decoder, 0);
86 m_fd = ::open(ms_PPSPath, O_RDWR);
89 qCDebug(lcQpaQnxVirtualKeyboard) <<
"Unable to open" << ms_PPSPath
90 <<
':' << strerror(errno);
95 m_buffer =
new char[ms_bufferSize];
96 if (Q_UNLIKELY(!m_buffer)) {
97 qCritical(
"QQnxVirtualKeyboard: Unable to allocate buffer of %zu bytes. "
98 "Size is unavailable.", ms_bufferSize);
105 m_readNotifier =
new QSocketNotifier(m_fd, QSocketNotifier::Read);
106 QObject::connect(m_readNotifier, SIGNAL(activated(QSocketDescriptor)),
this, SLOT(ppsDataReady()));
113 if (!prepareToSend())
117 pps_encoder_add_string(m_encoder,
"msg",
"info");
118 pps_encoder_add_string(m_encoder,
"id",
"1");
120 return writeCurrentPPSEncoder();
125 qint64 nread = qt_safe_read(m_fd, m_buffer, ms_bufferSize - 1);
127 qCDebug(lcQpaQnxVirtualKeyboard,
"keyboardMessage size: %lld", nread);
139 if (Q_UNLIKELY(
static_cast<size_t>(nread) > ms_bufferSize - 1)) {
140 qCritical(
"QQnxVirtualKeyboard: Keyboard buffer size too short; need %lld.", nread + 1);
146 pps_decoder_parse_pps_str(m_decoder, m_buffer);
147 pps_decoder_push(m_decoder, 0);
148#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
149 pps_decoder_dump_tree(m_decoder, stderr);
153 if (Q_UNLIKELY(pps_decoder_get_string(m_decoder,
"error", &value) == PPS_DECODER_OK)) {
154 qCritical(
"QQnxVirtualKeyboard: Keyboard PPS decoder error: %s", value ? value :
"[null]");
158 if (pps_decoder_get_string(m_decoder,
"msg", &value) == PPS_DECODER_OK) {
159 if (strcmp(value,
"show") == 0)
161 else if (strcmp(value,
"hide") == 0)
163 else if (strcmp(value,
"info") == 0)
164 handleKeyboardInfoMessage();
165 else if (strcmp(value,
"connect") == 0)
166 qCDebug(lcQpaQnxVirtualKeyboard,
"Unhandled command 'connect'");
168 qCritical(
"QQnxVirtualKeyboard: Unexpected keyboard PPS msg value: %s", value ? value :
"[null]");
169 }
else if (pps_decoder_get_string(m_decoder,
"res", &value) == PPS_DECODER_OK) {
170 if (strcmp(value,
"info") == 0)
171 handleKeyboardInfoMessage();
173 qCritical(
"QQnxVirtualKeyboard: Unexpected keyboard PPS res value: %s", value ? value :
"[null]");
175 qCritical(
"QQnxVirtualKeyboard: Unexpected keyboard PPS message type");
183 if (Q_UNLIKELY(pps_decoder_push(m_decoder,
"dat") != PPS_DECODER_OK)) {
184 qCritical(
"QQnxVirtualKeyboard: Keyboard PPS dat object not found");
187 if (Q_UNLIKELY(pps_decoder_get_int(m_decoder,
"size", &newHeight) != PPS_DECODER_OK)) {
188 qCritical(
"QQnxVirtualKeyboard: Keyboard PPS size field not found");
191 setHeight(newHeight);
193 qCDebug(lcQpaQnxVirtualKeyboard,
"size=%d", newHeight);
198 qCDebug(lcQpaQnxVirtualKeyboard) << Q_FUNC_INFO;
200 if (!prepareToSend())
210 pps_encoder_reset(m_encoder);
213 pps_encoder_add_string(m_encoder,
"msg",
"show");
215 return writeCurrentPPSEncoder();
220 qCDebug(lcQpaQnxVirtualKeyboard) << Q_FUNC_INFO;
222 if (!prepareToSend())
225 pps_encoder_add_string(m_encoder,
"msg",
"hide");
227 return writeCurrentPPSEncoder();
232 if (m_fd == -1 && !connect())
235 pps_encoder_reset(m_encoder);
241 if (::write(m_fd, pps_encoder_buffer(m_encoder), pps_encoder_length(m_encoder)) == -1) {
250 if (!prepareToSend())
254 pps_encoder_add_string(m_encoder,
"msg",
"options");
255 pps_encoder_start_object(m_encoder,
"dat");
257 pps_encoder_add_string(m_encoder,
"enter", enterKeyTypeStr());
258 pps_encoder_add_string(m_encoder,
"type", keyboardModeStr());
260 pps_encoder_end_object(m_encoder);
262 writeCurrentPPSEncoder();
267 switch (keyboardMode()) {
287 return "alphanumeric";
297 switch (enterKeyType()) {
299 return "enter.default";
301 return "enter.connect";
311 return "enter.search";
315 return "enter.submit";
~QQnxVirtualKeyboardPps()
bool hideKeyboard() override
void applyKeyboardOptions() override
bool showKeyboard() override
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")