diff options
-rw-r--r-- | protocol/udm.proto | 14 | ||||
-rw-r--r-- | server/include/api_module_base.h | 8 | ||||
-rw-r--r-- | server/include/api_module_downloader.h | 64 | ||||
-rw-r--r-- | server/src/modules_handler.cpp | 4 |
4 files changed, 81 insertions, 9 deletions
diff --git a/protocol/udm.proto b/protocol/udm.proto index 3ee2f63..15de0b7 100644 --- a/protocol/udm.proto +++ b/protocol/udm.proto @@ -43,7 +43,8 @@ message module_download_menu_element_info { required string id = 1; required string name = 2; optional string description = 3; - repeated module_download_menu_element_info children = 4; + optional bool data_required = 4 [default = false]; + repeated module_download_menu_element_info children = 5; //element with children cannot be executed, it's just container } @@ -107,6 +108,7 @@ message download_content_entry { optional DOWNLOAD_CONTENT_ENTRY_TYPE type = 2 [default = DOWNLOAD_CONTENT_ENTRY_TYPE_FILE]; repeated download_content_entry children = 3; optional int64 size = 4 [default = 0]; + optional int64 downloaded = 5 [default = 0]; } @@ -195,6 +197,13 @@ enum SERVER_MODULE_TYPE { SERVER_MODULE_METADATA_STORAGE = 2; } +message string_pair +{ + required string name = 1; + required string description = 2; +} + + message module_info { required SERVER_MODULE_TYPE type = 1; @@ -202,10 +211,11 @@ message module_info required string version = 3; optional string decription = 4 [default = "no description specified"]; repeated setting_info settings = 5; - repeated module_download_ui_element_info download_ui = 6; //always complete here + repeated module_download_ui_element_info download_info_ui = 6; //always complete here repeated module_download_ui_element_info download_creation_ui = 7; repeated module_download_menu_element_info download_menu = 8; repeated module_download_menu_element_info download_children_menu = 9; //menu for files and folders inside download root, may not present + repeated string_pair get_downloads_parameters_info = 10; } //module related messages end diff --git a/server/include/api_module_base.h b/server/include/api_module_base.h index 1a9fc4f..89fc4dd 100644 --- a/server/include/api_module_base.h +++ b/server/include/api_module_base.h @@ -26,9 +26,9 @@ struct module_info { - std::string name, description, version; - std::map<std::string, std::string> default_settings; //to save in config file - boost::function<void()> on_modules_loaded; + std::string name, description, version; //module name must be set and must be unique, description and version is optional + std::map<std::string, std::string> default_settings; //set all settings supported by module here with default values to save in config for editing later + boost::function<void()> on_modules_loaded; //if set, this function will be called after basic initialization of all installed modules, so installed modules can be partially used here, for example metadata storage will be available }; class module_base @@ -36,7 +36,7 @@ class module_base public: virtual void load(core_api *a) = 0; virtual const module_info &get_module_info() = 0; - virtual void set_module_settings(const std::map<std::string, std::string> &settings) = 0; + virtual void set_module_settings(const std::map<std::string, std::string> &settings) = 0; //will called with settings stored in config virtual ~module_base() = 0; protected: std::map<std::string, std::string> settings; 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 }; diff --git a/server/src/modules_handler.cpp b/server/src/modules_handler.cpp index d69fabf..65148ef 100644 --- a/server/src/modules_handler.cpp +++ b/server/src/modules_handler.cpp @@ -95,7 +95,7 @@ void modules_handler::load_downloader_modules(const std::string &path) module_downloader *m = f(); m->load(module_api); sync_module_settings(m); - metadata_modules.push_back(m); + downloader_modules.push_back(m); } } } @@ -113,7 +113,7 @@ std::string modules_handler::list_modules() { std::string buf; buf += "Installed metadata modules:\n"; - buf += list_modules_single_type_internal((std::list<module_base*>)metadata_modules); + buf += list_modules_single_type_internal(metadata_modules); buf += "\nInstalled downloader modules:\n"; buf += list_modules_single_type_internal(downloader_modules); |