1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
Copyright © 2015 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
UDM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
UDM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UDM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef API_MODULE_DOWNLOADER_H_INCLUDED
#define API_MODULE_DOWNLOADER_H_INCLUDED
#include <api_module_base.h>
#include <list>
//i decided to avoid protobuf dependency in modules, so here is a copy/past of some protobuf declared structures required by downloader module
enum MODULE_UI_ELEMENT_TYPE_e {
UI_EMPTY_ = 0, //helper type to set empty element
UI_STR_ = 1, //ui elements containing strings
UI_INTEGER_, //numeric only ui elements (use strings instead ?)
UI_PROGRESS_BAR_, //generic progress bar
UI_WINDOW_, //ui window ...
UI_GROUP_ //empty ui element to group children together in ui (tabs can be implemented using this type)
};
struct module_download_ui_element_info_s {
MODULE_UI_ELEMENT_TYPE_e type = UI_EMPTY_;
std::list<module_download_ui_element_info_s> children;
std::string name, description; // name can be non unique, description is optional
bool data_required = false; //set to true if ui element require data from client (used in download creation ui)
int id; //internal element id used to get element value (should be unique for every loaded module)
};
//TODO: some mechanism for module to tell it's abilities, for example if it can provide download content, e.t.c.
struct module_download_menu_element_info_s {
std::string name, description; // name can be non unique, description is optional
int id; //internal element id used to get element value (should be unique for every loaded module)
bool data_required = false; //set to true if menu element require data from client
std::list<module_download_menu_element_info_s> children; //element with children cannot be executed, it's just container
};
struct downloader_module_info : public module_info_base //downloader_module_info must be returned via module_base::get_module_info() for downloader module
{
std::list<module_download_menu_element_info_s> download_root_menu, download_content_menu; //downloader module can add additional menu entries for download root and download content if content management supported by protocol
std::list<module_download_ui_element_info_s> download_info_ui, download_creation_ui; //downloader module should set all data fields required for download creation, also may set data fields for info in ui in client
std::map<std::string, std::string> get_downloads_parameters_info; //any supported parameters of get_downloads(), get_download_info() must be described here
};
enum DOWNLOAD_CONTENT_ENTRY_TYPE_s {
DOWNLOAD_CONTENT_ENTRY_TYPE_FILE_ = 0,
DOWNLOAD_CONTENT_ENTRY_TYPE_DIRECTORY_ = 1
};
struct download_content_entry_s { //here is basic content entry description, this may be file or directory, i have set basic attributes required, but additional may be specified in info_map
std::string name; //file/dir name, required
DOWNLOAD_CONTENT_ENTRY_TYPE_s type = DOWNLOAD_CONTENT_ENTRY_TYPE_FILE_;
std::list<download_content_entry_s> children;
int64_t size = 0, downloaded = 0; //file/dir size, downloaded size, optional
std::map<std::string, std::string> info_map; //any additional info
};
struct download_s {
int id = -1; //id generated via download_add or via session restore and it's unique for current session and current dowloader
std::string name;
int64_t size = 0, downloaded = 0, download_speed = 0; //download size and size of downloaded data, also download speed all vars in bytes
std::map<int, std::string> info_map; //any additional info provided by downloader module can be stored here
std::list<download_content_entry_s> content; //download content can be set for download, structure described above
std::map<std::string, std::string> metadata; //client defined metadata map
};
class module_downloader : public module_base
{
public:
//basic actions
virtual int add_download(std::map<int, std::string> params) = 0; //add download, this function must return unique for current session and current downloader download id, -1 on error
virtual bool stop_download(int download_id) = 0; //stop download by id received via add_download, return true on success, false otherwise
virtual bool start_download(int download_id) = 0; //start download by id received via add_download, return true on success, false otherwise
virtual bool delete_download(int download_id, bool delete_data = false) = 0; //delete download by id received via add_download, if "delete_data" is set, also remove all downloaded data from storage, return true on success, false otherwise
virtual bool execute_action_on_download(int download_id, int action_id) = 0; //execute module defined action on download, by id received via add_download
virtual std::list<download_s> get_downloads(std::map<int, std::string> params = std::map<int, std::string>()) = 0; //this function must return list of downloads, additional options may be passed via params map
virtual download_s get_download(int download_id, std::map<int, std::string> params = std::map<int, std::string>()) = 0; //same as above, except this one is for single download, not a complete list
//metadata manipulation (api for client specified metadata, unused by server itself, for example labels should be implemented using this api)
virtual bool metadata_set(int download_id, std::map<std::string, std::string> metadata) = 0; //replace download metadata with provided one
virtual bool metadata_update(int download_id, std::map<std::string, std::string> metadata) = 0; //updated matching metadata entries, create non existent
virtual bool metadata_drop(int download_id, std::string var = std::string()) = 0; //remove all metadata if no variable specified, otherwise delete specified variable
virtual std::map<std::string, std::string> metadata_get(int download_id) = 0; //get download metadata
virtual std::string metadata_get(int download_id, std::string var) = 0; //get value of specified metadata variable
protected:
downloader_module_info info;
};
#endif // API_MODULE_DOWNLOADER_H_INCLUDED
|