Make OptionManager a plain class.
This commit is contained in:
parent
04b98aa385
commit
bece21cc38
@ -167,8 +167,7 @@ void Global::update_server_time_difference(double diff) {
|
|||||||
server_time_difference_was_updated_ = true;
|
server_time_difference_was_updated_ = true;
|
||||||
do_save_server_time_difference();
|
do_save_server_time_difference();
|
||||||
|
|
||||||
CHECK(Scheduler::instance());
|
get_option_manager()->on_update_server_time_difference();
|
||||||
send_closure(option_manager(), &OptionManager::on_update_server_time_difference);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,13 +247,13 @@ void Global::set_net_query_dispatcher(unique_ptr<NetQueryDispatcher> net_query_d
|
|||||||
}
|
}
|
||||||
|
|
||||||
const OptionManager *Global::get_option_manager() const {
|
const OptionManager *Global::get_option_manager() const {
|
||||||
CHECK(!option_manager_.empty())
|
CHECK(option_manager_ != nullptr);
|
||||||
return option_manager_.get_actor_unsafe();
|
return option_manager_;
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionManager *Global::get_option_manager() {
|
OptionManager *Global::get_option_manager() {
|
||||||
CHECK(!option_manager_.empty())
|
CHECK(option_manager_ != nullptr);
|
||||||
return option_manager_.get_actor_unsafe();
|
return option_manager_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Global::set_option_empty(Slice name) {
|
void Global::set_option_empty(Slice name) {
|
||||||
|
@ -301,10 +301,7 @@ class Global final : public ActorContext {
|
|||||||
notification_settings_manager_ = notification_settings_manager;
|
notification_settings_manager_ = notification_settings_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
ActorId<OptionManager> option_manager() const {
|
void set_option_manager(OptionManager *option_manager) {
|
||||||
return option_manager_;
|
|
||||||
}
|
|
||||||
void set_option_manager(ActorId<OptionManager> option_manager) {
|
|
||||||
option_manager_ = option_manager;
|
option_manager_ = option_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -491,7 +488,6 @@ class Global final : public ActorContext {
|
|||||||
ActorId<MessagesManager> messages_manager_;
|
ActorId<MessagesManager> messages_manager_;
|
||||||
ActorId<NotificationManager> notification_manager_;
|
ActorId<NotificationManager> notification_manager_;
|
||||||
ActorId<NotificationSettingsManager> notification_settings_manager_;
|
ActorId<NotificationSettingsManager> notification_settings_manager_;
|
||||||
ActorId<OptionManager> option_manager_;
|
|
||||||
ActorId<PasswordManager> password_manager_;
|
ActorId<PasswordManager> password_manager_;
|
||||||
ActorId<SecretChatsManager> secret_chats_manager_;
|
ActorId<SecretChatsManager> secret_chats_manager_;
|
||||||
ActorId<SponsoredMessageManager> sponsored_message_manager_;
|
ActorId<SponsoredMessageManager> sponsored_message_manager_;
|
||||||
@ -506,6 +502,8 @@ class Global final : public ActorContext {
|
|||||||
|
|
||||||
unique_ptr<MtprotoHeader> mtproto_header_;
|
unique_ptr<MtprotoHeader> mtproto_header_;
|
||||||
|
|
||||||
|
OptionManager *option_manager_ = nullptr;
|
||||||
|
|
||||||
TdParameters parameters_;
|
TdParameters parameters_;
|
||||||
int32 gc_scheduler_id_ = 0;
|
int32 gc_scheduler_id_ = 0;
|
||||||
int32 slow_net_scheduler_id_ = 0;
|
int32 slow_net_scheduler_id_ = 0;
|
||||||
|
@ -46,11 +46,8 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
OptionManager::OptionManager(Td *td, ActorShared<> parent)
|
OptionManager::OptionManager(Td *td)
|
||||||
: td_(td)
|
: td_(td), options_(td::make_unique<TsSeqKeyValue>()), option_pmc_(G()->td_db()->get_config_pmc_shared()) {
|
||||||
, parent_(std::move(parent))
|
|
||||||
, options_(td::make_unique<TsSeqKeyValue>())
|
|
||||||
, option_pmc_(G()->td_db()->get_config_pmc_shared()) {
|
|
||||||
send_unix_time_update();
|
send_unix_time_update();
|
||||||
|
|
||||||
auto all_options = option_pmc_->get_all();
|
auto all_options = option_pmc_->get_all();
|
||||||
@ -106,10 +103,6 @@ OptionManager::OptionManager(Td *td, ActorShared<> parent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptionManager::tear_down() {
|
|
||||||
parent_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
OptionManager::~OptionManager() = default;
|
OptionManager::~OptionManager() = default;
|
||||||
|
|
||||||
void OptionManager::set_option_boolean(Slice name, bool value) {
|
void OptionManager::set_option_boolean(Slice name, bool value) {
|
||||||
@ -202,6 +195,7 @@ void OptionManager::send_unix_time_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OptionManager::on_update_server_time_difference() {
|
void OptionManager::on_update_server_time_difference() {
|
||||||
|
// can be called from any thread
|
||||||
if (std::abs(G()->get_server_time_difference() - last_sent_server_time_difference_) < 0.5) {
|
if (std::abs(G()->get_server_time_difference() - last_sent_server_time_difference_) < 0.5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,11 @@
|
|||||||
|
|
||||||
#include "td/telegram/td_api.h"
|
#include "td/telegram/td_api.h"
|
||||||
|
|
||||||
#include "td/actor/actor.h"
|
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/Promise.h"
|
#include "td/utils/Promise.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -22,15 +21,14 @@ class KeyValueSyncInterface;
|
|||||||
class Td;
|
class Td;
|
||||||
class TsSeqKeyValue;
|
class TsSeqKeyValue;
|
||||||
|
|
||||||
class OptionManager final : public Actor {
|
class OptionManager {
|
||||||
public:
|
public:
|
||||||
OptionManager(Td *td, ActorShared<> parent);
|
explicit OptionManager(Td *td);
|
||||||
|
|
||||||
OptionManager(const OptionManager &) = delete;
|
OptionManager(const OptionManager &) = delete;
|
||||||
OptionManager &operator=(const OptionManager &) = delete;
|
OptionManager &operator=(const OptionManager &) = delete;
|
||||||
OptionManager(OptionManager &&) = delete;
|
OptionManager(OptionManager &&) = delete;
|
||||||
OptionManager &operator=(OptionManager &&) = delete;
|
OptionManager &operator=(OptionManager &&) = delete;
|
||||||
~OptionManager() final;
|
~OptionManager();
|
||||||
|
|
||||||
void set_option_boolean(Slice name, bool value);
|
void set_option_boolean(Slice name, bool value);
|
||||||
|
|
||||||
@ -65,8 +63,6 @@ class OptionManager final : public Actor {
|
|||||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void tear_down() final;
|
|
||||||
|
|
||||||
void set_option(Slice name, Slice value);
|
void set_option(Slice name, Slice value);
|
||||||
|
|
||||||
void on_option_updated(Slice name);
|
void on_option_updated(Slice name);
|
||||||
@ -84,12 +80,11 @@ class OptionManager final : public Actor {
|
|||||||
void send_unix_time_update();
|
void send_unix_time_update();
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
|
||||||
|
|
||||||
unique_ptr<TsSeqKeyValue> options_;
|
unique_ptr<TsSeqKeyValue> options_;
|
||||||
std::shared_ptr<KeyValueSyncInterface> option_pmc_;
|
std::shared_ptr<KeyValueSyncInterface> option_pmc_;
|
||||||
|
|
||||||
double last_sent_server_time_difference_ = 1e100;
|
std::atomic<double> last_sent_server_time_difference_{1e100};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -3294,6 +3294,7 @@ void Td::dec_actor_refcnt() {
|
|||||||
web_pages_manager_.reset();
|
web_pages_manager_.reset();
|
||||||
LOG(DEBUG) << "WebPagesManager was cleared" << timer;
|
LOG(DEBUG) << "WebPagesManager was cleared" << timer;
|
||||||
|
|
||||||
|
G()->set_option_manager(nullptr);
|
||||||
option_manager_.reset();
|
option_manager_.reset();
|
||||||
LOG(DEBUG) << "OptionManager was cleared" << timer;
|
LOG(DEBUG) << "OptionManager was cleared" << timer;
|
||||||
|
|
||||||
@ -3465,8 +3466,6 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "NotificationManager actor was cleared" << timer;
|
LOG(DEBUG) << "NotificationManager actor was cleared" << timer;
|
||||||
notification_settings_manager_actor_.reset();
|
notification_settings_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "NotificationSettingsManager actor was cleared" << timer;
|
LOG(DEBUG) << "NotificationSettingsManager actor was cleared" << timer;
|
||||||
option_manager_actor_.reset();
|
|
||||||
LOG(DEBUG) << "OptionManager actor was cleared" << timer;
|
|
||||||
poll_manager_actor_.reset();
|
poll_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "PollManager actor was cleared" << timer;
|
LOG(DEBUG) << "PollManager actor was cleared" << timer;
|
||||||
sponsored_message_manager_actor_.reset();
|
sponsored_message_manager_actor_.reset();
|
||||||
@ -3812,9 +3811,8 @@ void Td::init_options_and_network() {
|
|||||||
G()->set_state_manager(state_manager_.get());
|
G()->set_state_manager(state_manager_.get());
|
||||||
|
|
||||||
VLOG(td_init) << "Create OptionManager";
|
VLOG(td_init) << "Create OptionManager";
|
||||||
option_manager_ = make_unique<OptionManager>(this, create_reference());
|
option_manager_ = make_unique<OptionManager>(this);
|
||||||
option_manager_actor_ = register_actor("OptionManager", option_manager_.get());
|
G()->set_option_manager(option_manager_.get());
|
||||||
G()->set_option_manager(option_manager_actor_.get());
|
|
||||||
|
|
||||||
init_connection_creator();
|
init_connection_creator();
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ class Td final : public Actor {
|
|||||||
unique_ptr<AudiosManager> audios_manager_;
|
unique_ptr<AudiosManager> audios_manager_;
|
||||||
unique_ptr<CallbackQueriesManager> callback_queries_manager_;
|
unique_ptr<CallbackQueriesManager> callback_queries_manager_;
|
||||||
unique_ptr<DocumentsManager> documents_manager_;
|
unique_ptr<DocumentsManager> documents_manager_;
|
||||||
|
unique_ptr<OptionManager> option_manager_;
|
||||||
unique_ptr<VideoNotesManager> video_notes_manager_;
|
unique_ptr<VideoNotesManager> video_notes_manager_;
|
||||||
unique_ptr<VideosManager> videos_manager_;
|
unique_ptr<VideosManager> videos_manager_;
|
||||||
|
|
||||||
@ -168,8 +169,6 @@ class Td final : public Actor {
|
|||||||
ActorOwn<NotificationManager> notification_manager_actor_;
|
ActorOwn<NotificationManager> notification_manager_actor_;
|
||||||
unique_ptr<NotificationSettingsManager> notification_settings_manager_;
|
unique_ptr<NotificationSettingsManager> notification_settings_manager_;
|
||||||
ActorOwn<NotificationSettingsManager> notification_settings_manager_actor_;
|
ActorOwn<NotificationSettingsManager> notification_settings_manager_actor_;
|
||||||
unique_ptr<OptionManager> option_manager_;
|
|
||||||
ActorOwn<OptionManager> option_manager_actor_;
|
|
||||||
unique_ptr<PollManager> poll_manager_;
|
unique_ptr<PollManager> poll_manager_;
|
||||||
ActorOwn<PollManager> poll_manager_actor_;
|
ActorOwn<PollManager> poll_manager_actor_;
|
||||||
unique_ptr<SponsoredMessageManager> sponsored_message_manager_;
|
unique_ptr<SponsoredMessageManager> sponsored_message_manager_;
|
||||||
|
Loading…
Reference in New Issue
Block a user