diff --git a/td/telegram/CountryInfoManager.cpp b/td/telegram/CountryInfoManager.cpp index d69c7487c..3d222e5cb 100644 --- a/td/telegram/CountryInfoManager.cpp +++ b/td/telegram/CountryInfoManager.cpp @@ -136,7 +136,7 @@ void CountryInfoManager::tear_down() { } string CountryInfoManager::get_main_language_code() { - return to_lower(td_->language_pack_manager_->get_actor_unsafe()->get_main_language_code()); + return to_lower(td_->language_pack_manager_.get_actor_unsafe()->get_main_language_code()); } void CountryInfoManager::get_countries(Promise> &&promise) { diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index a82aebf5a..a6f9ec84d 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2681,7 +2681,7 @@ void NotificationManager::process_push_notification(string payload, Promisedevice_token_manager_->get_actor_unsafe()->get_encryption_keys(); + auto encryption_keys = td_->device_token_manager_.get_actor_unsafe()->get_encryption_keys(); VLOG(notifications) << "Process push notification \"" << format::escaped(payload) << "\" with receiver_id = " << receiver_id << " and " << encryption_keys.size() << " encryption keys"; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index f83c1062a..154dafe96 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -9031,7 +9031,7 @@ void StickersManager::on_get_language_codes(const string &key, Result StickersManager::get_emoji_language_codes(const vector &input_language_codes, Slice text, Promise &promise) { - vector language_codes = td_->language_pack_manager_->get_actor_unsafe()->get_used_language_codes(); + vector language_codes = td_->language_pack_manager_.get_actor_unsafe()->get_used_language_codes(); auto system_language_code = G()->mtproto_header().get_system_language_code(); if (system_language_code.size() >= 2 && system_language_code.find('$') == string::npos && (system_language_code.size() == 2 || system_language_code[2] == '-')) { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index e337123ff..8cc62f79a 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3754,10 +3754,10 @@ void Td::init_connection_creator() { auto net_stats_manager = create_actor("NetStatsManager", create_reference()); // How else could I let two actor know about each other, without quite complex async logic? - auto net_stats_manager_ptr = net_stats_manager->get_actor_unsafe(); + auto net_stats_manager_ptr = net_stats_manager.get_actor_unsafe(); net_stats_manager_ptr->init(); - connection_creator->get_actor_unsafe()->set_net_stats_callback(net_stats_manager_ptr->get_common_stats_callback(), - net_stats_manager_ptr->get_media_stats_callback()); + connection_creator.get_actor_unsafe()->set_net_stats_callback(net_stats_manager_ptr->get_common_stats_callback(), + net_stats_manager_ptr->get_media_stats_callback()); G()->set_net_stats_file_callbacks(net_stats_manager_ptr->get_file_stats_callbacks()); G()->set_connection_creator(std::move(connection_creator)); @@ -4283,7 +4283,7 @@ void Td::on_request(uint64 id, const td_api::getCurrentState &request) { notification_manager_->get_current_state(updates); - config_manager_->get_actor_unsafe()->get_current_state(updates); + config_manager_.get_actor_unsafe()->get_current_state(updates); // TODO updateFileGenerationStart generation_id:int64 original_path:string destination_path:string conversion:string = Update; // TODO updateCall call:call = Update; diff --git a/tdactor/td/actor/impl/ActorId-decl.h b/tdactor/td/actor/impl/ActorId-decl.h index bdbc5da72..03db2775b 100644 --- a/tdactor/td/actor/impl/ActorId-decl.h +++ b/tdactor/td/actor/impl/ActorId-decl.h @@ -26,7 +26,7 @@ class ActorId { ActorId(const ActorId &other) = default; ActorId &operator=(const ActorId &other) = default; ActorId(ActorId &&other) noexcept : ptr_(other.ptr_) { - other.ptr_.clear(); + other.clear(); } ActorId &operator=(ActorId &&other) noexcept { if (&other == this) { @@ -52,9 +52,6 @@ class ActorId { ActorInfo *get_actor_info() const; ActorType *get_actor_unsafe() const; - // returns pointer to actor if it is on current thread. nullptr otherwise - ActorType *try_get_actor() const; - Slice get_name() const; template ::value>> @@ -62,11 +59,6 @@ class ActorId { return ActorId(ptr_); } - template - ActorId as() const { - return ActorId(ptr_); - } - private: ObjectPool::WeakPtr ptr_; }; @@ -99,10 +91,7 @@ class ActorOwn { ActorId release(); void reset(ActorId other = ActorId()); void hangup() const; - const ActorId *operator->() const; - - using ActorIdConstRef = const ActorId &; - // operator ActorIdConstRef(); + ActorType *get_actor_unsafe() const; private: ActorId id_; @@ -137,7 +126,6 @@ class ActorShared { void reset(ActorId other = ActorId()); template void reset(ActorId other); - const ActorId *operator->() const; private: ActorId id_; diff --git a/tdactor/td/actor/impl/ActorId.h b/tdactor/td/actor/impl/ActorId.h index bdc320e1f..fa93118e2 100644 --- a/tdactor/td/actor/impl/ActorId.h +++ b/tdactor/td/actor/impl/ActorId.h @@ -29,15 +29,6 @@ ActorType *ActorId::get_actor_unsafe() const { return static_cast(ptr_->get_actor_unsafe()); } -template -ActorType *ActorId::try_get_actor() const { - auto info = get_actor_info(); - if (info && !info->is_migrating() && Scheduler::instance()->sched_id() == info->migrate_dest()) { - return static_cast(info->get_actor_unsafe()); - } - return nullptr; -} - template Slice ActorId::get_name() const { return ptr_->get_name(); @@ -46,14 +37,17 @@ Slice ActorId::get_name() const { template ActorOwn::ActorOwn(ActorId id) : id_(std::move(id)) { } + template template ActorOwn::ActorOwn(ActorId id) : id_(std::move(id)) { } + template template ActorOwn::ActorOwn(ActorOwn &&other) : id_(other.release()) { } + template template ActorOwn &ActorOwn::operator=(ActorOwn &&other) { @@ -64,6 +58,7 @@ ActorOwn &ActorOwn::operator=(ActorOwn &&o template ActorOwn::ActorOwn(ActorOwn &&other) noexcept : id_(other.release()) { } + template ActorOwn &ActorOwn::operator=(ActorOwn &&other) noexcept { reset(other.release()); @@ -79,6 +74,7 @@ template bool ActorOwn::empty() const { return id_.empty(); } + template ActorId ActorOwn::get() const { return id_; @@ -88,6 +84,7 @@ template ActorId ActorOwn::release() { return std::move(id_); } + template void ActorOwn::reset(ActorId other) { static_assert(sizeof(ActorType) > 0, "Can't use ActorOwn with incomplete type"); @@ -101,23 +98,27 @@ void ActorOwn::hangup() const { send_event(id_, Event::hangup()); } } + template -const ActorId *ActorOwn::operator->() const { - return &id_; +ActorType *ActorOwn::get_actor_unsafe() const { + return id_.get_actor_unsafe(); } template template ActorShared::ActorShared(ActorId id, uint64 token) : id_(std::move(id)), token_(token) { } + template template ActorShared::ActorShared(ActorShared &&other) : id_(other.release()), token_(other.token()) { } + template template ActorShared::ActorShared(ActorOwn &&other) : id_(other.release()), token_(0) { } + template template ActorShared &ActorShared::operator=(ActorShared &&other) { @@ -129,6 +130,7 @@ ActorShared &ActorShared::operator=(ActorShared ActorShared::ActorShared(ActorShared &&other) noexcept : id_(other.release()), token_(other.token_) { } + template ActorShared &ActorShared::operator=(ActorShared &&other) noexcept { reset(other.release()); @@ -145,10 +147,12 @@ template uint64 ActorShared::token() const { return token_; } + template bool ActorShared::empty() const { return id_.empty(); } + template ActorId ActorShared::get() const { return id_; @@ -158,6 +162,7 @@ template ActorId ActorShared::release() { return std::move(id_); } + template void ActorShared::reset(ActorId other) { reset(std::move(other)); @@ -172,10 +177,6 @@ void ActorShared::reset(ActorId other) { } id_ = static_cast>(other); } -template -const ActorId *ActorShared::operator->() const { - return &id_; -} template ActorRef::ActorRef(const ActorId &actor_id) : actor_id_(actor_id) { diff --git a/test/secret.cpp b/test/secret.cpp index 5a602fe85..6e8e5d477 100644 --- a/test/secret.cpp +++ b/test/secret.cpp @@ -760,7 +760,7 @@ class Master final : public Actor { auto old_context = set_context(std::make_shared()); alice_ = create_actor("SecretChatProxy alice", "alice", actor_shared(this, 1)); bob_ = create_actor("SecretChatProxy bob", "bob", actor_shared(this, 2)); - send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::create_chat, UserId(static_cast(2)), 0, + send_closure(alice_.get_actor_unsafe()->actor_, &SecretChatActor::create_chat, UserId(static_cast(2)), 0, 123, PromiseCreator::lambda([actor_id = actor_id(this)](Result res) { send_closure(actor_id, &Master::got_secret_chat_id, std::move(res), false); })); @@ -838,9 +838,9 @@ class Master final : public Actor { void process_net_query(my_api::messages_requestEncryption &&request_encryption, NetQueryPtr net_query, ActorShared callback) { CHECK(get_link_token() == 1); - send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::update_chat, + send_closure(alice_.get_actor_unsafe()->actor_, &SecretChatActor::update_chat, make_tl_object(123, 321, 0, 1, 2)); - send_closure(bob_->get_actor_unsafe()->actor_, &SecretChatActor::update_chat, + send_closure(bob_.get_actor_unsafe()->actor_, &SecretChatActor::update_chat, make_tl_object(0, false, 123, 321, 0, 1, 2, request_encryption.g_a_.clone())); net_query->clear(); @@ -848,7 +848,7 @@ class Master final : public Actor { void process_net_query(my_api::messages_acceptEncryption &&request_encryption, NetQueryPtr net_query, ActorShared callback) { CHECK(get_link_token() == 2); - send_closure(alice_->get_actor_unsafe()->actor_, &SecretChatActor::update_chat, + send_closure(alice_.get_actor_unsafe()->actor_, &SecretChatActor::update_chat, make_tl_object(123, 321, 0, 1, 2, request_encryption.g_b_.clone(), request_encryption.key_fingerprint_));