diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/include/api_module_downloader.h | 18 | ||||
-rw-r--r-- | server/src/server_session.cpp | 77 | ||||
-rw-r--r-- | server/udm-server.project | 10 |
3 files changed, 56 insertions, 49 deletions
diff --git a/server/include/api_module_downloader.h b/server/include/api_module_downloader.h index ba6cb6a..6445772 100644 --- a/server/include/api_module_downloader.h +++ b/server/include/api_module_downloader.h @@ -57,7 +57,8 @@ struct downloader_module_info : public module_info_base //downloader_module_info { 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 + std::map<std::string, std::string> get_downloads_parameters_info; //module defined parameters of get_downloads(), get_download_info() must be described here + std::map<int, std::string> download_state_names; //module defined download states }; enum DOWNLOAD_CONTENT_ENTRY_TYPE_s { @@ -75,15 +76,20 @@ struct download_content_entry_s { //here is basic content entry description, thi std::map<std::string, std::string> info_map; //any additional info }; +enum download_state_e { + stoppped = 0, + running = 1 +}; 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 + 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 + download_state_e state = download_state_e::stoppped; //download state can be module defined + 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 diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp index ff49408..2c8687d 100644 --- a/server/src/server_session.cpp +++ b/server/src/server_session.cpp @@ -420,34 +420,35 @@ bool server_session::handle_command(client_msg *msg) //draft implementation, need a lot of optimizations server_msg m; m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY); - for(auto i : downloads) - { - server_download_reply *r = m.add_downloads(); - download *d = r->mutable_download(); - d->set_id(i.first); //set core_id for later access - d->set_module_name(i.second.module_name); - module_base *module = nullptr; - for(auto dm : modules->get_downloader_modules()) - { + for(auto i : downloads) + { + server_download_reply *r = m.add_downloads(); + download *d = r->mutable_download(); + d->set_id(i.first); //set core_id for later access + d->set_module_name(i.second.module_name); + module_base *module = nullptr; + for(auto dm : modules->get_downloader_modules()) + { if(dm->get_module_info().name == i.second.module_name) { module = dm; break; } - } - if(!module) - { + } + if(!module) + { //downloader module not found, this should be a fatal error continue; - } - module_downloader *dm = static_cast<module_downloader*>(module); - download_s ds = dm->get_download(i.second.module_id); - d->set_downloaded(ds.downloaded); - d->set_size(ds.size); - d->set_name(ds.name); - } - send_message(&m); - return true; + } + module_downloader *dm = static_cast<module_downloader*>(module); + download_s ds = dm->get_download(i.second.module_id); + d->set_downloaded(ds.downloaded); + d->set_size(ds.size); + d->set_name(ds.name); + d->set_state(ds.state); + } + send_message(&m); + return true; } break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_ADD: @@ -459,24 +460,24 @@ bool server_session::handle_command(client_msg *msg) std::map<int, std::string> params; for(auto p : msg->download_add_request().params()) params[p.id()] = p.value(); - auto dm = static_cast<module_downloader *>(i); - int download_id = dm->add_download(params); - int core_id = downloads.size(); - downloads[core_id].module_id = download_id; - downloads[core_id].module_name = msg->download_add_request().module_name(); - server_msg m; - m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY); - download *d = m.mutable_download()->mutable_download(); - d->set_id(core_id); - auto dl = dm->get_download(download_id); - d->set_name(dl.name); - d->set_size(dl.size); - d->set_module_name(msg->download_add_request().module_name()); - d->set_downloaded(dl.downloaded); - send_message(&m); - + auto dm = static_cast<module_downloader *>(i); + int download_id = dm->add_download(params); + int core_id = downloads.size(); + downloads[core_id].module_id = download_id; + downloads[core_id].module_name = msg->download_add_request().module_name(); + server_msg m; + m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY); + download *d = m.mutable_download()->mutable_download(); + d->set_id(core_id); + auto dl = dm->get_download(download_id); + d->set_name(dl.name); + d->set_size(dl.size); + d->set_state(dl.state); + d->set_module_name(msg->download_add_request().module_name()); + d->set_downloaded(dl.downloaded); + send_message(&m); } - } + } } break; default: diff --git a/server/udm-server.project b/server/udm-server.project index 9a2b1b2..39a75cc 100644 --- a/server/udm-server.project +++ b/server/udm-server.project @@ -1,6 +1,9 @@ <?xml version="1.0" encoding="UTF-8"?> <CodeLite_Project Name="udm-server"> <Plugins> + <Plugin Name="qmake"> + <![CDATA[00010001N0005Debug000000000000]]> + </Plugin> <Plugin Name="CMakePlugin"> <![CDATA[[{ "name": "Debug", @@ -13,9 +16,6 @@ "parentProject": "" }]]]> </Plugin> - <Plugin Name="qmake"> - <![CDATA[00010001N0005Debug000000000000]]> - </Plugin> </Plugins> <Description/> <Dependencies/> @@ -89,8 +89,8 @@ <StartupCommands/> </Debugger> <PreBuild> - <Command Enabled="no">#[ -d ../protocol ] || mkdir ../protocol</Command> - <Command Enabled="no">#protoc --cpp_out=../protocol --proto_path=../protocol ../protocol/udm.proto</Command> + <Command Enabled="yes">[ -d ../protocol ] || mkdir ../protocol</Command> + <Command Enabled="yes">protoc --cpp_out=../protocol --proto_path=../protocol ../protocol/udm.proto</Command> </PreBuild> <PostBuild/> <CustomBuild Enabled="no"> |