diff options
-rw-r--r-- | common/messagequeue.cpp | 10 | ||||
-rw-r--r-- | common/messagequeue.h | 8 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 6 |
3 files changed, 19 insertions, 5 deletions
diff --git a/common/messagequeue.cpp b/common/messagequeue.cpp index cf63e57..e1bde4b 100644 --- a/common/messagequeue.cpp +++ b/common/messagequeue.cpp | |||
@@ -15,12 +15,13 @@ void MessageQueue::enqueue(void const *msg, size_t size) | |||
15 | mStorage.write(key.data(), key.size(), msg, size); | 15 | mStorage.write(key.data(), key.size(), msg, size); |
16 | mStorage.setMaxRevision(revision); | 16 | mStorage.setMaxRevision(revision); |
17 | mStorage.commitTransaction(); | 17 | mStorage.commitTransaction(); |
18 | emit messageReady(); | ||
18 | } | 19 | } |
19 | 20 | ||
20 | void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> &resultHandler, | 21 | void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> &resultHandler, |
21 | const std::function<void(const Error &error)> &errorHandler) | 22 | const std::function<void(const Error &error)> &errorHandler) |
22 | { | 23 | { |
23 | mStorage.scan("", [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { | 24 | mStorage.scan("", 0, [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool { |
24 | const std::string key(static_cast<char*>(keyPtr), keySize); | 25 | const std::string key(static_cast<char*>(keyPtr), keySize); |
25 | resultHandler(valuePtr, valueSize, [this, key](bool success) { | 26 | resultHandler(valuePtr, valueSize, [this, key](bool success) { |
26 | if (success) { | 27 | if (success) { |
@@ -30,7 +31,12 @@ void MessageQueue::dequeue(const std::function<void(void *ptr, int size, std::fu | |||
30 | } | 31 | } |
31 | }); | 32 | }); |
32 | return false; | 33 | return false; |
33 | }); | 34 | }, |
35 | [errorHandler](const Akonadi2::Storage::Error &error) { | ||
36 | qDebug() << "Error while retrieving value" << QString::fromStdString(error.message); | ||
37 | errorHandler(Error(error.store, error.code, error.message)); | ||
38 | } | ||
39 | ); | ||
34 | } | 40 | } |
35 | 41 | ||
36 | bool MessageQueue::isEmpty() | 42 | bool MessageQueue::isEmpty() |
diff --git a/common/messagequeue.h b/common/messagequeue.h index b56b3cd..8783421 100644 --- a/common/messagequeue.h +++ b/common/messagequeue.h | |||
@@ -1,5 +1,6 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <QObject> | ||
3 | #include <string> | 4 | #include <string> |
4 | #include <functional> | 5 | #include <functional> |
5 | #include <QString> | 6 | #include <QString> |
@@ -8,7 +9,9 @@ | |||
8 | /** | 9 | /** |
9 | * A persistent FIFO message queue. | 10 | * A persistent FIFO message queue. |
10 | */ | 11 | */ |
11 | class MessageQueue { | 12 | class MessageQueue : public QObject |
13 | { | ||
14 | Q_OBJECT | ||
12 | public: | 15 | public: |
13 | class Error | 16 | class Error |
14 | { | 17 | { |
@@ -29,6 +32,9 @@ public: | |||
29 | void dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> & resultHandler, | 32 | void dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> & resultHandler, |
30 | const std::function<void(const Error &error)> &errorHandler); | 33 | const std::function<void(const Error &error)> &errorHandler); |
31 | bool isEmpty(); | 34 | bool isEmpty(); |
35 | signals: | ||
36 | void messageReady(); | ||
37 | |||
32 | private: | 38 | private: |
33 | Akonadi2::Storage mStorage; | 39 | Akonadi2::Storage mStorage; |
34 | }; | 40 | }; |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index f0a5bc0..ae2be23 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -308,17 +308,19 @@ void Storage::scan(const char *keyData, uint keySize, | |||
308 | } | 308 | } |
309 | 309 | ||
310 | if (!keyData || keySize == 0) { | 310 | if (!keyData || keySize == 0) { |
311 | bool gotResult = false; | ||
311 | if ((rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST)) == 0 && | 312 | if ((rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST)) == 0 && |
312 | resultHandler(key.mv_data, key.mv_size, data.mv_data, data.mv_size)) { | 313 | resultHandler(key.mv_data, key.mv_size, data.mv_data, data.mv_size)) { |
313 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { | 314 | while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { |
315 | gotResult = true; | ||
314 | if (!resultHandler(key.mv_data, key.mv_size, data.mv_data, data.mv_size)) { | 316 | if (!resultHandler(key.mv_data, key.mv_size, data.mv_data, data.mv_size)) { |
315 | break; | 317 | break; |
316 | } | 318 | } |
317 | } | 319 | } |
318 | } | 320 | } |
319 | 321 | ||
320 | //We never find the last value | 322 | //We never find the last value, but ensure we got at least one. |
321 | if (rc == MDB_NOTFOUND) { | 323 | if (gotResult && rc == MDB_NOTFOUND) { |
322 | rc = 0; | 324 | rc = 0; |
323 | } | 325 | } |
324 | } else { | 326 | } else { |