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/db/Pmc.h"
|
|
|
|
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
|
|
|
ConfigShared(BinlogPmcPtr config_pmc, unique_ptr<Callback> callback);
|
|
|
|
|
|
|
|
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:
|
|
|
|
BinlogPmcPtr config_pmc_;
|
|
|
|
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
|