QPpsAttributeList QPpsObjectPrivate::decodeArray(pps_decoder_t *decoder, bool *ok) { QPpsAttributeList list; int length = pps_decoder_length(decoder); for (int i = 0; i < length; ++i) { // Force movement to a specific index. pps_decoder_error_t error = pps_decoder_goto_index(decoder, i); if (error != PPS_DECODER_OK) { qWarning() << "QPpsObjectPrivate::decodeArray: pps_decoder_goto_index failed"; *ok = false; return QPpsAttributeList(); } QPpsAttribute ppsAttribute = decodeData(decoder); if (!ppsAttribute.isValid()) { *ok = false; return QPpsAttributeList(); } list << ppsAttribute; } *ok = true; return list; }
QPpsAttributeMap QPpsObjectPrivate::decodeObject(pps_decoder_t *decoder, bool *ok) { QPpsAttributeMap map; int length = pps_decoder_length(decoder); for (int i = 0; i < length; ++i) { // Force movement to a specific index. pps_decoder_error_t error = pps_decoder_goto_index(decoder, i); if (error != PPS_DECODER_OK) { qWarning() << "QPpsObjectPrivate::decodeObject: pps_decoder_goto_index failed"; *ok = false; return QPpsAttributeMap(); } QString name = QString::fromUtf8(pps_decoder_name(decoder)); QPpsAttribute ppsAttribute = decodeData(decoder); if (!ppsAttribute.isValid()) { *ok = false; return QPpsAttributeMap(); } map[name] = ppsAttribute; } *ok = true; return map; }
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)); } } }