diff options
Diffstat (limited to 'server/include/api_module_downloader.h')
-rw-r--r-- | server/include/api_module_downloader.h | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/server/include/api_module_downloader.h b/server/include/api_module_downloader.h index 3cf8ec6..7c68cad 100644 --- a/server/include/api_module_downloader.h +++ b/server/include/api_module_downloader.h @@ -22,13 +22,75 @@ #ifndef API_MODULE_DOWNLOADER_H_INCLUDED #define API_MODULE_DOWNLOADER_H_INCLUDED #include <api_module_base.h> +#include <list> -struct downloader_module_info : public module_info +//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 id,name; //internal element id used to get element value (should be unique for every loaded module), name can be non unique +}; + +//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 id, name, description; //internal element id used to get element value (should be unique for every loaded module), name can be non unique, description is optional + 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 //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 { + std::string id, name; //id generated via download_add or via session restore and it's unique for current session and current dowloader + int64_t size, downloaded; //download size and size of downloaded data + std::map<std::string, 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 }; class module_downloader : public module_base { +public: + virtual int add_download(std::map<std::string, std::string> params) = 0; //add download, this function must return unique for current session and current downloader download id + 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, std::string action_id) = 0; //execute module defined action on download, by id received via add_download + virtual std::list<download_s> get_downloads(std::map<std::string, std::string> params = std::map<std::string, std::string>()) = 0; //this function must return list of downloads, additional options may be passed via params map + virtual download_s get_download_info(int download_id, std::map<std::string, std::string> params = std::map<std::string, std::string>()) = 0; //same as above, except this one is for single download, not a complete list }; |