summaryrefslogtreecommitdiffstats
path: root/common/messagequeue.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-15 23:03:27 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-15 23:03:27 +0100
commite8b2898efcd2225adc7b14329cc246d9b29f1fa6 (patch)
treea8521217f55e7464a7b170a0f3cb58f3aa00fdd2 /common/messagequeue.cpp
parent8ba8ff25c86a73045ab86238fdefc9486fa3738b (diff)
downloadsink-e8b2898efcd2225adc7b14329cc246d9b29f1fa6.tar.gz
sink-e8b2898efcd2225adc7b14329cc246d9b29f1fa6.zip
Fixed messageqeue and storage. Empty scan is not an error.
Diffstat (limited to 'common/messagequeue.cpp')
-rw-r--r--common/messagequeue.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp
index e1bde4b..99a0112 100644
--- a/common/messagequeue.cpp
+++ b/common/messagequeue.cpp
@@ -21,8 +21,13 @@ void MessageQueue::enqueue(void const *msg, size_t size)
21void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> &resultHandler, 21void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> &resultHandler,
22 const std::function<void(const Error &error)> &errorHandler) 22 const std::function<void(const Error &error)> &errorHandler)
23{ 23{
24 mStorage.scan("", 0, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { 24 bool readValue = false;
25 const std::string key(static_cast<char*>(keyPtr), keySize); 25 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 if (key.startsWith("__internal")) {
28 return true;
29 }
30 readValue = true;
26 resultHandler(valuePtr, valueSize, [this, key](bool success) { 31 resultHandler(valuePtr, valueSize, [this, key](bool success) {
27 if (success) { 32 if (success) {
28 mStorage.remove(key.data(), key.size()); 33 mStorage.remove(key.data(), key.size());
@@ -37,16 +42,21 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu
37 errorHandler(Error(error.store, error.code, error.message)); 42 errorHandler(Error(error.store, error.code, error.message));
38 } 43 }
39 ); 44 );
45 if (!readValue) {
46 errorHandler(Error("messagequeue", -1, "No message found"));
47 }
40} 48}
41 49
42bool MessageQueue::isEmpty() 50bool MessageQueue::isEmpty()
43{ 51{
44 int count = 0; 52 int count = 0;
45 mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { 53 mStorage.scan("", [&count](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool {
46 const QByteArray key(static_cast<char*>(keyPtr), keySize); 54 const auto key = QByteArray::fromRawData(static_cast<char*>(keyPtr), keySize);
47 if (!key.startsWith("__internal")) { 55 if (!key.startsWith("__internal")) {
48 count++; 56 count++;
57 return false;
49 } 58 }
59 return true;
50 }); 60 });
51 return count == 0; 61 return count == 0;
52} 62}