From 142bf3d8bc6569a432e065e851f026a46e9595ed Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Tue, 27 Jan 2015 18:44:03 +0100 Subject: introduce a set of isInternalKey functions to hide this impl detail --- common/messagequeue.cpp | 5 +++-- common/resourceaccess.cpp | 2 +- common/storage.h | 5 +++++ common/storage_common.cpp | 22 ++++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'common') 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 @@ #include "messagequeue.h" +#include "storage.h" #include MessageQueue::MessageQueue(const QString &storageRoot, const QString &name) @@ -24,7 +25,7 @@ void MessageQueue::dequeue(const std::function bool { const auto key = QByteArray::fromRawData(static_cast(keyPtr), keySize); - if (key.startsWith("__internal")) { + if (Akonadi2::Storage::isInternalKey(key)) { return true; } readValue = true; @@ -55,7 +56,7 @@ bool MessageQueue::isEmpty() int count = 0; mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { const auto key = QByteArray::fromRawData(static_cast(keyPtr), keySize); - if (!key.startsWith("__internal")) { + if (!Akonadi2::Storage::isInternalKey(key)) { count++; return false; } 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() return false; } - const uint messageId = *(int*)(d->partialMessageBuffer.constData()); + //const uint messageId = *(int*)(d->partialMessageBuffer.constData()); const int commandId = *(int*)(d->partialMessageBuffer.constData() + sizeof(uint)); const uint size = *(int*)(d->partialMessageBuffer.constData() + sizeof(int) + sizeof(uint)); 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: void setMaxRevision(qint64 revision); bool exists() const; + + static bool isInternalKey(const char *key); + static bool isInternalKey(void *key, int keySize); + static bool isInternalKey(const QByteArray &key); + private: class Private; 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 @@ namespace Akonadi2 { +static const char *s_internalPrefix = "__internal"; +static const int s_internalPrefixSize = strlen(s_internalPrefix); + void errorHandler(const Storage::Error &error) { //TODO: allow this to be turned on / off globally @@ -71,4 +74,23 @@ qint64 Storage::maxRevision() return r; } +bool Storage::isInternalKey(const char *key) +{ + return key && strncmp(key, s_internalPrefix, s_internalPrefixSize) == 0; +} + +bool Storage::isInternalKey(void *key, int size) +{ + if (size < 1) { + return false; + } + + return key && strncmp(static_cast(key), s_internalPrefix, (size > s_internalPrefixSize ? s_internalPrefixSize : size)) == 0; +} + +bool Storage::isInternalKey(const QByteArray &key) +{ + return key.startsWith(s_internalPrefix); +} + } // namespace Akonadi2 -- cgit v1.2.3