diff options
Diffstat (limited to 'server/include')
-rw-r--r-- | server/include/api_core.h | 5 | ||||
-rw-r--r-- | server/include/api_module_base.h | 22 | ||||
-rw-r--r-- | server/include/api_module_downloader.h | 24 | ||||
-rw-r--r-- | server/include/settings.h | 40 |
4 files changed, 72 insertions, 19 deletions
diff --git a/server/include/api_core.h b/server/include/api_core.h index 341bfc2..9af26f7 100644 --- a/server/include/api_core.h +++ b/server/include/api_core.h @@ -25,14 +25,15 @@ #include <vector> #include <map> -class module_base; +#include "settings.h" +class module_base; class core_api { public: //core - virtual std::map<std::string, std::string> get_module_settings(module_base *m); + virtual std::map<std::string, setting_s> get_module_settings(module_base *m); virtual std::map<std::string, std::string> get_core_settings(); //metadata diff --git a/server/include/api_module_base.h b/server/include/api_module_base.h index 89fc4dd..d8acf9b 100644 --- a/server/include/api_module_base.h +++ b/server/include/api_module_base.h @@ -21,25 +21,35 @@ #ifndef API_MODULE_BASE_H_INCLUDED #define API_MODULE_BASE_H_INCLUDED -#include <api_core.h> +#include "api_core.h" +#include "settings.h" #include <boost/function.hpp> -struct module_info + + +struct module_info_base { 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 + std::map<std::string, setting_s> 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 { 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; //will called with settings stored in config + virtual const module_info_base &get_module_info() = 0; + virtual void set_module_settings(const std::map<std::string, setting_s> &settings) = 0; //will called with settings stored in config + virtual std::map<std::string, setting_s> &get_runtime_module_settings() //get runtime module_settings, works faster than core_api function + { + return settings; + } virtual ~module_base() = 0; protected: - std::map<std::string, std::string> settings; + std::map<std::string, setting_s> settings; + core_api *api = nullptr; }; diff --git a/server/include/api_module_downloader.h b/server/include/api_module_downloader.h index ae91943..d980d62 100644 --- a/server/include/api_module_downloader.h +++ b/server/include/api_module_downloader.h @@ -27,16 +27,16 @@ //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) + 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; + MODULE_UI_ELEMENT_TYPE_e type = UI_EMPTY_; std::list<module_download_ui_element_info_s> children; std::string name; // name can be non unique int id; //internal element id used to get element value (should be unique for every loaded module) @@ -51,7 +51,7 @@ struct module_download_menu_element_info_s { }; -struct downloader_module_info : public module_info //downloader_module_info must be returned via module_base::get_module_info() for downloader module +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 @@ -59,15 +59,15 @@ struct downloader_module_info : public module_info //downloader_module_info must }; enum DOWNLOAD_CONTENT_ENTRY_TYPE_s { - DOWNLOAD_CONTENT_ENTRY_TYPE_FILE = 0, - DOWNLOAD_CONTENT_ENTRY_TYPE_DIRECTORY = 1 + 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; + 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 @@ -93,6 +93,8 @@ public: 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_info(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 +protected: + downloader_module_info info; }; diff --git a/server/include/settings.h b/server/include/settings.h new file mode 100644 index 0000000..ba8f017 --- /dev/null +++ b/server/include/settings.h @@ -0,0 +1,40 @@ +/* + 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 SETTINGS_H +#define SETTINGS_H + +#include <list> + +struct setting_info_s { + std::string default_value = "empty", minimal_value = "not set", maximal_value = "not set", description; + std::list<std::string> dependencies, blockers; //list containing all settings which must be turned on for this setting, list of settings which must be turned of for this setting +}; + +struct setting_s { + setting_info_s info; + std::string value; +}; + + + +#endif |