diff options
Diffstat (limited to 'common/genericresource.cpp')
-rw-r--r-- | common/genericresource.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
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 @@ | |||
6 | #include "createentity_generated.h" | 6 | #include "createentity_generated.h" |
7 | #include "modifyentity_generated.h" | 7 | #include "modifyentity_generated.h" |
8 | #include "deleteentity_generated.h" | 8 | #include "deleteentity_generated.h" |
9 | #include "inspection_generated.h" | ||
9 | #include "domainadaptor.h" | 10 | #include "domainadaptor.h" |
10 | #include "commands.h" | 11 | #include "commands.h" |
11 | #include "index.h" | 12 | #include "index.h" |
@@ -13,6 +14,7 @@ | |||
13 | #include "definitions.h" | 14 | #include "definitions.h" |
14 | 15 | ||
15 | #include <QUuid> | 16 | #include <QUuid> |
17 | #include <QDataStream> | ||
16 | 18 | ||
17 | static int sBatchSize = 100; | 19 | static int sBatchSize = 100; |
18 | 20 | ||
@@ -112,6 +114,7 @@ private: | |||
112 | class CommandProcessor : public QObject | 114 | class CommandProcessor : public QObject |
113 | { | 115 | { |
114 | Q_OBJECT | 116 | Q_OBJECT |
117 | typedef std::function<KAsync::Job<void>(void const *, size_t)> InspectionFunction; | ||
115 | public: | 118 | public: |
116 | CommandProcessor(Akonadi2::Pipeline *pipeline, QList<MessageQueue*> commandQueues) | 119 | CommandProcessor(Akonadi2::Pipeline *pipeline, QList<MessageQueue*> commandQueues) |
117 | : QObject(), | 120 | : QObject(), |
@@ -135,6 +138,11 @@ public: | |||
135 | mLowerBoundRevision = revision; | 138 | mLowerBoundRevision = revision; |
136 | } | 139 | } |
137 | 140 | ||
141 | void setInspectionCommand(const InspectionFunction &f) | ||
142 | { | ||
143 | mInspect = f; | ||
144 | } | ||
145 | |||
138 | 146 | ||
139 | signals: | 147 | signals: |
140 | void error(int errorCode, const QString &errorMessage); | 148 | void error(int errorCode, const QString &errorMessage); |
@@ -176,6 +184,14 @@ private slots: | |||
176 | return mPipeline->modifiedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); | 184 | return mPipeline->modifiedEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); |
177 | case Akonadi2::Commands::CreateEntityCommand: | 185 | case Akonadi2::Commands::CreateEntityCommand: |
178 | return mPipeline->newEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); | 186 | return mPipeline->newEntity(queuedCommand->command()->Data(), queuedCommand->command()->size()); |
187 | case Akonadi2::Commands::InspectionCommand: | ||
188 | if (mInspect) { | ||
189 | return mInspect(queuedCommand->command()->Data(), queuedCommand->command()->size()).then<qint64>([]() { | ||
190 | return -1; | ||
191 | }); | ||
192 | } else { | ||
193 | return KAsync::error<qint64>(-1, "Missing inspection command."); | ||
194 | } | ||
179 | default: | 195 | default: |
180 | return KAsync::error<qint64>(-1, "Unhandled command"); | 196 | return KAsync::error<qint64>(-1, "Unhandled command"); |
181 | } | 197 | } |
@@ -266,6 +282,7 @@ private: | |||
266 | bool mProcessingLock; | 282 | bool mProcessingLock; |
267 | //The lowest revision we no longer need | 283 | //The lowest revision we no longer need |
268 | qint64 mLowerBoundRevision; | 284 | qint64 mLowerBoundRevision; |
285 | InspectionFunction mInspect; | ||
269 | }; | 286 | }; |
270 | 287 | ||
271 | 288 | ||
@@ -279,6 +296,22 @@ GenericResource::GenericResource(const QByteArray &resourceInstanceIdentifier, c | |||
279 | mClientLowerBoundRevision(std::numeric_limits<qint64>::max()) | 296 | mClientLowerBoundRevision(std::numeric_limits<qint64>::max()) |
280 | { | 297 | { |
281 | mProcessor = new CommandProcessor(mPipeline.data(), QList<MessageQueue*>() << &mUserQueue << &mSynchronizerQueue); | 298 | mProcessor = new CommandProcessor(mPipeline.data(), QList<MessageQueue*>() << &mUserQueue << &mSynchronizerQueue); |
299 | mProcessor->setInspectionCommand([this](void const *command, size_t size) { | ||
300 | flatbuffers::Verifier verifier((const uint8_t *)command, size); | ||
301 | if (Akonadi2::Commands::VerifyInspectionBuffer(verifier)) { | ||
302 | auto buffer = Akonadi2::Commands::GetInspection(command); | ||
303 | int inspectionType = buffer->type(); | ||
304 | QByteArray entityId = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->entityId()->Data()), buffer->entityId()->size()); | ||
305 | QByteArray domainType = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->domainType()->Data()), buffer->domainType()->size()); | ||
306 | QByteArray property = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->property()->Data()), buffer->property()->size()); | ||
307 | QByteArray expectedValueString = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer->expectedValue()->Data()), buffer->expectedValue()->size()); | ||
308 | QDataStream s(expectedValueString); | ||
309 | QVariant expectedValue; | ||
310 | s >> expectedValue; | ||
311 | return inspect(inspectionType, domainType, entityId, property, expectedValue); | ||
312 | } | ||
313 | return KAsync::error<void>(-1, "Invalid inspection command."); | ||
314 | }); | ||
282 | QObject::connect(mProcessor, &CommandProcessor::error, [this](int errorCode, const QString &msg) { onProcessorError(errorCode, msg); }); | 315 | QObject::connect(mProcessor, &CommandProcessor::error, [this](int errorCode, const QString &msg) { onProcessorError(errorCode, msg); }); |
283 | QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); | 316 | QObject::connect(mPipeline.data(), &Pipeline::revisionUpdated, this, &Resource::revisionUpdated); |
284 | mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { | 317 | mSourceChangeReplay = new ChangeReplay(resourceInstanceIdentifier, [this](const QByteArray &type, const QByteArray &key, const QByteArray &value) { |
@@ -301,6 +334,12 @@ GenericResource::~GenericResource() | |||
301 | delete mSourceChangeReplay; | 334 | delete mSourceChangeReplay; |
302 | } | 335 | } |
303 | 336 | ||
337 | KAsync::Job<void> GenericResource::inspect(int inspectionType, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
338 | { | ||
339 | Warning() << "Inspection not implemented"; | ||
340 | return KAsync::null<void>(); | ||
341 | } | ||
342 | |||
304 | void GenericResource::enableChangeReplay(bool enable) | 343 | void GenericResource::enableChangeReplay(bool enable) |
305 | { | 344 | { |
306 | if (enable) { | 345 | if (enable) { |