From d8cd2d6585507a4e40881092a633ec1a80b14dd9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 18 Jan 2016 15:17:30 +0100 Subject: Draft of inspection API --- common/genericresource.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'common/genericresource.cpp') diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 29acce4..90fc763 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -6,6 +6,7 @@ #include "createentity_generated.h" #include "modifyentity_generated.h" #include "deleteentity_generated.h" +#include "inspection_generated.h" #include "domainadaptor.h" #include "commands.h" #include "index.h" @@ -13,6 +14,7 @@ #include "definitions.h" #include +#include static int sBatchSize = 100; @@ -112,6 +114,7 @@ private: class CommandProcessor : public QObject { Q_OBJECT + typedef std::function(void const *, size_t)> InspectionFunction; public: CommandProcessor(Akonadi2::Pipeline *pipeline, QList commandQueues) : QObject(), @@ -135,6 +138,11 @@ public: mLowerBoundRevision = revision; } + void setInspectionCommand(const InspectionFunction &f) + { + mInspect = f; + } + signals: void error(int errorCode, const QString &errorMessage); @@ -176,6 +184,14 @@ private slots: return mPipeline->modifiedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); case Akonadi2::Commands::CreateEntityCommand: return mPipeline->newEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); + case Akonadi2::Commands::InspectionCommand: + if (mInspect) { + return mInspect(queuedCommand->command()->Data(), queuedCommand->command()->size()).then([]() { + return -1; + }); + } else { + return KAsync::error(-1, "Missing inspection command."); + } default: return KAsync::error(-1, "Unhandled command"); } @@ -266,6 +282,7 @@ private: bool mProcessingLock; //The lowest revision we no longer need qint64 mLowerBoundRevision; + InspectionFunction mInspect; }; @@ -279,6 +296,22 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c mClientLowerBoundRevision(std::numeric_limits::max()) { mProcessor = new CommandProcessor(mPipeline.data(), QList() << &mUserQueue << &mSynchronizerQueue); + mProcessor->setInspectionCommand([this](void const *command, size_t size) { + flatbuffers::Verifier verifier((const uint8_t *)command, size); + if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { + auto buffer = Akonadi2::Commands::GetInspection(command); + int inspectionType = buffer->type(); + QByteArray entityId = QByteArray::fromRawData(reinterpret_cast(buffer->entityId()->Data()), buffer->entityId()->size()); + QByteArray domainType = QByteArray::fromRawData(reinterpret_cast(buffer->domainType()->Data()), buffer->domainType()->size()); + QByteArray property = QByteArray::fromRawData(reinterpret_cast(buffer->property()->Data()), buffer->property()->size()); + QByteArray expectedValueString = QByteArray::fromRawData(reinterpret_cast(buffer->expectedValue()->Data()), buffer->expectedValue()->size()); + QDataStream s(expectedValueString); + QVariant expectedValue; + s >> expectedValue; + return inspect(inspectionType, domainType, entityId, property, expectedValue); + } + return KAsync::error(-1, "Invalid inspection command."); + }); QObject::connect(mProcessor, &CommandProcessor::error, [this](int errorCode, const QString &msg) { onProcessorError(errorCode, msg); }); QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { @@ -301,6 +334,12 @@ GenericResource::~GenericResource() delete mSourceChangeReplay; } +KAsync::Job GenericResource::inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) +{ + Warning() << "Inspection not implemented"; + return KAsync::null(); +} + void GenericResource::enableChangeReplay(bool enable) { if (enable) { -- cgit v1.2.3