Verified Commit 32dade8e authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Make item delivery more robust

Use DBus error message to signal an error in item delivery.
parent ea6297e2
......@@ -39,15 +39,9 @@ class CacheTest : public QObject
private:
void enableAgent(const QString &id, bool enable)
{
AgentInstance instance;
foreach (AgentInstance agent, Akonadi::AgentManager::self()->instances()) { //krazy:exclude=foreach
if (agent.identifier() == id) {
instance = agent;
break;
}
}
auto instance = AgentManager::self()->instance(id);
QVERIFY(instance.isValid());
instance.setIsOnline(enable);
QTRY_COMPARE(Akonadi::AgentManager::self()->instance(id).isOnline(), enable);
}
......
......@@ -53,6 +53,9 @@
#include "favoritecollectionattribute.h"
#include "akonadiagentbase_debug.h"
#include <shared/akranges.h>
#include <KLocalizedString>
#include <KAboutData>
......@@ -61,6 +64,7 @@
#include <QApplication>
using namespace Akonadi;
using namespace AkRanges;
class Akonadi::ResourceBasePrivate : public AgentBasePrivate
{
......@@ -777,25 +781,20 @@ void ResourceBase::changeCommitted(const Tag &tag)
connect(job, SIGNAL(result(KJob*)), SLOT(changeCommittedResult(KJob*)));
}
QString ResourceBase::requestItemDelivery(const QList<qint64> &uids, const QByteArrayList &parts)
void ResourceBase::requestItemDelivery(const QVector<qint64> &uids, const QByteArrayList &parts)
{
Q_D(ResourceBase);
if (!isOnline()) {
const QString errorMsg = i18nc("@info", "Cannot fetch item in offline mode.");
sendErrorReply(QDBusError::Failed, errorMsg);
Q_EMIT error(errorMsg);
return errorMsg;
return;
}
setDelayedReply(true);
Item::List items;
items.reserve(uids.size());
for (auto uid : uids) {
items.push_back(Item(uid));
}
const auto items = uids | Views::transform([](const auto uid) { return Item{uid}; }) | Actions::toQVector;
d->scheduler->scheduleItemsFetch(items, QSet<QByteArray>::fromList(parts), message());
return QString();
}
void ResourceBase::collectionsRetrieved(const Collection::List &collections)
......
......@@ -847,7 +847,7 @@ private:
// dbus resource interface
friend class ::Akonadi__ResourceAdaptor;
QString requestItemDelivery(const QList<qint64> &uids, const QByteArrayList &parts);
void requestItemDelivery(const QVector<qint64> &uids, const QByteArrayList &parts);
private:
Q_DECLARE_PRIVATE(ResourceBase)
......
......@@ -567,14 +567,16 @@ void ResourceScheduler::collectionRemoved(const Akonadi::Collection &collection)
void ResourceScheduler::Task::sendDBusReplies(const QString &errorMsg)
{
for (const QDBusMessage &msg : qAsConst(dbusMsgs)) {
QDBusMessage reply(msg.createReply());
const QString methodName = msg.member();
if (methodName == QLatin1String("requestItemDelivery")) {
reply << errorMsg;
} else if (methodName.isEmpty()) {
qCDebug(AKONADIAGENTBASE_LOG) << "Sending dbus reply for method" << methodName << "with error" << errorMsg;
QDBusMessage reply;
if (!errorMsg.isEmpty()) {
reply = msg.createErrorReply(QDBusError::Failed, errorMsg);
} else if (msg.member() == QLatin1String("requestItemDelivery")) {
reply = msg.createReply();
} else if (msg.member().isEmpty()) {
continue; // unittest calls scheduleItemFetch with empty QDBusMessage
} else {
qCCritical(AKONADIAGENTBASE_LOG) << "Got unexpected member:" << methodName;
qCCritical(AKONADIAGENTBASE_LOG) << "ResourceScheduler: got unexpected method name :" << msg.member();
}
QDBusConnection::sessionBus().send(reply);
}
......
......@@ -10,8 +10,7 @@
</signal>
<signal name="collectionTreeSynchronized"/>
<method name="requestItemDelivery">
<arg type="s" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList&lt;qlonglong&gt;"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVector&lt;qlonglong&gt;"/>
<arg name="uids" type="ax" direction="in"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QByteArrayList"/>
<arg name="parts" type="aay" direction="in"/>
......
......@@ -21,7 +21,6 @@
#include "itemretrievalrequest.h"
#include "resourceinterface.h"
#include "akonadiserver_debug.h"
#include <shared/akranges.h>
#include <QDBusPendingCallWatcher>
......@@ -44,7 +43,7 @@ void ItemRetrievalJob::start()
// call the resource
if (m_interface) {
m_active = true;
auto reply = m_interface->requestItemDelivery(request().ids | AkRanges::Actions::toQList, request().parts);
auto reply = m_interface->requestItemDelivery(request().ids, request().parts);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished,
this, &ItemRetrievalJob::callFinished);
......@@ -65,7 +64,7 @@ void ItemRetrievalJob::kill()
void ItemRetrievalJob::callFinished(QDBusPendingCallWatcher *watcher)
{
watcher->deleteLater();
QDBusPendingReply<QString> reply = *watcher;
QDBusPendingReply<void> reply = *watcher;
if (m_active) {
m_active = false;
if (reply.isError()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment