2018-12-31 20:04:05 +01:00
|
|
|
//
|
2018-12-31 23:02:34 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019
|
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
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
2019-01-06 23:20:38 +01:00
|
|
|
#include "td/db/binlog/ConcurrentBinlog.h"
|
|
|
|
#include "td/db/BinlogKeyValue.h"
|
|
|
|
|
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>
|
2018-12-31 20:04:05 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
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;
|
|
|
|
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-06 23:20:38 +01:00
|
|
|
ConfigShared(std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> config_pmc, 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);
|
|
|
|
void set_option_integer(Slice name, int32 value);
|
|
|
|
void set_option_string(Slice name, Slice value);
|
|
|
|
|
2018-03-08 16:01:45 +01:00
|
|
|
bool have_option(Slice name) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
string get_option(Slice name) const;
|
|
|
|
std::unordered_map<string, string> get_options(Slice prefix) const;
|
|
|
|
std::unordered_map<string, string> get_options() const;
|
|
|
|
|
2018-05-03 12:18:07 +02:00
|
|
|
bool get_option_boolean(Slice name, bool default_value = false) const;
|
2018-12-31 20:04:05 +01:00
|
|
|
int32 get_option_integer(Slice name, int32 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
|
|
|
|
2018-09-20 19:41:22 +02:00
|
|
|
tl_object_ptr<td_api::OptionValue> get_option_value(Slice name) const;
|
|
|
|
|
|
|
|
static tl_object_ptr<td_api::OptionValue> get_option_value_object(Slice value);
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-06 23:20:38 +01:00
|
|
|
std::shared_ptr<BinlogKeyValue<ConcurrentBinlog>> 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
|