예제 #1
0
void QBBVirtualKeyboard::ppsDataReady()
{
    while(1) {
        ssize_t nread = read(mFd, mBuffer, sBufferSize - 1);

#ifdef QBBVIRTUALKEYBOARD_DEBUG
        qDebug() << "QBB: keyboardMessage size: " << nread;
#endif
        if (nread < 0)
            break;

        // nread is the real space necessary, not the amount read.
        if (static_cast<size_t>(nread) > sBufferSize - 1) {
            qCritical("QBBVirtualKeyboard: Keyboard buffer size too short; need %u.", nread + 1);
            break;
        }

        mBuffer[nread] = 0;
        pps_decoder_parse_pps_str(mDecoder, mBuffer);
        pps_decoder_push(mDecoder, NULL);
#ifdef QBBVIRTUALKEYBOARD_DEBUG
        pps_decoder_dump_tree(mDecoder, stderr);
#endif

        const char* value;
        if (pps_decoder_get_string(mDecoder, "error", &value) == PPS_DECODER_OK) {
            qCritical("QBBVirtualKeyboard: Keyboard PPS decoder error: %s", value ? value : "[null]");
            continue;
        }

        if (pps_decoder_get_string(mDecoder, "msg", &value) == PPS_DECODER_OK) {
            if (strcmp(value, "show") == 0) {
                mVisible = true;
                handleKeyboardStateChangeMessage(true);
            } else if (strcmp(value, "hide") == 0) {
                mVisible = false;
                handleKeyboardStateChangeMessage(false);
            } else if (strcmp(value, "info") == 0)
                handleKeyboardInfoMessage();
            else if (strcmp(value, "connect") == 0) { }
            else
                qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS msg value: %s", value ? value : "[null]");
        } else if (pps_decoder_get_string(mDecoder, "res", &value) == PPS_DECODER_OK) {
            if (strcmp(value, "info") == 0)
                handleKeyboardInfoMessage();
            else
                qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS res value: %s", value ? value : "[null]");
        } else
            qCritical("QBBVirtualKeyboard: Unexpected keyboard PPS message type");
    }

#ifdef QBBVIRTUALKEYBOARD_DEBUG
    qDebug() << "QBB: exiting keyboard thread";
#endif

    if (mDecoder)
        pps_decoder_cleanup(mDecoder);
}
예제 #2
0
void QQnxVirtualKeyboardPps::ppsDataReady()
{
    ssize_t nread = qt_safe_read(m_fd, m_buffer, ms_bufferSize - 1);

    qVirtualKeyboardDebug() << Q_FUNC_INFO << "keyboardMessage size: " << nread;
    if (nread < 0){
        connect(); // reconnect
        return;
    }

    // We sometimes get spurious read notifications when no data is available.
    // Bail out early in this case
    if (nread == 0)
        return;

    // nread is the real space necessary, not the amount read.
    if (static_cast<size_t>(nread) > ms_bufferSize - 1) {
        qCritical("QQnxVirtualKeyboard: Keyboard buffer size too short; need %u.", nread + 1);
        connect(); // reconnect
        return;
    }

    m_buffer[nread] = 0;
    pps_decoder_parse_pps_str(m_decoder, m_buffer);
    pps_decoder_push(m_decoder, 0);
#if defined(QQNXVIRTUALKEYBOARD_DEBUG)
    pps_decoder_dump_tree(m_decoder, stderr);
#endif

    const char *value;
    if (pps_decoder_get_string(m_decoder, "error", &value) == PPS_DECODER_OK) {
        qCritical("QQnxVirtualKeyboard: Keyboard PPS decoder error: %s", value ? value : "[null]");
        return;
    }

    if (pps_decoder_get_string(m_decoder, "msg", &value) == PPS_DECODER_OK) {
        if (strcmp(value, "show") == 0)
            setVisible(true);
        else if (strcmp(value, "hide") == 0)
            setVisible(false);
        else if (strcmp(value, "info") == 0)
            handleKeyboardInfoMessage();
        else if (strcmp(value, "connect") == 0)
            qVirtualKeyboardDebug() << Q_FUNC_INFO << "Unhandled command 'connect'";
        else
            qCritical("QQnxVirtualKeyboard: Unexpected keyboard PPS msg value: %s", value ? value : "[null]");
    } else if (pps_decoder_get_string(m_decoder, "res", &value) == PPS_DECODER_OK) {
        if (strcmp(value, "info") == 0)
            handleKeyboardInfoMessage();
        else
            qCritical("QQnxVirtualKeyboard: Unexpected keyboard PPS res value: %s", value ? value : "[null]");
    } else {
        qCritical("QQnxVirtualKeyboard: Unexpected keyboard PPS message type");
    }
}