summaryrefslogtreecommitdiffstats
path: root/common/messagequeue.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-11 16:10:01 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-11 16:10:01 +0100
commit091412c472b10ca61ada445c19bf3c95cd4e8e40 (patch)
treeae66dfc69e3c82f6cf42fd98b3cd94f23ad7aa4f /common/messagequeue.h
parenta4aeea4322252725165cb62390e880f2861035a6 (diff)
downloadsink-091412c472b10ca61ada445c19bf3c95cd4e8e40.tar.gz
sink-091412c472b10ca61ada445c19bf3c95cd4e8e40.zip
A messagequeue.
Diffstat (limited to 'common/messagequeue.h')
-rw-r--r--common/messagequeue.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/common/messagequeue.h b/common/messagequeue.h
new file mode 100644
index 0000000..b56b3cd
--- /dev/null
+++ b/common/messagequeue.h
@@ -0,0 +1,34 @@
1#pragma once
2
3#include <string>
4#include <functional>
5#include <QString>
6#include "storage.h"
7
8/**
9 * A persistent FIFO message queue.
10 */
11class MessageQueue {
12public:
13 class Error
14 {
15 public:
16 Error(const std::string &s, int c, const std::string &m)
17 : store(s), message(m), code(c) {}
18 std::string store;
19 std::string message;
20 int code;
21 };
22
23 MessageQueue(const QString &storageRoot, const QString &name);
24
25 void enqueue(void const *msg, size_t size);
26 //Dequeue a message. This will return a new message everytime called.
27 //Call the result handler with a success response to remove the message from the store.
28 //TODO track processing progress to avoid processing the same message with the same preprocessor twice?
29 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);
31 bool isEmpty();
32private:
33 Akonadi2::Storage mStorage;
34};