summaryrefslogtreecommitdiffstats
path: root/common/index.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-21 10:52:02 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-21 10:52:02 +0100
commitb36ae2d0e0b0ee9865fdc7e628374853d160b55a (patch)
treede8328191a63b54f748648611a67c4e24be265a1 /common/index.cpp
parentcf91df49d0eadfdc7dec23fd82da9e7b9a964ea6 (diff)
downloadsink-b36ae2d0e0b0ee9865fdc7e628374853d160b55a.tar.gz
sink-b36ae2d0e0b0ee9865fdc7e628374853d160b55a.zip
An index implementation.
Diffstat (limited to 'common/index.cpp')
-rw-r--r--common/index.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/common/index.cpp b/common/index.cpp
new file mode 100644
index 0000000..7b0c682
--- /dev/null
+++ b/common/index.cpp
@@ -0,0 +1,30 @@
1#include "index.h"
2#include <QDebug>
3
4Index::Index(const QString &storageRoot, const QString &name, Akonadi2::Storage::AccessMode mode)
5 : mStorage(storageRoot, name, mode, true)
6{
7
8}
9
10void Index::add(const QByteArray &key, const QByteArray &value)
11{
12 mStorage.startTransaction(Akonadi2::Storage::ReadWrite);
13 mStorage.write(key.data(), key.size(), value.data(), value.size());
14 mStorage.commitTransaction();
15}
16
17void Index::lookup(const QByteArray &key, const std::function<void(const QByteArray &value)> &resultHandler,
18 const std::function<void(const Error &error)> &errorHandler)
19{
20 mStorage.scan(key.data(), key.size(), [this, resultHandler](void *keyPtr, int keySize, void *valuePtr, int valueSize) -> bool {
21 resultHandler(QByteArray(static_cast<char*>(valuePtr), valueSize));
22 return true;
23 },
24 [errorHandler](const Akonadi2::Storage::Error &error) {
25 qDebug() << "Error while retrieving value" << QString::fromStdString(error.message);
26 errorHandler(Error(error.store, error.code, error.message));
27 }
28 );
29}
30