2022-02-23 19:34:09 +01:00
|
|
|
//
|
|
|
|
// 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
|
2022-02-25 14:18:23 +01:00
|
|
|
|
2022-02-23 19:34:09 +01:00
|
|
|
#include "td/telegram/files/FileId.h"
|
2022-03-01 13:54:04 +01:00
|
|
|
#include "td/telegram/files/FileManager.h"
|
2022-02-23 19:34:09 +01:00
|
|
|
#include "td/telegram/files/FileSourceId.h"
|
2022-02-25 13:11:10 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
2022-02-25 14:18:23 +01:00
|
|
|
|
|
|
|
#include "td/actor/actor.h"
|
|
|
|
|
2022-02-23 19:34:09 +01:00
|
|
|
#include "td/utils/common.h"
|
2022-06-27 12:30:18 +02:00
|
|
|
#include "td/utils/Promise.h"
|
2022-02-23 19:34:09 +01:00
|
|
|
|
|
|
|
namespace td {
|
2022-02-25 14:18:23 +01:00
|
|
|
|
|
|
|
class DownloadManager : public Actor {
|
2022-02-23 19:34:09 +01:00
|
|
|
public:
|
|
|
|
struct Counters {
|
|
|
|
int64 total_size{};
|
|
|
|
int32 total_count{};
|
|
|
|
int64 downloaded_size{};
|
2022-02-25 15:57:08 +01:00
|
|
|
|
2022-02-26 19:55:12 +01:00
|
|
|
bool operator==(const Counters &other) const {
|
2022-02-26 21:54:01 +01:00
|
|
|
return total_size == other.total_size && total_count == other.total_count &&
|
|
|
|
downloaded_size == other.downloaded_size;
|
2022-02-26 19:55:12 +01:00
|
|
|
}
|
|
|
|
|
2022-02-27 16:23:06 +01:00
|
|
|
td_api::object_ptr<td_api::updateFileDownloads> get_update_file_downloads_object() const;
|
|
|
|
|
2022-02-26 19:55:12 +01:00
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2022-02-23 19:34:09 +01:00
|
|
|
};
|
|
|
|
|
2022-03-05 02:11:18 +01:00
|
|
|
struct FileCounters {
|
|
|
|
int32 active_count{};
|
|
|
|
int32 paused_count{};
|
|
|
|
int32 completed_count{};
|
|
|
|
|
|
|
|
bool operator==(const FileCounters &other) const {
|
|
|
|
return active_count == other.active_count && paused_count == other.paused_count &&
|
|
|
|
completed_count == other.completed_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::downloadedFileCounts> get_downloaded_file_counts_object() const;
|
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
|
|
|
};
|
|
|
|
|
2022-03-09 01:27:03 +01:00
|
|
|
// Callback is needed to make DownloadManager testable
|
2022-02-23 19:34:09 +01:00
|
|
|
class Callback {
|
|
|
|
public:
|
|
|
|
virtual ~Callback() = default;
|
|
|
|
virtual void update_counters(Counters counters) = 0;
|
2022-03-05 01:14:31 +01:00
|
|
|
virtual void update_file_added(FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date,
|
2022-03-06 01:20:18 +01:00
|
|
|
bool is_paused, FileCounters counters) = 0;
|
|
|
|
virtual void update_file_changed(FileId file_id, int32 complete_date, bool is_paused, FileCounters counters) = 0;
|
|
|
|
virtual void update_file_removed(FileId file_id, FileCounters counters) = 0;
|
2022-03-02 11:56:04 +01:00
|
|
|
virtual void start_file(FileId file_id, int8 priority, ActorShared<DownloadManager> download_manager) = 0;
|
2022-02-23 19:34:09 +01:00
|
|
|
virtual void pause_file(FileId file_id) = 0;
|
|
|
|
virtual void delete_file(FileId file_id) = 0;
|
|
|
|
virtual FileId dup_file_id(FileId file_id) = 0;
|
|
|
|
|
2022-07-23 16:01:27 +02:00
|
|
|
virtual void get_file_search_text(FileId file_id, FileSourceId file_source_id, Promise<string> &&promise) = 0;
|
|
|
|
|
2022-03-03 19:11:34 +01:00
|
|
|
virtual FileView get_sync_file_view(FileId file_id) = 0;
|
2022-07-23 16:11:25 +02:00
|
|
|
virtual td_api::object_ptr<td_api::file> get_file_object(FileId file_id) = 0;
|
2022-02-27 16:23:06 +01:00
|
|
|
virtual td_api::object_ptr<td_api::fileDownload> get_file_download_object(FileId file_id,
|
|
|
|
FileSourceId file_source_id,
|
|
|
|
int32 add_date, int32 complete_date,
|
|
|
|
bool is_paused) = 0;
|
2022-02-23 19:34:09 +01:00
|
|
|
};
|
|
|
|
|
2022-03-02 11:56:04 +01:00
|
|
|
static unique_ptr<DownloadManager> create(unique_ptr<Callback> callback);
|
|
|
|
|
2022-02-23 19:34:09 +01:00
|
|
|
//
|
|
|
|
// public interface for user
|
|
|
|
//
|
2022-07-23 16:11:25 +02:00
|
|
|
virtual void add_file(FileId file_id, FileSourceId file_source_id, string search_text, int8 priority,
|
|
|
|
Promise<td_api::object_ptr<td_api::file>> promise) = 0;
|
2022-07-23 15:41:03 +02:00
|
|
|
virtual void toggle_is_paused(FileId file_id, bool is_paused, Promise<Unit> promise) = 0;
|
|
|
|
virtual void toggle_all_is_paused(bool is_paused, Promise<Unit> promise) = 0;
|
2022-02-28 16:25:07 +01:00
|
|
|
virtual void search(string query, bool only_active, bool only_completed, string offset, int32 limit,
|
|
|
|
Promise<td_api::object_ptr<td_api::foundFileDownloads>> promise) = 0;
|
2022-07-23 15:41:03 +02:00
|
|
|
virtual void remove_file(FileId file_id, FileSourceId file_source_id, bool delete_from_cache,
|
|
|
|
Promise<Unit> promise) = 0;
|
|
|
|
virtual void remove_all_files(bool only_active, bool only_completed, bool delete_from_cache,
|
|
|
|
Promise<Unit> promise) = 0;
|
2022-02-23 19:34:09 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// private interface to handle all kinds of updates
|
|
|
|
//
|
2022-07-23 16:11:25 +02:00
|
|
|
virtual void after_get_difference() = 0;
|
|
|
|
virtual void change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) = 0;
|
|
|
|
virtual void remove_file_if_finished(FileId file_id) = 0;
|
2022-03-02 16:29:49 +01:00
|
|
|
virtual void update_file_download_state(FileId internal_file_id, int64 downloaded_size, int64 size,
|
|
|
|
int64 expected_size, bool is_paused) = 0;
|
2022-02-28 16:25:07 +01:00
|
|
|
virtual void update_file_deleted(FileId internal_file_id) = 0;
|
2022-03-03 11:44:05 +01:00
|
|
|
virtual void update_file_viewed(FileId file_id, FileSourceId file_source_id) = 0;
|
2022-02-23 19:34:09 +01:00
|
|
|
};
|
2022-02-25 14:18:23 +01:00
|
|
|
|
|
|
|
} // namespace td
|