Make OptionManager a plain class.

This commit is contained in:
levlam 2022-08-18 18:52:59 +03:00
parent 04b98aa385
commit bece21cc38
6 changed files with 20 additions and 37 deletions

View File

@ -167,8 +167,7 @@ void Global::update_server_time_difference(double diff) {
server_time_difference_was_updated_ = true;
do_save_server_time_difference();
CHECK(Scheduler::instance());
send_closure(option_manager(), &OptionManager::on_update_server_time_difference);
get_option_manager()->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 {
CHECK(!option_manager_.empty())
return option_manager_.get_actor_unsafe();
CHECK(option_manager_ != nullptr);
return option_manager_;
}
OptionManager *Global::get_option_manager() {
CHECK(!option_manager_.empty())
return option_manager_.get_actor_unsafe();
CHECK(option_manager_ != nullptr);
return option_manager_;
}
void Global::set_option_empty(Slice name) {

View File

@ -301,10 +301,7 @@ class Global final : public ActorContext {
notification_settings_manager_ = notification_settings_manager;
}
ActorId<OptionManager> option_manager() const {
return option_manager_;
}
void set_option_manager(ActorId<OptionManager> option_manager) {
void set_option_manager(OptionManager *option_manager) {
option_manager_ = option_manager;
}
@ -491,7 +488,6 @@ class Global final : public ActorContext {
ActorId<MessagesManager> messages_manager_;
ActorId<NotificationManager> notification_manager_;
ActorId<NotificationSettingsManager> notification_settings_manager_;
ActorId<OptionManager> option_manager_;
ActorId<PasswordManager> password_manager_;
ActorId<SecretChatsManager> secret_chats_manager_;
ActorId<SponsoredMessageManager> sponsored_message_manager_;
@ -506,6 +502,8 @@ class Global final : public ActorContext {
unique_ptr<MtprotoHeader> mtproto_header_;
OptionManager *option_manager_ = nullptr;
TdParameters parameters_;
int32 gc_scheduler_id_ = 0;
int32 slow_net_scheduler_id_ = 0;

View File

@ -46,11 +46,8 @@
namespace td {
OptionManager::OptionManager(Td *td, ActorShared<> parent)
: td_(td)
, parent_(std::move(parent))
, options_(td::make_unique<TsSeqKeyValue>())
, option_pmc_(G()->td_db()->get_config_pmc_shared()) {
OptionManager::OptionManager(Td *td)
: td_(td), options_(td::make_unique<TsSeqKeyValue>()), option_pmc_(G()->td_db()->get_config_pmc_shared()) {
send_unix_time_update();
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;
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() {
// can be called from any thread
if (std::abs(G()->get_server_time_difference() - last_sent_server_time_difference_) < 0.5) {
return;
}

View File

@ -8,12 +8,11 @@
#include "td/telegram/td_api.h"
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include <atomic>
#include <memory>
namespace td {
@ -22,15 +21,14 @@ class KeyValueSyncInterface;
class Td;
class TsSeqKeyValue;
class OptionManager final : public Actor {
class OptionManager {
public:
OptionManager(Td *td, ActorShared<> parent);
explicit OptionManager(Td *td);
OptionManager(const OptionManager &) = delete;
OptionManager &operator=(const OptionManager &) = delete;
OptionManager(OptionManager &&) = delete;
OptionManager &operator=(OptionManager &&) = delete;
~OptionManager() final;
~OptionManager();
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;
private:
void tear_down() final;
void set_option(Slice name, Slice value);
void on_option_updated(Slice name);
@ -84,12 +80,11 @@ class OptionManager final : public Actor {
void send_unix_time_update();
Td *td_;
ActorShared<> parent_;
unique_ptr<TsSeqKeyValue> options_;
std::shared_ptr<KeyValueSyncInterface> option_pmc_;
double last_sent_server_time_difference_ = 1e100;
std::atomic<double> last_sent_server_time_difference_{1e100};
};
} // namespace td

View File

@ -3294,6 +3294,7 @@ void Td::dec_actor_refcnt() {
web_pages_manager_.reset();
LOG(DEBUG) << "WebPagesManager was cleared" << timer;
G()->set_option_manager(nullptr);
option_manager_.reset();
LOG(DEBUG) << "OptionManager was cleared" << timer;
@ -3465,8 +3466,6 @@ void Td::clear() {
LOG(DEBUG) << "NotificationManager actor was cleared" << timer;
notification_settings_manager_actor_.reset();
LOG(DEBUG) << "NotificationSettingsManager actor was cleared" << timer;
option_manager_actor_.reset();
LOG(DEBUG) << "OptionManager actor was cleared" << timer;
poll_manager_actor_.reset();
LOG(DEBUG) << "PollManager actor was cleared" << timer;
sponsored_message_manager_actor_.reset();
@ -3812,9 +3811,8 @@ void Td::init_options_and_network() {
G()->set_state_manager(state_manager_.get());
VLOG(td_init) << "Create OptionManager";
option_manager_ = make_unique<OptionManager>(this, create_reference());
option_manager_actor_ = register_actor("OptionManager", option_manager_.get());
G()->set_option_manager(option_manager_actor_.get());
option_manager_ = make_unique<OptionManager>(this);
G()->set_option_manager(option_manager_.get());
init_connection_creator();

View File

@ -133,6 +133,7 @@ class Td final : public Actor {
unique_ptr<AudiosManager> audios_manager_;
unique_ptr<CallbackQueriesManager> callback_queries_manager_;
unique_ptr<DocumentsManager> documents_manager_;
unique_ptr<OptionManager> option_manager_;
unique_ptr<VideoNotesManager> video_notes_manager_;
unique_ptr<VideosManager> videos_manager_;
@ -168,8 +169,6 @@ class Td final : public Actor {
ActorOwn<NotificationManager> notification_manager_actor_;
unique_ptr<NotificationSettingsManager> notification_settings_manager_;
ActorOwn<NotificationSettingsManager> notification_settings_manager_actor_;
unique_ptr<OptionManager> option_manager_;
ActorOwn<OptionManager> option_manager_actor_;
unique_ptr<PollManager> poll_manager_;
ActorOwn<PollManager> poll_manager_actor_;
unique_ptr<SponsoredMessageManager> sponsored_message_manager_;