Example #1
0
QPpsAttribute QPpsObjectPrivate::decodeData(pps_decoder_t *decoder)
{
    pps_node_type_t nodeType = pps_decoder_type(decoder, 0);
    switch (nodeType) {
    case PPS_TYPE_BOOL:
        return decodeBool(decoder);
    case PPS_TYPE_NUMBER:
        return decodeNumber(decoder);
    case PPS_TYPE_STRING:
        return decodeString(decoder);
    case PPS_TYPE_ARRAY:
        return decodeNestedData(&QPpsObjectPrivate::decodeArray, decoder);
    case PPS_TYPE_OBJECT:
        return decodeNestedData(&QPpsObjectPrivate::decodeObject, decoder);
    case PPS_TYPE_DELETED: {
        // This should create an attribute with the flags set to PpsAttribute::Deleted.
        // However, we need to create a valid QPpsAttribute while doing so. To do this,
        // I'll create an empty map as a sentinel. Note that the readFlags() call with produce
        // the correct set of flags. While I suspect that there will never be any other flags
        // set in conjunction with this one, I'd rather not be surprised later.
        QPpsAttributeMap emptyMap;
        QPpsAttribute::Flags flags = readFlags(decoder);
        QPpsAttribute returnVal = QPpsAttributePrivate::createPpsAttribute(emptyMap, flags);
        return returnVal;
    }
    case PPS_TYPE_NULL:
    case PPS_TYPE_NONE:
    case PPS_TYPE_UNKNOWN:
    default:
        qWarning() << "QPpsObjectPrivate::decodeData: invalid pps_node_type";
        return QPpsAttribute();
    }
}
Example #2
0
QVariant ppsReadSetting(const char *property)
{
    int settingsFD;
    char buf[ppsBufferSize];
    if ((settingsFD = qt_safe_open(btSettingsFDPath, O_RDONLY)) == -1) {
        qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btSettingsFDPath;
        return QVariant();
    }

    QVariant result;

    qt_safe_read( settingsFD, &buf, sizeof(buf));
    pps_decoder_t decoder;
    pps_decoder_initialize(&decoder, 0);

    if (pps_decoder_parse_pps_str(&decoder, buf) == PPS_DECODER_OK) {
        pps_decoder_push(&decoder, 0);
        pps_node_type_t nodeType = pps_decoder_type(&decoder, property);
        if (nodeType == PPS_TYPE_STRING) {
            const char *dat;
            if (pps_decoder_get_string(&decoder, property, &dat) == PPS_DECODER_OK) {
                result = QString::fromUtf8(dat);
                qCDebug(QT_BT_QNX) << "Read setting" << result;
            } else {
                qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property;
                return QVariant();
            }
        } else if (nodeType == PPS_TYPE_BOOL) {
            bool dat;
            if (pps_decoder_get_bool(&decoder, property, &dat) == PPS_DECODER_OK) {
                result = dat;
                qCDebug(QT_BT_QNX) << "Read setting" << result;
            } else {
                qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property;
                return QVariant();
            }
        } else if (nodeType == PPS_TYPE_NUMBER) {
            int dat;
            if (pps_decoder_get_int(&decoder, property, &dat) == PPS_DECODER_OK) {
                result = dat;
                qCDebug(QT_BT_QNX) << "Read setting" << result;
            } else {
                qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "could not read"<< property;
                return QVariant();
            }
        } else {
            qCDebug(QT_BT_QNX) << Q_FUNC_INFO << "unrecognized entry for settings";
        }
    }
    pps_decoder_cleanup(&decoder);
    qt_safe_close(settingsFD);
    return result;
}
Example #3
0
QVariant ppsRemoteDeviceStatus(const QByteArray &address, const char *property)
{
    int rmFD;
    char buf[ppsBufferSize];
    QByteArray filename = btRemoteDevFDPath;
    filename.append(address);

    if ((rmFD = qt_safe_open(filename.constData(), O_RDONLY)) < 0) {
        qCWarning(QT_BT_QNX) << Q_FUNC_INFO << "failed to open "<< btRemoteDevFDPath << address;
        return false;
    }

    QVariant res;

    qt_safe_read(rmFD, &buf, sizeof(buf));
    pps_decoder_t ppsDecoder;
    pps_decoder_initialize(&ppsDecoder, 0);
    if (pps_decoder_parse_pps_str(&ppsDecoder, buf) == PPS_DECODER_OK) {
        pps_decoder_push(&ppsDecoder, 0);

        //Find out about the node type
        pps_node_type_t nodeType = pps_decoder_type(&ppsDecoder, property);
        if (nodeType == PPS_TYPE_STRING) {
            const char *dat;
            pps_decoder_get_string(&ppsDecoder,property,&dat);
            res = QString::fromUtf8(dat);
        } else if (nodeType == PPS_TYPE_BOOL) {
            bool dat;
            pps_decoder_get_bool(&ppsDecoder,property,&dat);
            res = QVariant(dat);
        } else {
            qCDebug(QT_BT_QNX) << "RDStatus: No node type" << property;
        }
    }
    pps_decoder_cleanup(&ppsDecoder);
    qt_safe_close(rmFD);
    return res;
}
Example #4
0
void ppsDecodeControlResponse()
{
    ppsResult result;
    ResultType resType = UNKNOWN;

    if (ppsCtrlFD != -1) {
        char buf[ppsBufferSize];
        qt_safe_read(ppsCtrlFD, &buf, sizeof(buf) );
        if (buf[0] != '@')
            return;
        qCDebug(QT_BT_QNX) << "CTRL Response" << buf;

        pps_decoder_t ppsDecoder;
        pps_decoder_initialize(&ppsDecoder, 0);
        if (pps_decoder_parse_pps_str(&ppsDecoder, buf) == PPS_DECODER_OK) {
            pps_decoder_push(&ppsDecoder, 0);
            const char *buf;

            //The pps response can either be of type 'res', 'msg' or 'evt'
            if (pps_decoder_get_string(&ppsDecoder, "res", &buf) == PPS_DECODER_OK) {
                result.msg = QString::fromUtf8(buf);
                resType = RESPONSE;
            } else if (pps_decoder_get_string(&ppsDecoder, "msg", &buf) == PPS_DECODER_OK) {
                result.msg = QString::fromUtf8(buf);
                resType = MESSAGE;
            } else if (pps_decoder_get_string(&ppsDecoder, "evt", &buf) == PPS_DECODER_OK) {
                result.msg = QString::fromUtf8(buf);
                resType = EVENT;
            }

            if (pps_decoder_get_string(&ppsDecoder, "id",  &buf) == PPS_DECODER_OK)
                result.id = QString::fromUtf8(buf).toInt();

            //read out the error message if there is one
            if (pps_decoder_get_string(&ppsDecoder, "errstr", &buf) == PPS_DECODER_OK)
                result.errorMsg = QString::fromUtf8(buf);

            int dat;
            if (pps_decoder_get_int(&ppsDecoder, "err", &dat) == PPS_DECODER_OK) {
                result.error = dat;
            }

            //The dat object can be either a string or a array
            pps_node_type_t nodeType = pps_decoder_type(&ppsDecoder,"dat");
            if (nodeType == PPS_TYPE_STRING) {
                pps_decoder_get_string(&ppsDecoder,"dat",&buf);
                result.dat << QString::fromUtf8(buf);
            } else if (nodeType == PPS_TYPE_OBJECT || nodeType == PPS_TYPE_ARRAY) {
                pps_decoder_push(&ppsDecoder,"dat");
                pps_decoder_goto_index(&ppsDecoder, 0);
                int len = pps_decoder_length(&ppsDecoder);

                for (int i = 0; i < len; ++i) {
                    switch ( pps_decoder_type(&ppsDecoder, 0)) {
                    case PPS_TYPE_STRING:
                         result.dat << QString::fromUtf8(pps_decoder_name(&ppsDecoder));
                         pps_decoder_get_string(&ppsDecoder, 0, &buf);
                         result.dat << QString::fromUtf8(buf);
                         break;
                     case PPS_TYPE_NUMBER:
                         result.dat << QString::fromUtf8(pps_decoder_name(&ppsDecoder));
                         double dvalue;
                         pps_decoder_get_double(&ppsDecoder, 0, &dvalue);
                         result.dat << QString::number(dvalue);
                         break;
                     default:
                         pps_decoder_next(&ppsDecoder);
                     }
                 }
            } else {
                qCDebug(QT_BT_QNX) << "Control Response: No node type" << result.msg;
            }
        }
        pps_decoder_cleanup(&ppsDecoder);
    }

    if (result.msg == QStringLiteral("radio_init")) {
        qCDebug(QT_BT_QNX) << "Radio initialized";
    } else if (result.msg == QStringLiteral("access_changed") && __newHostMode != -1) {
        qCDebug(QT_BT_QNX) << "Access changed after radio init";
        ppsSendControlMessage("set_access", QStringLiteral("{\"access\":%1}").arg(__newHostMode), 0);
        __newHostMode = -1;
    }

    if (resType == RESPONSE) {
        QPair<int, QObject*> wMessage = takeObjectInWList(result.id);
        if (wMessage.second != 0)
            wMessage.second->metaObject()->invokeMethod(wMessage.second, "controlReply", Q_ARG(ppsResult, result));
    } else if (resType == EVENT) {
        //qCDebug(QT_BT_QNX) << "Distributing event" << result.msg;
        for (int i=0; i < evtRegistration.size(); i++) {
            if (result.msg == evtRegistration.at(i).first)
                evtRegistration.at(i).second->metaObject()->invokeMethod(evtRegistration.at(i).second, "controlEvent", Q_ARG(ppsResult, result));
        }
    }
}