2018-12-31 20:04:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2021-09-18 23:47:05 +02:00
|
|
|
#include "td/telegram/files/FileLocation.h"
|
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2023-08-05 15:09:36 +02:00
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace td {
|
2019-01-19 20:35:28 +01:00
|
|
|
|
2018-12-31 20:04:05 +01:00
|
|
|
class FileGenerateActor;
|
|
|
|
|
|
|
|
class FileGenerateCallback {
|
|
|
|
public:
|
|
|
|
FileGenerateCallback() = default;
|
|
|
|
FileGenerateCallback(const FileGenerateCallback &) = delete;
|
|
|
|
FileGenerateCallback &operator=(const FileGenerateCallback &) = delete;
|
|
|
|
virtual ~FileGenerateCallback() = default;
|
|
|
|
|
2022-05-11 16:17:20 +02:00
|
|
|
virtual void on_partial_generate(PartialLocalFileLocation partial_local, int64 expected_size) = 0;
|
2021-10-19 17:11:16 +02:00
|
|
|
virtual void on_ok(FullLocalFileLocation local) = 0;
|
2018-12-31 20:04:05 +01:00
|
|
|
virtual void on_error(Status error) = 0;
|
|
|
|
};
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class FileGenerateManager final : public Actor {
|
2018-12-31 20:04:05 +01:00
|
|
|
public:
|
|
|
|
explicit FileGenerateManager(ActorShared<> parent) : parent_(std::move(parent)) {
|
|
|
|
}
|
|
|
|
|
2018-10-30 15:25:31 +01:00
|
|
|
void generate_file(uint64 query_id, FullGenerateFileLocation generate_location,
|
2018-09-27 03:19:03 +02:00
|
|
|
const LocalFileLocation &local_location, string name, unique_ptr<FileGenerateCallback> callback);
|
2018-12-31 20:04:05 +01:00
|
|
|
void cancel(uint64 query_id);
|
|
|
|
|
|
|
|
// external updates about file generation state
|
2022-05-11 16:17:20 +02:00
|
|
|
void external_file_generate_write_part(uint64 query_id, int64 offset, string data, Promise<> promise);
|
|
|
|
void external_file_generate_progress(uint64 query_id, int64 expected_size, int64 local_prefix_size,
|
2018-12-31 20:04:05 +01:00
|
|
|
Promise<> promise);
|
|
|
|
void external_file_generate_finish(uint64 query_id, Status status, Promise<> promise);
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Query {
|
|
|
|
Query() = default;
|
2023-05-05 12:51:19 +02:00
|
|
|
Query(const Query &) = delete;
|
|
|
|
Query &operator=(const Query &) = delete;
|
2021-10-18 13:36:15 +02:00
|
|
|
Query(Query &&other) noexcept;
|
|
|
|
Query &operator=(Query &&other) noexcept;
|
2018-12-31 20:04:05 +01:00
|
|
|
~Query();
|
|
|
|
|
|
|
|
ActorOwn<FileGenerateActor> worker_;
|
|
|
|
};
|
|
|
|
|
|
|
|
ActorShared<> parent_;
|
|
|
|
std::map<uint64, Query> query_id_to_query_;
|
|
|
|
bool close_flag_ = false;
|
|
|
|
|
2021-07-03 22:51:36 +02:00
|
|
|
void hangup() final;
|
|
|
|
void hangup_shared() final;
|
|
|
|
void loop() final;
|
2018-12-31 20:04:05 +01:00
|
|
|
void do_cancel(uint64 query_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|