summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/clientapi.h15
-rw-r--r--common/domain/event.cpp4
-rw-r--r--common/resourceaccess.cpp29
3 files changed, 32 insertions, 16 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 38ec1ee..4948c59 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -193,6 +193,13 @@ public:
193 return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage"; 193 return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/storage";
194 } 194 }
195 195
196 static QByteArray resourceName(const QByteArray &instanceIdentifier)
197 {
198 auto split = instanceIdentifier.split('.');
199 split.removeLast();
200 return split.join('.');
201 }
202
196 /** 203 /**
197 * Asynchronusly load a dataset 204 * Asynchronusly load a dataset
198 */ 205 */
@@ -209,7 +216,7 @@ public:
209 KAsync::iterate(query.resources) 216 KAsync::iterate(query.resources)
210 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { 217 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) {
211 //TODO pass resource identifier to factory 218 //TODO pass resource identifier to factory
212 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); 219 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource));
213 if (facade) { 220 if (facade) {
214 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); 221 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec();
215 //Keep the facade alive for the lifetime of the resultSet. 222 //Keep the facade alive for the lifetime of the resultSet.
@@ -254,7 +261,7 @@ public:
254 template <class DomainType> 261 template <class DomainType>
255 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 262 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
256 //Potentially move to separate thread as well 263 //Potentially move to separate thread as well
257 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 264 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier));
258 facade->create(domainObject).exec().waitForFinished(); 265 facade->create(domainObject).exec().waitForFinished();
259 //TODO return job? 266 //TODO return job?
260 } 267 }
@@ -267,7 +274,7 @@ public:
267 template <class DomainType> 274 template <class DomainType>
268 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 275 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
269 //Potentially move to separate thread as well 276 //Potentially move to separate thread as well
270 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 277 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier));
271 facade->modify(domainObject).exec().waitForFinished(); 278 facade->modify(domainObject).exec().waitForFinished();
272 //TODO return job? 279 //TODO return job?
273 } 280 }
@@ -278,7 +285,7 @@ public:
278 template <class DomainType> 285 template <class DomainType>
279 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 286 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
280 //Potentially move to separate thread as well 287 //Potentially move to separate thread as well
281 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceIdentifier); 288 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier));
282 facade->remove(domainObject).exec().waitForFinished(); 289 facade->remove(domainObject).exec().waitForFinished();
283 //TODO return job? 290 //TODO return job?
284 } 291 }
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index c435c6b..08ce698 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -36,7 +36,7 @@ ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query,
36{ 36{
37 QVector<QByteArray> keys; 37 QVector<QByteArray> keys;
38 if (query.propertyFilter.contains("uid")) { 38 if (query.propertyFilter.contains("uid")) {
39 Index uidIndex(Akonadi2::Store::storageLocation(), resourceInstanceIdentifier + "index.uid", Akonadi2::Storage::ReadOnly); 39 Index uidIndex(Akonadi2::Store::storageLocation(), resourceInstanceIdentifier + ".index.uid", Akonadi2::Storage::ReadOnly);
40 uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) { 40 uidIndex.lookup(query.propertyFilter.value("uid").toByteArray(), [&](const QByteArray &value) {
41 keys << value; 41 keys << value;
42 }, 42 },
@@ -50,7 +50,7 @@ ResultSet TypeImplementation<Event>::queryIndexes(const Akonadi2::Query &query,
50 50
51void TypeImplementation<Event>::index(const Event &type) 51void TypeImplementation<Event>::index(const Event &type)
52{ 52{
53 Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + "index.uid", Akonadi2::Storage::ReadWrite); 53 Index uidIndex(Akonadi2::Store::storageLocation(), type.resourceInstanceIdentifier() + ".index.uid", Akonadi2::Storage::ReadWrite);
54 const auto uid = type.getProperty("uid"); 54 const auto uid = type.getProperty("uid");
55 if (uid.isValid()) { 55 if (uid.isValid()) {
56 uidIndex.add(uid.toByteArray(), type.identifier()); 56 uidIndex.add(uid.toByteArray(), type.identifier());
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index feffcf4..249dd55 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -69,10 +69,11 @@ public:
69class ResourceAccess::Private 69class ResourceAccess::Private
70{ 70{
71public: 71public:
72 Private(const QByteArray &name, ResourceAccess *ra); 72 Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *ra);
73 KAsync::Job<void> tryToConnect(); 73 KAsync::Job<void> tryToConnect();
74 KAsync::Job<void> initializeSocket(); 74 KAsync::Job<void> initializeSocket();
75 QByteArray resourceName; 75 QByteArray resourceName;
76 QByteArray resourceInstanceIdentifier;
76 QSharedPointer<QLocalSocket> socket; 77 QSharedPointer<QLocalSocket> socket;
77 QByteArray partialMessageBuffer; 78 QByteArray partialMessageBuffer;
78 flatbuffers::FlatBufferBuilder fbb; 79 flatbuffers::FlatBufferBuilder fbb;
@@ -82,8 +83,9 @@ public:
82 uint messageId; 83 uint messageId;
83}; 84};
84 85
85ResourceAccess::Private::Private(const QByteArray &name, ResourceAccess *q) 86ResourceAccess::Private::Private(const QByteArray &name, const QByteArray &instanceIdentifier, ResourceAccess *q)
86 : resourceName(name), 87 : resourceName(name),
88 resourceInstanceIdentifier(instanceIdentifier),
87 messageId(0) 89 messageId(0)
88{ 90{
89} 91}
@@ -118,7 +120,7 @@ KAsync::Job<void> ResourceAccess::Private::tryToConnect()
118 [this](KAsync::Future<void> &future) { 120 [this](KAsync::Future<void> &future) {
119 Trace() << "Loop"; 121 Trace() << "Loop";
120 KAsync::wait(50) 122 KAsync::wait(50)
121 .then(connectToServer(resourceName)) 123 .then(connectToServer(resourceInstanceIdentifier))
122 .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { 124 .then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) {
123 Q_ASSERT(s); 125 Q_ASSERT(s);
124 socket = s; 126 socket = s;
@@ -134,7 +136,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket()
134{ 136{
135 return KAsync::start<void>([this](KAsync::Future<void> &future) { 137 return KAsync::start<void>([this](KAsync::Future<void> &future) {
136 Trace() << "Trying to connect"; 138 Trace() << "Trying to connect";
137 connectToServer(resourceName).then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) { 139 connectToServer(resourceInstanceIdentifier).then<void, QSharedPointer<QLocalSocket> >([this, &future](const QSharedPointer<QLocalSocket> &s) {
138 Trace() << "Connected to resource, without having to start it."; 140 Trace() << "Connected to resource, without having to start it.";
139 Q_ASSERT(s); 141 Q_ASSERT(s);
140 socket = s; 142 socket = s;
@@ -144,7 +146,7 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket()
144 Trace() << "Failed to connect, starting resource"; 146 Trace() << "Failed to connect, starting resource";
145 //We failed to connect, so let's start the resource 147 //We failed to connect, so let's start the resource
146 QStringList args; 148 QStringList args;
147 args << resourceName; 149 args << resourceInstanceIdentifier;
148 qint64 pid = 0; 150 qint64 pid = 0;
149 if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) { 151 if (QProcess::startDetached("akonadi2_synchronizer", args, QDir::homePath(), &pid)) {
150 Trace() << "Started resource " << pid; 152 Trace() << "Started resource " << pid;
@@ -159,9 +161,16 @@ KAsync::Job<void> ResourceAccess::Private::initializeSocket()
159 }); 161 });
160} 162}
161 163
162ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) 164static QByteArray getResourceName(const QByteArray &instanceIdentifier)
165{
166 auto split = instanceIdentifier.split('.');
167 split.removeLast();
168 return split.join('.');
169}
170
171ResourceAccess::ResourceAccess(const QByteArray &resourceInstanceIdentifier, QObject *parent)
163 : QObject(parent), 172 : QObject(parent),
164 d(new Private(resourceName, this)) 173 d(new Private(getResourceName(resourceInstanceIdentifier), resourceInstanceIdentifier, this))
165{ 174{
166 log("Starting access"); 175 log("Starting access");
167} 176}
@@ -316,7 +325,7 @@ void ResourceAccess::disconnected()
316void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error) 325void ResourceAccess::connectionError(QLocalSocket::LocalSocketError error)
317{ 326{
318 if (error == QLocalSocket::PeerClosedError) { 327 if (error == QLocalSocket::PeerClosedError) {
319 Log(d->resourceName) << "The resource closed the connection."; 328 Log(d->resourceInstanceIdentifier) << "The resource closed the connection.";
320 } else { 329 } else {
321 Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString()); 330 Warning() << QString("Connection error: %1 : %2").arg(error).arg(d->socket->errorString());
322 } 331 }
@@ -379,7 +388,7 @@ bool ResourceAccess::processMessageBuffer()
379 auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize); 388 auto buffer = GetNotification(d->partialMessageBuffer.constData() + headerSize);
380 switch (buffer->type()) { 389 switch (buffer->type()) {
381 case Akonadi2::NotificationType::NotificationType_Shutdown: 390 case Akonadi2::NotificationType::NotificationType_Shutdown:
382 Log(d->resourceName) << "Received shutdown notification."; 391 Log(d->resourceInstanceIdentifier) << "Received shutdown notification.";
383 close(); 392 close();
384 break; 393 break;
385 default: 394 default:
@@ -406,7 +415,7 @@ void ResourceAccess::callCallbacks(int id)
406 415
407void ResourceAccess::log(const QString &message) 416void ResourceAccess::log(const QString &message)
408{ 417{
409 Log(d->resourceName) << this << message; 418 Log(d->resourceInstanceIdentifier) << this << message;
410} 419}
411 420
412} 421}