diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 19:33:01 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 19:33:01 +0100 |
commit | 938554f267193b652478fc12343819fa45d76034 (patch) | |
tree | 1c027f97f3209571740377f1d4b7e6721d8de777 /common/inspector.cpp | |
parent | 885f185f55249a2e97e9c7c238f89a5d0d99d1df (diff) | |
download | sink-938554f267193b652478fc12343819fa45d76034.tar.gz sink-938554f267193b652478fc12343819fa45d76034.zip |
Moved inspection commands to a separate inspector.
Diffstat (limited to 'common/inspector.cpp')
-rw-r--r-- | common/inspector.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/common/inspector.cpp b/common/inspector.cpp new file mode 100644 index 0000000..8b4c93a --- /dev/null +++ b/common/inspector.cpp | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #include "inspector.h" | ||
21 | |||
22 | #include "resourcecontext.h" | ||
23 | #include "inspection_generated.h" | ||
24 | #include "bufferutils.h" | ||
25 | |||
26 | #include <QDataStream> | ||
27 | |||
28 | using namespace Sink; | ||
29 | |||
30 | Inspector::Inspector(const ResourceContext &context) | ||
31 | : QObject(), | ||
32 | mResourceContext(context) | ||
33 | // mEntityStore(Storage::EntityStore::Ptr::create(mResourceContext)), | ||
34 | // mSyncStorage(Sink::storageLocation(), mResourceContext.instanceId() + ".synchronization", Sink::Storage::DataStore::DataStore::ReadWrite) | ||
35 | { | ||
36 | // SinkTrace() << "Starting synchronizer: " << mResourceContext.resourceType << mResourceContext.instanceId(); | ||
37 | } | ||
38 | |||
39 | Inspector::~Inspector() | ||
40 | { | ||
41 | |||
42 | } | ||
43 | |||
44 | KAsync::Job<void> Inspector::processCommand(void const *command, size_t size) | ||
45 | { | ||
46 | flatbuffers::Verifier verifier((const uint8_t *)command, size); | ||
47 | if (Sink::Commands::VerifyInspectionBuffer(verifier)) { | ||
48 | auto buffer = Sink::Commands::GetInspection(command); | ||
49 | int inspectionType = buffer->type(); | ||
50 | |||
51 | QByteArray inspectionId = BufferUtils::extractBuffer(buffer->id()); | ||
52 | QByteArray entityId = BufferUtils::extractBuffer(buffer->entityId()); | ||
53 | QByteArray domainType = BufferUtils::extractBuffer(buffer->domainType()); | ||
54 | QByteArray property = BufferUtils::extractBuffer(buffer->property()); | ||
55 | QByteArray expectedValueString = BufferUtils::extractBuffer(buffer->expectedValue()); | ||
56 | QDataStream s(expectedValueString); | ||
57 | QVariant expectedValue; | ||
58 | s >> expectedValue; | ||
59 | inspect(inspectionType, inspectionId, domainType, entityId, property, expectedValue) | ||
60 | .then<void>( | ||
61 | [=](const KAsync::Error &error) { | ||
62 | Sink::Notification n; | ||
63 | n.type = Sink::Notification::Inspection; | ||
64 | n.id = inspectionId; | ||
65 | if (error) { | ||
66 | Warning_area("resource.inspection") << "Inspection failed: " << inspectionType << inspectionId << entityId << error.errorMessage; | ||
67 | n.code = Sink::Notification::Failure; | ||
68 | } else { | ||
69 | Log_area("resource.inspection") << "Inspection was successful: " << inspectionType << inspectionId << entityId; | ||
70 | n.code = Sink::Notification::Success; | ||
71 | } | ||
72 | emit notify(n); | ||
73 | return KAsync::null(); | ||
74 | }) | ||
75 | .exec(); | ||
76 | return KAsync::null<void>(); | ||
77 | } | ||
78 | return KAsync::error<void>(-1, "Invalid inspection command."); | ||
79 | } | ||
80 | |||
81 | KAsync::Job<void> Inspector::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
82 | { | ||
83 | return KAsync::error(-1, "Inspection not implemented."); | ||
84 | } | ||
85 | |||