/* 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 . */ #ifndef API_MODULE_DOWNLOADER_H_INCLUDED #define API_MODULE_DOWNLOADER_H_INCLUDED #include #include //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 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 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 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 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 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 children; int64_t size = 0, downloaded = 0; //file/dir size, downloaded size, optional std::map 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 info_map; //any additional info provided by downloader module can be stored here std::list content; //download content can be set for download, structure described above std::map metadata; //client defined metadata map }; class module_downloader : public module_base { public: //basic actions virtual int add_download(std::map 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 get_downloads(std::map params = std::map()) = 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 params = std::map()) = 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 metadata) = 0; //replace download metadata with provided one virtual bool metadata_update(int download_id, std::map 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 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