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 ++++++++++++++++++++++ dummyresource/facade.cpp | 2 +- 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 @@ #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 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 storage, c storage->scan(key.data(), key.size(), [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { //Skip internals - if (QByteArray::fromRawData(static_cast(keyValue), keySize).startsWith("__internal")) { + if (Akonadi2::Storage::isInternalKey(keyValue, keySize)) { return true; } 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: mProcessingLock(false) { for (auto queue : mCommandQueues) { - bool ret = connect(queue, &MessageQueue::messageReady, this, &Processor::process); + const bool ret = connect(queue, &MessageQueue::messageReady, this, &Processor::process); Q_UNUSED(ret); - Q_ASSERT(ret); } } @@ -298,7 +297,7 @@ void findByRemoteId(QSharedPointer storage, const QString &ri //TODO lookup in rid index instead of doing a full scan const std::string ridString = rid.toStdString(); storage->scan("", [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { - if (QByteArray::fromRawData(static_cast(keyValue), keySize).startsWith("__internal")) { + if (Akonadi2::Storage::isInternalKey(keyValue, keySize)) { return true; } -- cgit v1.2.3