diff options
-rw-r--r-- | common/messagequeue.cpp | 5 | ||||
-rw-r--r-- | common/resourceaccess.cpp | 2 | ||||
-rw-r--r-- | common/storage.h | 5 | ||||
-rw-r--r-- | common/storage_common.cpp | 22 | ||||
-rw-r--r-- | dummyresource/facade.cpp | 2 | ||||
-rw-r--r-- | dummyresource/resourcefactory.cpp | 5 |
6 files changed, 34 insertions, 7 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index 3754b16..76f8162 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "messagequeue.h" | 1 | #include "messagequeue.h" |
2 | #include "storage.h" | ||
2 | #include <QDebug> | 3 | #include <QDebug> |
3 | 4 | ||
4 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) | 5 | MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) |
@@ -24,7 +25,7 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
24 | bool readValue = false; | 25 | bool readValue = false; |
25 | mStorage.scan("", 0, [this, resultHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 26 | mStorage.scan("", 0, [this, resultHandler, &readValue](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
26 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); | 27 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); |
27 | if (key.startsWith("__internal")) { | 28 | if (Akonadi2::Storage::isInternalKey(key)) { |
28 | return true; | 29 | return true; |
29 | } | 30 | } |
30 | readValue = true; | 31 | readValue = true; |
@@ -55,7 +56,7 @@ bool MessageQueue::isEmpty() | |||
55 | int count = 0; | 56 | int count = 0; |
56 | mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 57 | mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
57 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); | 58 | const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize); |
58 | if (!key.startsWith("__internal")) { | 59 | if (!Akonadi2::Storage::isInternalKey(key)) { |
59 | count++; | 60 | count++; |
60 | return false; | 61 | return false; |
61 | } | 62 | } |
diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index b874679..fc63e7c 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp | |||
@@ -319,7 +319,7 @@ bool ResourceAccess::processMessageBuffer() | |||
319 | return false; | 319 | return false; |
320 | } | 320 | } |
321 | 321 | ||
322 | const uint messageId = *(int*)(d->partialMessageBuffer.constData()); | 322 | //const uint messageId = *(int*)(d->partialMessageBuffer.constData()); |
323 | const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); | 323 | const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); |
324 | const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); | 324 | const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); |
325 | 325 | ||
diff --git a/common/storage.h b/common/storage.h index 758765e..d8378e2 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -79,6 +79,11 @@ public: | |||
79 | void setMaxRevision(qint64 revision); | 79 | void setMaxRevision(qint64 revision); |
80 | 80 | ||
81 | bool exists() const; | 81 | bool exists() const; |
82 | |||
83 | static bool isInternalKey(const char *key); | ||
84 | static bool isInternalKey(void *key, int keySize); | ||
85 | static bool isInternalKey(const QByteArray &key); | ||
86 | |||
82 | private: | 87 | private: |
83 | class Private; | 88 | class Private; |
84 | Private * const d; | 89 | Private * const d; |
diff --git a/common/storage_common.cpp b/common/storage_common.cpp index bdae9dd..ff2a2cd 100644 --- a/common/storage_common.cpp +++ b/common/storage_common.cpp | |||
@@ -25,6 +25,9 @@ | |||
25 | namespace Akonadi2 | 25 | namespace Akonadi2 |
26 | { | 26 | { |
27 | 27 | ||
28 | static const char *s_internalPrefix = "__internal"; | ||
29 | static const int s_internalPrefixSize = strlen(s_internalPrefix); | ||
30 | |||
28 | void errorHandler(const Storage::Error &error) | 31 | void errorHandler(const Storage::Error &error) |
29 | { | 32 | { |
30 | //TODO: allow this to be turned on / off globally | 33 | //TODO: allow this to be turned on / off globally |
@@ -71,4 +74,23 @@ qint64 Storage::maxRevision() | |||
71 | return r; | 74 | return r; |
72 | } | 75 | } |
73 | 76 | ||
77 | bool Storage::isInternalKey(const char *key) | ||
78 | { | ||
79 | return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; | ||
80 | } | ||
81 | |||
82 | bool Storage::isInternalKey(void *key, int size) | ||
83 | { | ||
84 | if (size < 1) { | ||
85 | return false; | ||
86 | } | ||
87 | |||
88 | return key && strncmp(static_cast<char *>(key), s_internalPrefix, (size > s_internalPrefixSize ? s_internalPrefixSize : size)) == 0; | ||
89 | } | ||
90 | |||
91 | bool Storage::isInternalKey(const QByteArray &key) | ||
92 | { | ||
93 | return key.startsWith(s_internalPrefix); | ||
94 | } | ||
95 | |||
74 | } // namespace Akonadi2 | 96 | } // namespace Akonadi2 |
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 79763ef..e0d27dc 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp | |||
@@ -138,7 +138,7 @@ void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, c | |||
138 | storage->scan(key.data(), key.size(), [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { | 138 | storage->scan(key.data(), key.size(), [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { |
139 | 139 | ||
140 | //Skip internals | 140 | //Skip internals |
141 | if (QByteArray::fromRawData(static_cast<char*>(keyValue), keySize).startsWith("__internal")) { | 141 | if (Akonadi2::Storage::isInternalKey(keyValue, keySize)) { |
142 | return true; | 142 | return true; |
143 | } | 143 | } |
144 | 144 | ||
diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index aefd66f..e5019f2 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp | |||
@@ -113,9 +113,8 @@ public: | |||
113 | mProcessingLock(false) | 113 | mProcessingLock(false) |
114 | { | 114 | { |
115 | for (auto queue : mCommandQueues) { | 115 | for (auto queue : mCommandQueues) { |
116 | bool ret = connect(queue, &MessageQueue::messageReady, this, &Processor::process); | 116 | const bool ret = connect(queue, &MessageQueue::messageReady, this, &Processor::process); |
117 | Q_UNUSED(ret); | 117 | Q_UNUSED(ret); |
118 | Q_ASSERT(ret); | ||
119 | } | 118 | } |
120 | } | 119 | } |
121 | 120 | ||
@@ -298,7 +297,7 @@ void findByRemoteId(QSharedPointer<Akonadi2::Storage> storage, const QString &ri | |||
298 | //TODO lookup in rid index instead of doing a full scan | 297 | //TODO lookup in rid index instead of doing a full scan |
299 | const std::string ridString = rid.toStdString(); | 298 | const std::string ridString = rid.toStdString(); |
300 | storage->scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { | 299 | storage->scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { |
301 | if (QByteArray::fromRawData(static_cast<char*>(keyValue), keySize).startsWith("__internal")) { | 300 | if (Akonadi2::Storage::isInternalKey(keyValue, keySize)) { |
302 | return true; | 301 | return true; |
303 | } | 302 | } |
304 | 303 | ||