Handling delayed dbus method
-
Hello everyone!
I am developing dbus api and encontered with this, How to handle delayed dbus call? I have daemon app which is handling dbus requests and share plugin qml extension which is sending dbus method call to daemon app.
I followed this tutorial to create delayed method. After that I request some data from internet. Here is code:
//Creating delayed message QVariant DBusAdaptor::getChatList(const int offset, const QDBusMessage &message) { m_delayedList.append(RequestData()); message.setDelayedReply(true); m_delayedList.last().reply = message.createReply(); QDBusConnection::sessionBus().send(m_delayedList.last().reply); tdlibJson->getChats(0, std::numeric_limits<std::int64_t>::max(), 5, c_extraName); return QVariant(); } //Sending delayed message with data void DBusAdaptor::sendChatList() { QDBusMessage reply = m_delayedList.last().reply; qDebug() << m_chats[0]; reply << m_chats[0] << m_chats[1]; QDBusConnection::sessionBus().send(reply); m_delayedList.removeLast(); m_chatIds.clear(); m_chats.clear(); } //Filling list with data which will be send over dbus. void DBusAdaptor::addChatItem(const QJsonObject &chatObject) { if (chatObject.keys().contains("@extra")) if (chatObject["@extra"].toString() == c_extraName) m_chats.append(chatObject.toVariantMap()); qDebug() << m_chats.size() << m_chatIds.size(); if (m_chats.size() == m_chatIds.size()) emit sendData(); }
In etension plugin I use this code:
QDBusPendingCall async = remoteAppIface->asyncCall(c_dbusMethod, 0); dbusWatcher = new QDBusPendingCallWatcher(async, this); connect(dbusWatcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher * call) { QDBusPendingReply<QString, QByteArray> reply = *call; if (reply.isError()) qDebug() << reply.error(); else qDebug() << reply.argumentAt<0>(); call->deleteLater(); });
And I can't get data from method, all I get is emptyness with error message:
QDBusError("org.freedesktop.DBus.Error.InvalidSignature","Unexpected reply signature: got \"\", expected \"say\"")
I assume that handling delayed methods are different, but can't find any examples. Is there on internet any examples of this? Or There is an error in code?
Thanks in advance
-
I've solved it.
To handle long I did not have to send immediately reply (even though tutorial said that we have to). And delayed reply will be send.
Also in extension,
QDBusPendingReply<QString, QByteArray> reply = *call;
setting expecting signature to\"say\"
and not looking to xml interface.