2018-07-26 23:36:28 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-30 23:34:23 +03:00
|
|
|
#include "storage/cache/storage_cache_types.h"
|
|
|
|
#include "base/basic_types.h"
|
2018-07-26 23:36:28 +03:00
|
|
|
#include <crl/crl_object_on_queue.h>
|
2018-08-18 21:45:12 +03:00
|
|
|
#include <crl/crl_time.h>
|
2018-08-29 16:23:16 +03:00
|
|
|
#include <rpl/producer.h>
|
2018-07-26 23:36:28 +03:00
|
|
|
#include <QtCore/QString>
|
|
|
|
|
|
|
|
namespace Storage {
|
|
|
|
class EncryptionKey;
|
|
|
|
namespace Cache {
|
|
|
|
namespace details {
|
2018-08-19 23:06:49 +03:00
|
|
|
class DatabaseObject;
|
2018-07-26 23:36:28 +03:00
|
|
|
} // namespace details
|
|
|
|
|
|
|
|
class Database {
|
|
|
|
public:
|
2018-08-21 21:53:04 +03:00
|
|
|
using Settings = details::Settings;
|
2018-08-31 14:37:22 +03:00
|
|
|
using SettingsUpdate = details::SettingsUpdate;
|
2018-07-29 00:08:29 +03:00
|
|
|
Database(const QString &path, const Settings &settings);
|
|
|
|
|
2018-08-29 16:23:16 +03:00
|
|
|
void reconfigure(const Settings &settings);
|
2018-08-31 14:37:22 +03:00
|
|
|
void updateSettings(const SettingsUpdate &update);
|
2018-08-29 16:23:16 +03:00
|
|
|
|
2018-08-28 23:49:16 +03:00
|
|
|
void open(EncryptionKey &&key, FnMut<void(Error)> &&done = nullptr);
|
|
|
|
void close(FnMut<void()> &&done = nullptr);
|
2018-07-29 00:08:29 +03:00
|
|
|
|
2018-08-27 10:15:25 +03:00
|
|
|
void put(
|
|
|
|
const Key &key,
|
2018-08-28 23:49:16 +03:00
|
|
|
QByteArray &&value,
|
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
|
|
|
void get(const Key &key, FnMut<void(QByteArray&&)> &&done);
|
|
|
|
void remove(const Key &key, FnMut<void(Error)> &&done = nullptr);
|
2018-08-27 10:15:25 +03:00
|
|
|
|
2018-08-27 14:35:58 +03:00
|
|
|
void putIfEmpty(
|
|
|
|
const Key &key,
|
2018-08-28 23:49:16 +03:00
|
|
|
QByteArray &&value,
|
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
2018-08-27 14:35:58 +03:00
|
|
|
void copyIfEmpty(
|
2018-08-27 10:15:25 +03:00
|
|
|
const Key &from,
|
|
|
|
const Key &to,
|
2018-08-28 23:49:16 +03:00
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
2018-08-27 14:35:58 +03:00
|
|
|
void moveIfEmpty(
|
2018-08-27 10:15:25 +03:00
|
|
|
const Key &from,
|
|
|
|
const Key &to,
|
2018-08-28 23:49:16 +03:00
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
2018-08-27 10:15:25 +03:00
|
|
|
|
2018-08-28 23:49:16 +03:00
|
|
|
using TaggedValue = details::TaggedValue;
|
|
|
|
void put(
|
|
|
|
const Key &key,
|
|
|
|
TaggedValue &&value,
|
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
|
|
|
void putIfEmpty(
|
|
|
|
const Key &key,
|
|
|
|
TaggedValue &&value,
|
|
|
|
FnMut<void(Error)> &&done = nullptr);
|
|
|
|
void getWithTag(const Key &key, FnMut<void(TaggedValue&&)> &&done);
|
|
|
|
|
|
|
|
using Stats = details::Stats;
|
2018-08-29 16:23:16 +03:00
|
|
|
using TaggedSummary = details::TaggedSummary;
|
|
|
|
rpl::producer<Stats> statsOnMain() const;
|
2018-08-28 23:49:16 +03:00
|
|
|
|
|
|
|
void clear(FnMut<void(Error)> &&done = nullptr);
|
2018-08-29 16:23:16 +03:00
|
|
|
void clearByTag(uint8 tag, FnMut<void(Error)> &&done = nullptr);
|
2018-08-29 22:17:06 +03:00
|
|
|
void waitForCleaner(FnMut<void()> &&done = nullptr);
|
2018-07-29 00:08:29 +03:00
|
|
|
|
2019-02-25 21:26:08 +04:00
|
|
|
void sync();
|
|
|
|
|
2018-07-29 00:08:29 +03:00
|
|
|
~Database();
|
2018-07-26 23:36:28 +03:00
|
|
|
|
|
|
|
private:
|
2018-08-19 23:06:49 +03:00
|
|
|
using Implementation = details::DatabaseObject;
|
2018-07-26 23:36:28 +03:00
|
|
|
crl::object_on_queue<Implementation> _wrapped;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Cache
|
|
|
|
} // namespace Storage
|