void PendingCallWatcher::readNdefMessagesFinished(QDBusPendingCallWatcher *watcher)
{
    QNearFieldTarget::RequestId id = m_pendingNdefReads.take(watcher);

    if (!id.isValid()) {
        watcher->deleteLater();
        return;
    }

    QDBusPendingReply<QList<QByteArray> > reply = *watcher;
    if (reply.isError()) {
        QMetaObject::invokeMethod(parent(), "error",
                                  Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::NdefReadError),
                                  Q_ARG(QNearFieldTarget::RequestId, id));
    } else {
        const QList<QByteArray> data = reply.argumentAt<0>();
        foreach (const QByteArray &m, data) {
            qDebug() << Q_FUNC_INFO << m.toHex();
            const QNdefMessage message = QNdefMessage::fromByteArray(m);

            qDebug() << "record count:" << message.count();
            foreach (const QNdefRecord &record, message)
                qDebug() << record.typeNameFormat() << record.type() << record.payload().toHex();

            QMetaObject::invokeMethod(parent(), "ndefMessageRead", Q_ARG(QNdefMessage, message));
        }

        QMetaObject::invokeMethod(parent(), "requestCompleted",
                                  Q_ARG(QNearFieldTarget::RequestId, id));
    }
Пример #2
0
void NfcMaster::onTargetDetected(QNearFieldTarget *target) {
    qDebug()<<Q_FUNC_INFO;
    qDebug()<<Q_FUNC_INFO<<"supported accessmethods:"<<target->accessMethods();
    QNearFieldTarget::RequestId id = target->sendCommand("/usr/bin/gallery");
    qDebug()<<"req id is valid "<<id.isValid();
    // Send url to peer nfc device is not working :(
//    QUrl url = QUrl::fromUserInput(QString("www.google.com"));
//    if(url.isValid())
//        qDebug()<<Q_FUNC_INFO<<" url is valid";
//    QNdefMessage msg;
//    QNdefNfcUriRecord rec;
//    rec.setUri(url);
//    msg.append(rec);
//    QNearFieldTarget::RequestId id = target->writeNdefMessages(QList<QNdefMessage>()<<msg);
//    qDebug()<<"req id is valid "<<id.isValid();
}
void PendingCallWatcher::sendCommandFinished(QDBusPendingCallWatcher *watcher)
{
    QNearFieldTarget::RequestId id = m_pendingCommands.take(watcher);

    if (!id.isValid()) {
        watcher->deleteLater();
        return;
    }

    QDBusPendingReply<QByteArray> reply = *watcher;
    if (reply.isError()) {
        QMetaObject::invokeMethod(parent(), "error",
                                  Q_ARG(QNearFieldTarget::Error, QNearFieldTarget::UnknownError),
                                  Q_ARG(QNearFieldTarget::RequestId, id));
    } else {
        const QByteArray data = reply.argumentAt<0>();
        QMetaObject::invokeMethod(parent(), "handleResponse",
                                  Q_ARG(QNearFieldTarget::RequestId, id),
                                  Q_ARG(QByteArray, data));
    }

    watcher->deleteLater();
}