Don't inherit FileManager from FileLoadManager::Callback.
This commit is contained in:
parent
1c3d52eec6
commit
1d6e7f5b1c
@ -17,7 +17,9 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
FileLoadManager::FileLoadManager(ActorShared<Callback> callback, ActorShared<> parent)
|
||||
FileLoadManager::Callback::~Callback() = default;
|
||||
|
||||
FileLoadManager::FileLoadManager(unique_ptr<Callback> callback, ActorShared<> parent)
|
||||
: callback_(std::move(callback)), parent_(std::move(parent)) {
|
||||
}
|
||||
|
||||
@ -212,7 +214,7 @@ void FileLoadManager::on_start_download() {
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_start_download, node->query_id_);
|
||||
callback_->on_start_download(node->query_id_);
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,8 +225,7 @@ void FileLoadManager::on_partial_download(PartialLocalFileLocation partial_local
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_partial_download, node->query_id_, std::move(partial_local), ready_size,
|
||||
size);
|
||||
callback_->on_partial_download(node->query_id_, std::move(partial_local), ready_size, size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +236,7 @@ void FileLoadManager::on_hash(string hash) {
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_hash, node->query_id_, std::move(hash));
|
||||
callback_->on_hash(node->query_id_, std::move(hash));
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,7 +247,7 @@ void FileLoadManager::on_partial_upload(PartialRemoteFileLocation partial_remote
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_partial_upload, node->query_id_, std::move(partial_remote), ready_size);
|
||||
callback_->on_partial_upload(node->query_id_, std::move(partial_remote), ready_size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +258,7 @@ void FileLoadManager::on_ok_download(FullLocalFileLocation local, int64 size, bo
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_download_ok, node->query_id_, std::move(local), size, is_new);
|
||||
callback_->on_download_ok(node->query_id_, std::move(local), size, is_new);
|
||||
}
|
||||
close_node(node_id);
|
||||
loop();
|
||||
@ -270,7 +271,7 @@ void FileLoadManager::on_ok_upload(FileType file_type, PartialRemoteFileLocation
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_upload_ok, node->query_id_, file_type, std::move(remote), size);
|
||||
callback_->on_upload_ok(node->query_id_, file_type, std::move(remote), size);
|
||||
}
|
||||
close_node(node_id);
|
||||
loop();
|
||||
@ -283,7 +284,7 @@ void FileLoadManager::on_ok_upload_full(FullRemoteFileLocation remote) {
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_upload_full_ok, node->query_id_, std::move(remote));
|
||||
callback_->on_upload_full_ok(node->query_id_, std::move(remote));
|
||||
}
|
||||
close_node(node_id);
|
||||
loop();
|
||||
@ -301,7 +302,7 @@ void FileLoadManager::on_error_impl(NodeId node_id, Status status) {
|
||||
return;
|
||||
}
|
||||
if (!stop_flag_) {
|
||||
send_closure(callback_, &Callback::on_error, node->query_id_, std::move(status));
|
||||
callback_->on_error(node->query_id_, std::move(status));
|
||||
}
|
||||
close_node(node_id);
|
||||
loop();
|
||||
|
@ -32,8 +32,9 @@ namespace td {
|
||||
class FileLoadManager final : public Actor {
|
||||
public:
|
||||
using QueryId = uint64;
|
||||
class Callback : public Actor {
|
||||
class Callback {
|
||||
public:
|
||||
virtual ~Callback();
|
||||
virtual void on_start_download(QueryId query_id) = 0;
|
||||
virtual void on_partial_download(QueryId query_id, PartialLocalFileLocation partial_local, int64 ready_size,
|
||||
int64 size) = 0;
|
||||
@ -45,7 +46,7 @@ class FileLoadManager final : public Actor {
|
||||
virtual void on_error(QueryId query_id, Status status) = 0;
|
||||
};
|
||||
|
||||
explicit FileLoadManager(ActorShared<Callback> callback, ActorShared<> parent);
|
||||
explicit FileLoadManager(unique_ptr<Callback> callback, ActorShared<> parent);
|
||||
|
||||
void download(QueryId query_id, const FullRemoteFileLocation &remote_location, const LocalFileLocation &local,
|
||||
int64 size, string name, const FileEncryptionKey &encryption_key, bool search_file, int64 offset,
|
||||
@ -83,7 +84,7 @@ class FileLoadManager final : public Actor {
|
||||
ActorOwn<ResourceManager> upload_resource_manager_;
|
||||
|
||||
Container<Node> nodes_container_;
|
||||
ActorShared<Callback> callback_;
|
||||
unique_ptr<Callback> callback_;
|
||||
ActorShared<> parent_;
|
||||
std::map<QueryId, NodeId> query_id_to_node_id_;
|
||||
int64 max_download_resource_limit_ = 1 << 21;
|
||||
|
@ -887,7 +887,8 @@ FileManager::FileManager(unique_ptr<Context> context) : context_(std::move(conte
|
||||
|
||||
void FileManager::init_actor() {
|
||||
file_load_manager_ = create_actor_on_scheduler<FileLoadManager>("FileLoadManager", G()->get_slow_net_scheduler_id(),
|
||||
actor_shared(this), context_->create_reference());
|
||||
make_unique<FileLoadManagerCallback>(actor_id(this)),
|
||||
context_->create_reference());
|
||||
file_generate_manager_ = create_actor_on_scheduler<FileGenerateManager>(
|
||||
"FileGenerateManager", G()->get_slow_net_scheduler_id(), context_->create_reference());
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ class FileView {
|
||||
ConstFileNodePtr node_{};
|
||||
};
|
||||
|
||||
class FileManager final : public FileLoadManager::Callback {
|
||||
class FileManager final : public Actor {
|
||||
public:
|
||||
static constexpr int64 KEEP_DOWNLOAD_LIMIT = -1;
|
||||
static constexpr int64 KEEP_DOWNLOAD_OFFSET = -1;
|
||||
@ -559,6 +559,50 @@ class FileManager final : public FileLoadManager::Callback {
|
||||
FileId parse_file(ParserT &parser);
|
||||
|
||||
private:
|
||||
class FileLoadManagerCallback final : public FileLoadManager::Callback {
|
||||
public:
|
||||
explicit FileLoadManagerCallback(ActorId<FileManager> actor_id) : actor_id_(std::move(actor_id)) {
|
||||
}
|
||||
|
||||
private:
|
||||
ActorId<FileManager> actor_id_;
|
||||
|
||||
void on_start_download(FileLoadManager::QueryId query_id) final {
|
||||
send_closure(actor_id_, &FileManager::on_start_download, query_id);
|
||||
}
|
||||
|
||||
void on_partial_download(FileLoadManager::QueryId query_id, PartialLocalFileLocation partial_local,
|
||||
int64 ready_size, int64 size) final {
|
||||
send_closure(actor_id_, &FileManager::on_partial_download, query_id, std::move(partial_local), ready_size, size);
|
||||
}
|
||||
|
||||
void on_partial_upload(FileLoadManager::QueryId query_id, PartialRemoteFileLocation partial_remote,
|
||||
int64 ready_size) final {
|
||||
send_closure(actor_id_, &FileManager::on_partial_upload, query_id, std::move(partial_remote), ready_size);
|
||||
}
|
||||
|
||||
void on_hash(FileLoadManager::QueryId query_id, string hash) final {
|
||||
send_closure(actor_id_, &FileManager::on_hash, query_id, std::move(hash));
|
||||
}
|
||||
|
||||
void on_upload_ok(FileLoadManager::QueryId query_id, FileType file_type, PartialRemoteFileLocation remote,
|
||||
int64 size) final {
|
||||
send_closure(actor_id_, &FileManager::on_upload_ok, query_id, file_type, std::move(remote), size);
|
||||
}
|
||||
|
||||
void on_upload_full_ok(FileLoadManager::QueryId query_id, FullRemoteFileLocation remote) final {
|
||||
send_closure(actor_id_, &FileManager::on_upload_full_ok, query_id, std::move(remote));
|
||||
}
|
||||
|
||||
void on_download_ok(FileLoadManager::QueryId query_id, FullLocalFileLocation local, int64 size, bool is_new) final {
|
||||
send_closure(actor_id_, &FileManager::on_download_ok, query_id, std::move(local), size, is_new);
|
||||
}
|
||||
|
||||
void on_error(FileLoadManager::QueryId query_id, Status status) final {
|
||||
send_closure(actor_id_, &FileManager::on_error, query_id, std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
Result<FileId> check_input_file_id(FileType type, Result<FileId> result, bool is_encrypted, bool allow_zero,
|
||||
bool is_secure) TD_WARN_UNUSED_RESULT;
|
||||
|
||||
@ -710,15 +754,14 @@ class FileManager final : public FileLoadManager::Callback {
|
||||
void run_download(FileNodePtr node, bool force_update_priority);
|
||||
void run_generate(FileNodePtr node);
|
||||
|
||||
void on_start_download(QueryId query_id) final;
|
||||
void on_partial_download(QueryId query_id, PartialLocalFileLocation partial_local, int64 ready_size,
|
||||
int64 size) final;
|
||||
void on_hash(QueryId query_id, string hash) final;
|
||||
void on_partial_upload(QueryId query_id, PartialRemoteFileLocation partial_remote, int64 ready_size) final;
|
||||
void on_download_ok(QueryId query_id, FullLocalFileLocation local, int64 size, bool is_new) final;
|
||||
void on_upload_ok(QueryId query_id, FileType file_type, PartialRemoteFileLocation partial_remote, int64 size) final;
|
||||
void on_upload_full_ok(QueryId query_id, FullRemoteFileLocation remote) final;
|
||||
void on_error(QueryId query_id, Status status) final;
|
||||
void on_start_download(QueryId query_id);
|
||||
void on_partial_download(QueryId query_id, PartialLocalFileLocation partial_local, int64 ready_size, int64 size);
|
||||
void on_hash(QueryId query_id, string hash);
|
||||
void on_partial_upload(QueryId query_id, PartialRemoteFileLocation partial_remote, int64 ready_size);
|
||||
void on_download_ok(QueryId query_id, FullLocalFileLocation local, int64 size, bool is_new);
|
||||
void on_upload_ok(QueryId query_id, FileType file_type, PartialRemoteFileLocation partial_remote, int64 size);
|
||||
void on_upload_full_ok(QueryId query_id, FullRemoteFileLocation remote);
|
||||
void on_error(QueryId query_id, Status status);
|
||||
|
||||
void on_error_impl(FileNodePtr node, Query::Type type, bool was_active, Status status);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user