2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-01-01 01:35:39 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2019-01-06 23:58:09 +01:00
|
|
|
#include "td/db/KeyValueSyncInterface.h"
|
2019-01-06 23:20:38 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
2019-01-06 23:20:38 +01:00
|
|
|
#include <memory>
|
2022-02-09 15:05:27 +01:00
|
|
|
#include <unordered_map>
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
2018-05-17 20:08:51 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class ConfigShared {
|
|
|
|
public:
|
|
|
|
class Callback {
|
|
|
|
public:
|
|
|
|
Callback() = default;
|
|
|
|
Callback(const Callback &) = delete;
|
|
|
|
Callback &operator=(const Callback &) = delete;
|
2019-01-17 21:12:31 +01:00
|
|
|
Callback(Callback &&) = delete;
|
|
|
|
Callback &operator=(Callback &&) = delete;
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual ~Callback() = default;
|
2018-09-27 18:51:45 +02:00
|
|
|
virtual void on_option_updated(const string &name, const string &value) const = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
|
|
|
|
2019-01-17 21:12:31 +01:00
|
|
|
explicit ConfigShared(std::shared_ptr<KeyValueSyncInterface> config_pmc);
|
|
|
|
|
|
|
|
void set_callback(unique_ptr<Callback> callback);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
void set_option_boolean(Slice name, bool value);
|
|
|
|
void set_option_empty(Slice name);
|
2020-09-24 23:46:16 +02:00
|
|
|
void set_option_integer(Slice name, int64 value);
|
2018-12-31 20:04:05 +01:00
|
|
|
void set_option_string(Slice name, Slice value);
|
|
|
|
|
2018-03-08 16:01:45 +01:00
|
|
|
bool have_option(Slice name) const;
|
2021-12-16 20:56:19 +01:00
|
|
|
|
|
|
|
string get_option(Slice name) const;
|
|
|
|
|
2022-02-09 15:05:27 +01:00
|
|
|
std::unordered_map<string, string> get_options() const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2018-05-03 12:18:07 +02:00
|
|
|
bool get_option_boolean(Slice name, bool default_value = false) const;
|
2020-09-24 23:46:16 +02:00
|
|
|
int64 get_option_integer(Slice name, int64 default_value = 0) const;
|
2018-05-17 20:08:51 +02:00
|
|
|
string get_option_string(Slice name, string default_value = "") const;
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-06 23:58:09 +01:00
|
|
|
std::shared_ptr<KeyValueSyncInterface> config_pmc_;
|
2018-12-31 20:04:05 +01:00
|
|
|
unique_ptr<Callback> callback_;
|
|
|
|
|
|
|
|
bool set_option(Slice name, Slice value);
|
|
|
|
|
2018-05-22 13:09:58 +02:00
|
|
|
void on_option_updated(Slice name) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2018-05-17 20:08:51 +02:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
} // namespace td
|