summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-31 21:08:39 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-10-31 23:26:26 +0100
commit25d08af0851b56db664cee7f6463532d7c103d33 (patch)
tree7ff24ea3c435d656df9de059e6ff438103c387a6
parent8d59bbdebcca2293d5b3b1da903c39845f7ba1a9 (diff)
downloadsink-25d08af0851b56db664cee7f6463532d7c103d33.tar.gz
sink-25d08af0851b56db664cee7f6463532d7c103d33.zip
Fixed shutdown and synchronize commands
-rw-r--r--common/clientapi.cpp23
-rw-r--r--common/clientapi.h11
-rw-r--r--examples/client/main.cpp4
-rw-r--r--tests/dummyresourcetest.cpp2
4 files changed, 28 insertions, 12 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp
index aa3abb4..f99ebb8 100644
--- a/common/clientapi.cpp
+++ b/common/clientapi.cpp
@@ -69,10 +69,10 @@ QList<QByteArray> Store::getResources(const QList<QByteArray> &resourceFilter, c
69 return resources; 69 return resources;
70} 70}
71 71
72void Store::shutdown(const QByteArray &identifier) 72KAsync::Job<void> Store::shutdown(const QByteArray &identifier)
73{ 73{
74 Trace() << "shutdown"; 74 Trace() << "shutdown";
75 ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](const QSharedPointer<QLocalSocket> &socket, KAsync::Future<void> &future) { 75 return ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](QSharedPointer<QLocalSocket> socket, KAsync::Future<void> &future) {
76 //We can't currently reuse the socket 76 //We can't currently reuse the socket
77 socket->close(); 77 socket->close();
78 auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier); 78 auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier);
@@ -83,15 +83,24 @@ void Store::shutdown(const QByteArray &identifier)
83 }, 83 },
84 [](int, const QString &) { 84 [](int, const QString &) {
85 //Resource isn't started, nothing to shutdown 85 //Resource isn't started, nothing to shutdown
86 }).exec().waitForFinished(); 86 })
87 //FIXME JOBAPI this is only required because we don't care about the return value of connectToServer
88 .template then<void>([](){});
87} 89}
88 90
89void Store::synchronize(const QByteArray &identifier) 91KAsync::Job<void> Store::synchronize(const Akonadi2::Query &query)
90{ 92{
91 Trace() << "synchronize"; 93 Trace() << "synchronize";
92 auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier); 94 return KAsync::iterate(query.resources)
93 resourceAccess->open(); 95 .template each<void, QByteArray>([query](const QByteArray &resource, KAsync::Future<void> &future) {
94 resourceAccess->synchronizeResource(true, false).exec().waitForFinished(); 96 auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resource);
97 resourceAccess->open();
98 resourceAccess->synchronizeResource(true, false).then<void>([&future]() {
99 future.setFinished();
100 }).exec();
101 })
102 //FIXME JOBAPI this is only required because we don't care about the return value of each (and each shouldn't even have a return value)
103 .template then<void>([](){});
95} 104}
96 105
97} // namespace Akonadi2 106} // namespace Akonadi2
diff --git a/common/clientapi.h b/common/clientapi.h
index 4e6db09..9a32188 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -153,10 +153,15 @@ public:
153 }); 153 });
154 } 154 }
155 155
156 static void shutdown(const QByteArray &resourceIdentifier); 156 /**
157 * Shutdown resource.
158 */
159 static KAsync::Job<void> shutdown(const QByteArray &resourceIdentifier);
157 160
158 //TODO do we really want this command? And if yes, shouldn't it take a query to specify what to sync exactly? 161 /**
159 static void synchronize(const QByteArray &resourceIdentifier); 162 * Synchronize data to local cache.
163 */
164 static KAsync::Job<void> synchronize(const Akonadi2::Query &query);
160}; 165};
161 166
162 167
diff --git a/examples/client/main.cpp b/examples/client/main.cpp
index 52f3607..0a1a725 100644
--- a/examples/client/main.cpp
+++ b/examples/client/main.cpp
@@ -59,7 +59,9 @@ public:
59 auto syncButton = new QPushButton(this); 59 auto syncButton = new QPushButton(this);
60 syncButton->setText("Synchronize!"); 60 syncButton->setText("Synchronize!");
61 QObject::connect(syncButton, &QPushButton::pressed, []() { 61 QObject::connect(syncButton, &QPushButton::pressed, []() {
62 Akonadi2::Store::synchronize("org.kde.dummy.instance1"); 62 Akonadi2::Query query;
63 query.resources << "org.kde.dummy.instance1";
64 Akonadi2::Store::synchronize(query);
63 }); 65 });
64 66
65 auto removeButton = new QPushButton(this); 67 auto removeButton = new QPushButton(this);
diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp
index ae71912..d027266 100644
--- a/tests/dummyresourcetest.cpp
+++ b/tests/dummyresourcetest.cpp
@@ -31,7 +31,7 @@ private Q_SLOTS:
31 31
32 void cleanup() 32 void cleanup()
33 { 33 {
34 Akonadi2::Store::shutdown("org.kde.dummy.instance1"); 34 Akonadi2::Store::shutdown(QByteArray("org.kde.dummy.instance1")).exec().waitForFinished();
35 DummyResource::removeFromDisk("org.kde.dummy.instance1"); 35 DummyResource::removeFromDisk("org.kde.dummy.instance1");
36 auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy"); 36 auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy");
37 QVERIFY(factory); 37 QVERIFY(factory);