// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // 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/actor/impl/ActorId-decl.h" #include "td/actor/impl/ActorInfo-decl.h" #include "td/actor/impl/Scheduler-decl.h" #include "td/utils/Slice.h" namespace td { // If actor is on our scheduler(thread) result will be valid // If actor is on another scheduler we will see it in migrate_dest_flags template ActorInfo *ActorId::get_actor_info() const { if (ptr_.is_alive()) { return &*ptr_; } return nullptr; } template ActorType *ActorId::get_actor_unsafe() const { return static_cast(ptr_->get_actor_unsafe()); } template Slice ActorId::get_name() const { return ptr_->get_name(); } 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) { reset(static_cast>(other.release())); return *this; } template ActorOwn::ActorOwn(ActorOwn &&other) noexcept : id_(other.release()) { } template ActorOwn &ActorOwn::operator=(ActorOwn &&other) noexcept { reset(other.release()); return *this; } template ActorOwn::~ActorOwn() { reset(); } template bool ActorOwn::empty() const { return id_.empty(); } template ActorId ActorOwn::get() const { return id_; } 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"); if (!id_.empty()) { send_event(id_, Event::hangup()); } id_ = std::move(other); } template 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) { reset(other.release()); token_ = other.token(); return *this; } template ActorShared::ActorShared(ActorShared &&other) noexcept : id_(other.release()), token_(other.token_) { } template ActorShared &ActorShared::operator=(ActorShared &&other) noexcept { reset(other.release()); token_ = other.token_; return *this; } template ActorShared::~ActorShared() { reset(); } template uint64 ActorShared::token() const { return token_; } template bool ActorShared::empty() const { return id_.empty(); } template ActorId ActorShared::get() const { return id_; } template ActorId ActorShared::release() { return std::move(id_); } template void ActorShared::reset(ActorId other) { reset(std::move(other)); } template template void ActorShared::reset(ActorId other) { static_assert(sizeof(ActorType) > 0, "Can't use ActorShared with incomplete type"); if (!id_.empty()) { send_event(*this, Event::hangup()); } id_ = static_cast>(other); } template ActorRef::ActorRef(const ActorId &actor_id) : actor_id_(actor_id) { } template ActorRef::ActorRef(ActorId &&actor_id) : actor_id_(actor_id) { actor_id.clear(); } template ActorRef::ActorRef(const ActorShared &actor_id) : actor_id_(actor_id.get()), token_(actor_id.token()) { } template ActorRef::ActorRef(ActorShared &&actor_id) : actor_id_(actor_id.release()), token_(actor_id.token()) { } template ActorRef::ActorRef(const ActorOwn &actor_id) : actor_id_(actor_id.get()) { } template ActorRef::ActorRef(ActorOwn &&actor_id) : actor_id_(actor_id.release()) { } } // namespace td