From 573051b8df4a2961b4ba8a1b7e31f1437517f9c8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 9 Feb 2016 15:47:09 +0100 Subject: Moved some API --- common/clientapi.cpp | 8 ++--- common/clientapi.h | 77 +++++++++++++++++++++------------------- tests/dummyresourcebenchmark.cpp | 4 +-- tests/dummyresourcetest.cpp | 16 ++++----- tests/maildirresourcetest.cpp | 45 +++++++++++------------ tests/modelinteractivitytest.cpp | 2 +- tests/querytest.cpp | 12 +++---- 7 files changed, 84 insertions(+), 80 deletions(-) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 73bc194..e6878a6 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -160,7 +160,7 @@ KAsync::Job Store::remove(const DomainType &domainObject) }); } -KAsync::Job Store::shutdown(const QByteArray &identifier) +KAsync::Job Resources::shutdown(const QByteArray &identifier) { Trace() << "shutdown " << identifier; auto time = QSharedPointer::create(); @@ -183,7 +183,7 @@ KAsync::Job Store::shutdown(const QByteArray &identifier) .template then([](){}); } -KAsync::Job Store::start(const QByteArray &identifier) +KAsync::Job Resources::start(const QByteArray &identifier) { Trace() << "start " << identifier; auto time = QSharedPointer::create(); @@ -231,7 +231,7 @@ KAsync::Job Store::synchronize(const Sink::Query &query) .template then([](){}); } -KAsync::Job Store::flushMessageQueue(const QByteArrayList &resourceIdentifier) +KAsync::Job Resources::flushMessageQueue(const QByteArrayList &resourceIdentifier) { Trace() << "flushMessageQueue" << resourceIdentifier; return KAsync::iterate(resourceIdentifier) @@ -247,7 +247,7 @@ KAsync::Job Store::flushMessageQueue(const QByteArrayList &resourceIdentif .template then([](){}); } -KAsync::Job Store::flushReplayQueue(const QByteArrayList &resourceIdentifier) +KAsync::Job Resources::flushReplayQueue(const QByteArrayList &resourceIdentifier) { return flushMessageQueue(resourceIdentifier); } diff --git a/common/clientapi.h b/common/clientapi.h index 19d42e0..36c923b 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -36,6 +36,19 @@ namespace Sink { class ResourceAccess; class Notification; +class SINKCOMMON_EXPORT Notifier { +public: + Notifier(const QSharedPointer &resourceAccess); + Notifier(const QByteArray &resourceInstanceIdentifier); + // Notifier(const QByteArrayList &resource); + void registerHandler(std::function); + +private: + class Private; + QSharedPointer d; +}; + + /** * Store interface used in the client API. */ @@ -81,30 +94,6 @@ public: */ static KAsync::Job synchronize(const Sink::Query &query); - /** - * Shutdown resource. - */ - static KAsync::Job shutdown(const QByteArray &resourceIdentifier); - - /** - * Start resource. - * - * The resource is ready for operation once this command completes. - * This command is only necessary if a resource was shutdown previously, - * otherwise the resource process will automatically start as necessary. - */ - static KAsync::Job start(const QByteArray &resourceIdentifier); - - /** - * Flushes any pending messages to disk - */ - static KAsync::Job flushMessageQueue(const QByteArrayList &resourceIdentifier); - - /** - * Flushes any pending messages that haven't been replayed to the source. - */ - static KAsync::Job flushReplayQueue(const QByteArrayList &resourceIdentifier); - /** * Removes a resource from disk. */ @@ -128,21 +117,35 @@ public: }; namespace Resources { - template - KAsync::Job SINKCOMMON_EXPORT inspect(const Inspection &inspectionCommand); -} -class SINKCOMMON_EXPORT Notifier { -public: - Notifier(const QSharedPointer &resourceAccess); - Notifier(const QByteArray &resourceInstanceIdentifier); - // Notifier(const QByteArrayList &resource); - void registerHandler(std::function); +template +KAsync::Job SINKCOMMON_EXPORT inspect(const Inspection &inspectionCommand); -private: - class Private; - QSharedPointer d; -}; +/** + * Shutdown resource. + */ +KAsync::Job SINKCOMMON_EXPORT shutdown(const QByteArray &resourceIdentifier); + +/** + * Start resource. + * + * The resource is ready for operation once this command completes. + * This command is only necessary if a resource was shutdown previously, + * otherwise the resource process will automatically start as necessary. + */ +KAsync::Job SINKCOMMON_EXPORT start(const QByteArray &resourceIdentifier); + +/** + * Flushes any pending messages to disk + */ +KAsync::Job SINKCOMMON_EXPORT flushMessageQueue(const QByteArrayList &resourceIdentifier); + +/** + * Flushes any pending messages that haven't been replayed to the source. + */ +KAsync::Job SINKCOMMON_EXPORT flushReplayQueue(const QByteArrayList &resourceIdentifier); + +} } diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 089fc08..6170f49 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -102,7 +102,7 @@ private Q_SLOTS: QTRY_VERIFY(gotNotification); QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); - Sink::Store::shutdown("org.kde.dummy.instance1").exec().waitForFinished(); + Sink::Resources::shutdown("org.kde.dummy.instance1").exec().waitForFinished(); qDebug() << "Single command took [ms]: " << duration; } @@ -127,7 +127,7 @@ private Q_SLOTS: { Sink::Query query; query.resources << "org.kde.dummy.instance1"; - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); } auto allProcessedTime = time.elapsed(); diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index bfa4885..e74fe25 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -65,7 +65,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); auto model = Sink::Store::loadModel(query); @@ -89,7 +89,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("uid", "testuid"); @@ -117,7 +117,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); query.propertyFilter.insert("summary", "summaryValue2"); @@ -151,7 +151,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); @@ -168,7 +168,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->rowCount(QModelIndex()) >= 1); @@ -191,7 +191,7 @@ private Q_SLOTS: query.propertyFilter.insert("uid", "testuid"); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //Test create Sink::ApplicationDomain::Event event2; @@ -210,7 +210,7 @@ private Q_SLOTS: Sink::Store::modify(event2).exec().waitForFinished(); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //Test modify { @@ -225,7 +225,7 @@ private Q_SLOTS: Sink::Store::remove(event2).exec().waitForFinished(); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //Test remove { diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index e502d10..c5c9348 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -68,7 +68,7 @@ private Q_SLOTS: void cleanup() { - Sink::Store::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); + Sink::Resources::shutdown(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); MaildirResource::removeFromDisk("org.kde.maildir.instance1"); QDir dir(targetPath); dir.removeRecursively(); @@ -80,7 +80,7 @@ private Q_SLOTS: qDebug() << "-----------------------------------------"; qDebug(); copyRecursively(TESTDATAPATH "/maildir1", targetPath); - Sink::Store::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); + Sink::Resources::start(QByteArray("org.kde.maildir.instance1")).exec().waitForFinished(); } void testListFolders() @@ -90,7 +90,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -105,7 +105,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -123,7 +123,7 @@ private Q_SLOTS: //Ensure all local data is processed auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); - Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto result = Store::fetchOne( Query::ResourceFilter("org.kde.maildir.instance1") + Query::RequestedProperties(QByteArrayList() << "name") ) @@ -149,7 +149,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto mailModel = Sink::Store::loadModel(query); QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -172,7 +172,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/"; QDir dir(targetPath); @@ -180,7 +180,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -196,11 +196,11 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto mailModel = Sink::Store::loadModel(query); QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -215,7 +215,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/cur/1365777830.R28.localhost.localdomain:2,S"; QFile file(targetPath); @@ -223,7 +223,7 @@ private Q_SLOTS: //Ensure all local data is processed Sink::Store::synchronize(query).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto mailModel = Sink::Store::loadModel(query); QTRY_VERIFY(mailModel->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -236,7 +236,7 @@ private Q_SLOTS: query.resources << "org.kde.maildir.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); folder.setProperty("name", "testCreateFolder"); @@ -244,7 +244,7 @@ private Q_SLOTS: Sink::Store::create(folder).exec().waitForFinished(); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/testCreateFolder"; QFileInfo file(targetPath); @@ -262,7 +262,7 @@ private Q_SLOTS: Sink::ApplicationDomain::Folder folder("org.kde.maildir.instance1"); folder.setProperty("name", "testCreateFolder"); Sink::Store::create(folder).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); QTRY_VERIFY(QFileInfo(targetPath).exists()); Sink::Query folderQuery; @@ -274,7 +274,7 @@ private Q_SLOTS: auto createdFolder = model->index(0, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value(); Sink::Store::remove(*createdFolder).exec().waitForFinished(); - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); QTRY_VERIFY(!QFileInfo(targetPath).exists()); } @@ -284,15 +284,16 @@ private Q_SLOTS: query.resources << "org.kde.maildir.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); Sink::ApplicationDomain::Mail mail("org.kde.maildir.instance1"); mail.setProperty("name", "testCreateMail"); + //FIXME instead of properties, ensure the mimeMessage property is used and the file is moved as expected Sink::Store::create(mail).exec().waitForFinished(); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto targetPath = tempDir.path() + "/maildir1/new"; QDir dir(targetPath); @@ -307,7 +308,7 @@ private Q_SLOTS: auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); - Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto result = Store::fetchOne( Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") @@ -324,7 +325,7 @@ private Q_SLOTS: auto mail = mails.first(); return Store::remove(*mail) - .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already + .then(Resources::flushReplayQueue(query.resources)) //The change needs to be replayed already .then(Resources::inspect(Resources::Inspection::ExistenceInspection(*mail, false))); }) .then([](){}); @@ -341,7 +342,7 @@ private Q_SLOTS: auto query = Query::ResourceFilter("org.kde.maildir.instance1"); Store::synchronize(query).exec().waitForFinished(); - Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Resources::flushMessageQueue(query.resources).exec().waitForFinished(); Folder f; @@ -361,7 +362,7 @@ private Q_SLOTS: auto mail = mails.first(); mail->setProperty("unread", true); return Store::modify(*mail) - .then(Store::flushReplayQueue(query.resources)) //The change needs to be replayed already + .then(Resources::flushReplayQueue(query.resources)) //The change needs to be replayed already .then(Resources::inspect(Resources::Inspection::PropertyInspection(*mail, "unread", true))) .then(Resources::inspect(Resources::Inspection::PropertyInspection(*mail, "subject", mail->getProperty("subject")))); }) diff --git a/tests/modelinteractivitytest.cpp b/tests/modelinteractivitytest.cpp index 7b7d131..f180f9c 100644 --- a/tests/modelinteractivitytest.cpp +++ b/tests/modelinteractivitytest.cpp @@ -73,7 +73,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; query.liveQuery = true; - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //Test QTime time; diff --git a/tests/querytest.cpp b/tests/querytest.cpp index cac81c5..89d8693 100644 --- a/tests/querytest.cpp +++ b/tests/querytest.cpp @@ -86,7 +86,7 @@ private Q_SLOTS: query.liveQuery = false; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -161,7 +161,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -181,7 +181,7 @@ private Q_SLOTS: query.parentProperty = "parent"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch after the data is available and don't rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -210,7 +210,7 @@ private Q_SLOTS: query.propertyFilter.insert("uid", "test1"); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); @@ -230,7 +230,7 @@ private Q_SLOTS: query.resources << "org.kde.dummy.instance1"; //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); auto model = Sink::Store::loadModel(query); QTRY_VERIFY(model->data(QModelIndex(), Sink::Store::ChildrenFetchedRole).toBool()); @@ -251,7 +251,7 @@ private Q_SLOTS: query.propertyFilter.insert("folder", folderEntity->identifier()); //Ensure all local data is processed - Sink::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + Sink::Resources::flushMessageQueue(query.resources).exec().waitForFinished(); //We fetch before the data is available and rely on the live query mechanism to deliver the actual data auto model = Sink::Store::loadModel(query); -- cgit v1.2.3