summaryrefslogtreecommitdiffstats
path: root/common/resourceaccess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/resourceaccess.cpp')
-rw-r--r--common/resourceaccess.cpp63
1 files changed, 53 insertions, 10 deletions
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp
index a4a5795..ef4e64c 100644
--- a/common/resourceaccess.cpp
+++ b/common/resourceaccess.cpp
@@ -26,6 +26,10 @@
26#include "common/revisionupdate_generated.h" 26#include "common/revisionupdate_generated.h"
27#include "common/synchronize_generated.h" 27#include "common/synchronize_generated.h"
28#include "common/notification_generated.h" 28#include "common/notification_generated.h"
29#include "common/createentity_generated.h"
30#include "common/modifyentity_generated.h"
31#include "common/deleteentity_generated.h"
32#include "common/entitybuffer.h"
29#include "log.h" 33#include "log.h"
30 34
31#include <QCoreApplication> 35#include <QCoreApplication>
@@ -79,7 +83,6 @@ public:
79 QByteArray resourceInstanceIdentifier; 83 QByteArray resourceInstanceIdentifier;
80 QSharedPointer<QLocalSocket> socket; 84 QSharedPointer<QLocalSocket> socket;
81 QByteArray partialMessageBuffer; 85 QByteArray partialMessageBuffer;
82 flatbuffers::FlatBufferBuilder fbb;
83 QVector<QSharedPointer<QueuedCommand>> commandQueue; 86 QVector<QSharedPointer<QueuedCommand>> commandQueue;
84 QMap<uint, QSharedPointer<QueuedCommand>> pendingCommands; 87 QMap<uint, QSharedPointer<QueuedCommand>> pendingCommands;
85 QMultiMap<uint, std::function<void(int error, const QString &errorMessage)> > resultHandler; 88 QMultiMap<uint, std::function<void(int error, const QString &errorMessage)> > resultHandler;
@@ -276,10 +279,50 @@ KAsync::Job<void> ResourceAccess::sendCommand(int commandId, flatbuffers::FlatB
276 279
277KAsync::Job<void> ResourceAccess::synchronizeResource(bool sourceSync, bool localSync) 280KAsync::Job<void> ResourceAccess::synchronizeResource(bool sourceSync, bool localSync)
278{ 281{
279 auto command = Akonadi2::CreateSynchronize(d->fbb, sourceSync, localSync); 282 flatbuffers::FlatBufferBuilder fbb;
280 Akonadi2::FinishSynchronizeBuffer(d->fbb, command); 283 auto command = Akonadi2::CreateSynchronize(fbb, sourceSync, localSync);
281 return sendCommand(Commands::SynchronizeCommand, d->fbb); 284 Akonadi2::FinishSynchronizeBuffer(fbb, command);
282 d->fbb.Clear(); 285 open();
286 return sendCommand(Commands::SynchronizeCommand, fbb);
287}
288
289KAsync::Job<void> ResourceAccess::sendCreateCommand(const QByteArray &resourceBufferType, const QByteArray &buffer)
290{
291 flatbuffers::FlatBufferBuilder fbb;
292 //This is the resource buffer type and not the domain type
293 auto type = fbb.CreateString(resourceBufferType.constData());
294 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
295 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta);
296 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
297 open();
298 return sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb);
299}
300
301KAsync::Job<void> ResourceAccess::sendModifyCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType, const QByteArrayList &deletedProperties, const QByteArray &buffer)
302{
303 flatbuffers::FlatBufferBuilder fbb;
304 auto entityId = fbb.CreateString(uid.constData());
305 //This is the resource buffer type and not the domain type
306 auto type = fbb.CreateString(resourceBufferType.constData());
307 //FIXME
308 auto deletions = 0;
309 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
310 auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta);
311 Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location);
312 open();
313 return sendCommand(Akonadi2::Commands::ModifyEntityCommand, fbb);
314}
315
316KAsync::Job<void> ResourceAccess::sendDeleteCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType)
317{
318 flatbuffers::FlatBufferBuilder fbb;
319 auto entityId = fbb.CreateString(uid.constData());
320 //This is the resource buffer type and not the domain type
321 auto type = fbb.CreateString(resourceBufferType.constData());
322 auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type);
323 Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location);
324 open();
325 return sendCommand(Akonadi2::Commands::DeleteEntityCommand, fbb);
283} 326}
284 327
285void ResourceAccess::open() 328void ResourceAccess::open()
@@ -346,11 +389,11 @@ void ResourceAccess::connected()
346 log(QString("Connected: %1").arg(d->socket->fullServerName())); 389 log(QString("Connected: %1").arg(d->socket->fullServerName()));
347 390
348 { 391 {
349 auto name = d->fbb.CreateString(QString::number(QCoreApplication::applicationPid()).toLatin1()); 392 flatbuffers::FlatBufferBuilder fbb;
350 auto command = Akonadi2::CreateHandshake(d->fbb, name); 393 auto name = fbb.CreateString(QString::number(QCoreApplication::applicationPid()).toLatin1());
351 Akonadi2::FinishHandshakeBuffer(d->fbb, command); 394 auto command = Akonadi2::CreateHandshake(fbb, name);
352 Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, d->fbb); 395 Akonadi2::FinishHandshakeBuffer(fbb, command);
353 d->fbb.Clear(); 396 Commands::write(d->socket.data(), ++d->messageId, Commands::HandshakeCommand, fbb);
354 } 397 }
355 398
356 processCommandQueue(); 399 processCommandQueue();