summaryrefslogtreecommitdiffstats
path: root/common/messagequeue.h
blob: b56b3cd0dc6026b5995fc901cdbcf2875e8b8809 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#pragma once

#include <string>
#include <functional>
#include <QString>
#include "storage.h"

/**
 * A persistent FIFO message queue.
 */
class MessageQueue {
public:
    class Error
    {
    public:
        Error(const std::string &s, int c, const std::string &m)
            : store(s), message(m), code(c) {}
        std::string store;
        std::string message;
        int code;
    };

    MessageQueue(const QString &storageRoot, const QString &name);

    void enqueue(void const *msg, size_t size);
    //Dequeue a message. This will return a new message everytime called.
    //Call the result handler with a success response to remove the message from the store.
    //TODO track processing progress to avoid processing the same message with the same preprocessor twice?
    void dequeue(const std::function<void(void *ptr, int size, std::function<void(bool success)>)> & resultHandler,
              const std::function<void(const Error &error)> &errorHandler);
    bool isEmpty();
private:
    Akonadi2::Storage mStorage;
};