diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-19 12:39:45 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-19 12:39:45 +0100 |
commit | d5b28efe4d7fc2a984243417d923ff5727234e94 (patch) | |
tree | 1546145760eb0fa2d8d606e3332e1bab92e63161 | |
parent | 4922555a38af32fc94e56aeb208b9fda31dab1b2 (diff) | |
download | sink-d5b28efe4d7fc2a984243417d923ff5727234e94.tar.gz sink-d5b28efe4d7fc2a984243417d923ff5727234e94.zip |
Added bufferutils.h
-rw-r--r-- | common/bufferutils.h | 26 | ||||
-rw-r--r-- | common/facade.cpp | 5 | ||||
-rw-r--r-- | common/genericresource.cpp | 18 | ||||
-rw-r--r-- | common/pipeline.cpp | 5 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 5 |
5 files changed, 45 insertions, 14 deletions
diff --git a/common/bufferutils.h b/common/bufferutils.h new file mode 100644 index 0000000..b0fb75a --- /dev/null +++ b/common/bufferutils.h | |||
@@ -0,0 +1,26 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <flatbuffers/flatbuffers.h> | ||
4 | #include <QByteArray> | ||
5 | |||
6 | namespace Akonadi2 { | ||
7 | namespace BufferUtils { | ||
8 | template<typename T> | ||
9 | static QByteArray extractBuffer(const T *data) | ||
10 | { | ||
11 | return QByteArray::fromRawData(reinterpret_cast<char const *>(data->Data()), data->size()); | ||
12 | } | ||
13 | |||
14 | template<typename T> | ||
15 | static QByteArray extractBufferCopy(const T *data) | ||
16 | { | ||
17 | return QByteArray(reinterpret_cast<char const *>(data->Data()), data->size()); | ||
18 | } | ||
19 | |||
20 | static QByteArray extractBuffer(const flatbuffers::FlatBufferBuilder &fbb) | ||
21 | { | ||
22 | return QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||
diff --git a/common/facade.cpp b/common/facade.cpp index 22ef84a..91021db 100644 --- a/common/facade.cpp +++ b/common/facade.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "definitions.h" | 25 | #include "definitions.h" |
26 | #include "domainadaptor.h" | 26 | #include "domainadaptor.h" |
27 | #include "queryrunner.h" | 27 | #include "queryrunner.h" |
28 | #include "bufferutils.h" | ||
28 | 29 | ||
29 | using namespace Akonadi2; | 30 | using namespace Akonadi2; |
30 | 31 | ||
@@ -113,7 +114,7 @@ KAsync::Job<void> GenericFacade<DomainType>::create(const DomainType &domainObje | |||
113 | } | 114 | } |
114 | flatbuffers::FlatBufferBuilder entityFbb; | 115 | flatbuffers::FlatBufferBuilder entityFbb; |
115 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | 116 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); |
116 | return mResourceAccess->sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | 117 | return mResourceAccess->sendCreateCommand(bufferTypeForDomainType(), BufferUtils::extractBuffer(entityFbb)); |
117 | } | 118 | } |
118 | 119 | ||
119 | template<class DomainType> | 120 | template<class DomainType> |
@@ -125,7 +126,7 @@ KAsync::Job<void> GenericFacade<DomainType>::modify(const DomainType &domainObje | |||
125 | } | 126 | } |
126 | flatbuffers::FlatBufferBuilder entityFbb; | 127 | flatbuffers::FlatBufferBuilder entityFbb; |
127 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | 128 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); |
128 | return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | 129 | return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), BufferUtils::extractBuffer(entityFbb)); |
129 | } | 130 | } |
130 | 131 | ||
131 | template<class DomainType> | 132 | template<class DomainType> |
diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 892c3db..40e3add 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "index.h" | 12 | #include "index.h" |
13 | #include "log.h" | 13 | #include "log.h" |
14 | #include "definitions.h" | 14 | #include "definitions.h" |
15 | #include "bufferutils.h" | ||
15 | 16 | ||
16 | #include <QUuid> | 17 | #include <QUuid> |
17 | #include <QDataStream> | 18 | #include <QDataStream> |
@@ -301,11 +302,12 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c | |||
301 | if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { | 302 | if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { |
302 | auto buffer = Akonadi2::Commands::GetInspection(command); | 303 | auto buffer = Akonadi2::Commands::GetInspection(command); |
303 | int inspectionType = buffer->type(); | 304 | int inspectionType = buffer->type(); |
304 | QByteArray inspectionId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->id()->Data()), buffer->id()->size()); | 305 | |
305 | QByteArray entityId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->entityId()->Data()), buffer->entityId()->size()); | 306 | QByteArray inspectionId = BufferUtils::extractBuffer(buffer->id()); |
306 | QByteArray domainType = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->domainType()->Data()), buffer->domainType()->size()); | 307 | QByteArray entityId = BufferUtils::extractBuffer(buffer->entityId()); |
307 | QByteArray property = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->property()->Data()), buffer->property()->size()); | 308 | QByteArray domainType = BufferUtils::extractBuffer(buffer->domainType()); |
308 | QByteArray expectedValueString = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->expectedValue()->Data()), buffer->expectedValue()->size()); | 309 | QByteArray property = BufferUtils::extractBuffer(buffer->property()); |
310 | QByteArray expectedValueString = BufferUtils::extractBuffer(buffer->expectedValue()); | ||
309 | QDataStream s(expectedValueString); | 311 | QDataStream s(expectedValueString); |
310 | QVariant expectedValue; | 312 | QVariant expectedValue; |
311 | s >> expectedValue; | 313 | s >> expectedValue; |
@@ -518,7 +520,7 @@ void GenericResource::createEntity(const QByteArray &akonadiId, const QByteArray | |||
518 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | 520 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); |
519 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); | 521 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, entityId, type, delta, replayToSource); |
520 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | 522 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); |
521 | callback(QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize())); | 523 | callback(BufferUtils::extractBuffer(fbb)); |
522 | } | 524 | } |
523 | 525 | ||
524 | void GenericResource::modifyEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback) | 526 | void GenericResource::modifyEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, DomainTypeAdaptorFactoryInterface &adaptorFactory, std::function<void(const QByteArray &)> callback) |
@@ -535,7 +537,7 @@ void GenericResource::modifyEntity(const QByteArray &akonadiId, qint64 revision, | |||
535 | //TODO removals | 537 | //TODO removals |
536 | auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); | 538 | auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, 0, type, delta, replayToSource); |
537 | Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); | 539 | Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); |
538 | callback(QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize())); | 540 | callback(BufferUtils::extractBuffer(fbb)); |
539 | } | 541 | } |
540 | 542 | ||
541 | void GenericResource::deleteEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, std::function<void(const QByteArray &)> callback) | 543 | void GenericResource::deleteEntity(const QByteArray &akonadiId, qint64 revision, const QByteArray &bufferType, std::function<void(const QByteArray &)> callback) |
@@ -548,7 +550,7 @@ void GenericResource::deleteEntity(const QByteArray &akonadiId, qint64 revision, | |||
548 | auto type = fbb.CreateString(bufferType.toStdString()); | 550 | auto type = fbb.CreateString(bufferType.toStdString()); |
549 | auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); | 551 | auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type, replayToSource); |
550 | Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); | 552 | Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); |
551 | callback(QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize())); | 553 | callback(BufferUtils::extractBuffer(fbb)); |
552 | } | 554 | } |
553 | 555 | ||
554 | void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) | 556 | void GenericResource::recordRemoteId(const QByteArray &bufferType, const QByteArray &localId, const QByteArray &remoteId, Akonadi2::Storage::Transaction &transaction) |
diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 06d8114..a087def 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "log.h" | 34 | #include "log.h" |
35 | #include "domain/applicationdomaintype.h" | 35 | #include "domain/applicationdomaintype.h" |
36 | #include "definitions.h" | 36 | #include "definitions.h" |
37 | #include "bufferutils.h" | ||
37 | 38 | ||
38 | namespace Akonadi2 | 39 | namespace Akonadi2 |
39 | { | 40 | { |
@@ -119,7 +120,7 @@ Storage &Pipeline::storage() const | |||
119 | 120 | ||
120 | void Pipeline::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid) | 121 | void Pipeline::storeNewRevision(qint64 newRevision, const flatbuffers::FlatBufferBuilder &fbb, const QByteArray &bufferType, const QByteArray &uid) |
121 | { | 122 | { |
122 | d->transaction.openDatabase(bufferType + ".main").write(Akonadi2::Storage::assembleKey(uid, newRevision), QByteArray::fromRawData(reinterpret_cast<char const *>(fbb.GetBufferPointer()), fbb.GetSize()), | 123 | d->transaction.openDatabase(bufferType + ".main").write(Akonadi2::Storage::assembleKey(uid, newRevision), BufferUtils::extractBuffer(fbb), |
123 | [](const Akonadi2::Storage::Error &error) { | 124 | [](const Akonadi2::Storage::Error &error) { |
124 | Warning() << "Failed to write entity"; | 125 | Warning() << "Failed to write entity"; |
125 | } | 126 | } |
@@ -285,7 +286,7 @@ KAsync::Job<qint64> Pipeline::modifiedEntity(void const *command, size_t size) | |||
285 | //Remove deletions | 286 | //Remove deletions |
286 | if (modifyEntity->deletions()) { | 287 | if (modifyEntity->deletions()) { |
287 | for (const auto &property : *modifyEntity->deletions()) { | 288 | for (const auto &property : *modifyEntity->deletions()) { |
288 | newObject->setProperty(QByteArray::fromRawData(property->data(), property->size()), QVariant()); | 289 | newObject->setProperty(BufferUtils::extractBuffer(property), QVariant()); |
289 | } | 290 | } |
290 | } | 291 | } |
291 | 292 | ||
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index d2aa969..6540e98 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -32,6 +32,7 @@ | |||
32 | #include "common/revisionreplayed_generated.h" | 32 | #include "common/revisionreplayed_generated.h" |
33 | #include "common/inspection_generated.h" | 33 | #include "common/inspection_generated.h" |
34 | #include "common/entitybuffer.h" | 34 | #include "common/entitybuffer.h" |
35 | #include "common/bufferutils.h" | ||
35 | #include "log.h" | 36 | #include "log.h" |
36 | 37 | ||
37 | #include <QCoreApplication> | 38 | #include <QCoreApplication> |
@@ -551,11 +552,11 @@ bool ResourceAccess::processMessageBuffer() | |||
551 | ResourceNotification n; | 552 | ResourceNotification n; |
552 | if (buffer->identifier()) { | 553 | if (buffer->identifier()) { |
553 | //Don't use fromRawData, the buffer is gone once we invoke emit notification | 554 | //Don't use fromRawData, the buffer is gone once we invoke emit notification |
554 | n.id = QByteArray(reinterpret_cast<char const *>(buffer->identifier()->Data()), buffer->identifier()->size()); | 555 | n.id = BufferUtils::extractBufferCopy(buffer->identifier()); |
555 | } | 556 | } |
556 | if (buffer->message()) { | 557 | if (buffer->message()) { |
557 | //Don't use fromRawData, the buffer is gone once we invoke emit notification | 558 | //Don't use fromRawData, the buffer is gone once we invoke emit notification |
558 | n.message = QByteArray(reinterpret_cast<char const *>(buffer->message()->Data()), buffer->message()->size()); | 559 | n.message = BufferUtils::extractBufferCopy(buffer->message()); |
559 | } | 560 | } |
560 | n.type = buffer->type(); | 561 | n.type = buffer->type(); |
561 | n.code = buffer->code(); | 562 | n.code = buffer->code(); |