diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-09-24 14:37:36 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-09-24 14:37:36 +0300 |
commit | 380a818768c810b7d9eed5cb240c15305921910f (patch) | |
tree | 97b256c50c2d3cce326414761c4e3b3b599e9220 /server/src | |
parent | b7065f2918cd3b2c44d40d40c457f7a09d32ec10 (diff) |
protocol:
use repeated instead of optional fields for download_start_request, download_stop_request, download_delete_request, download_action_request - this allow to execute same action on multiple downloads via one message which is much more efficient than send
message for each download
client-qt:
basic download menu (without dynamic actions)
implemented start/stop/delete proto part
server:
core:
basic protocol implementation for: CLIENT_DOWNLOAD_INFO_REQUEST, CLIENT_DOWNLOAD_START, CLIENT_DOWNLOAD_STOP, CLIENT_DOWNLOAD_DELETE
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/server_session.cpp | 140 |
1 files changed, 111 insertions, 29 deletions
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp index 868370a..43d8837 100644 --- a/server/src/server_session.cpp +++ b/server/src/server_session.cpp @@ -421,40 +421,28 @@ bool server_session::handle_command(client_msg *msg) } break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOADS_LIST_REQUEST: + send_download_list(); + break; + case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_INFO_REQUEST: { - //TODO: thread safety - //draft implementation, need a lot of optimizations - server_msg m; - m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOADS_LIST_REPLY); - for(auto i : downloads) + for(auto i : modules->get_downloader_modules()) { - 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(i->get_module_info().name == downloads[msg->download_info_request().download_id()].module_name) { - //downloader module not found, this should be a fatal error - continue; + auto dm = static_cast<module_downloader *>(i); + server_msg m; + m.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_INFO_REPLY); + download *d = m.mutable_download()->mutable_download(); + d->set_id(msg->download_info_request().download_id()); + auto dl = dm->get_download(downloads[msg->download_info_request().download_id()].module_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); } - 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: @@ -482,6 +470,64 @@ bool server_session::handle_command(client_msg *msg) d->set_module_name(msg->download_add_request().module_name()); d->set_downloaded(dl.downloaded); send_message(&m); + break; + } + } + } + break; + case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_START: + { + for(auto i : msg->download_start_request()) + { + for(auto m : modules->get_downloader_modules()) + { + if(m->get_module_info().name == downloads[i.download_id()].module_name) + { + auto dm = static_cast<module_downloader *>(m); + if(!dm->start_download(i.download_id())) + { + //TODO: handle error + } + break; + } + } + } + } + break; + case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_STOP: + { + for(auto i : msg->download_stop_request()) + { + for(auto m : modules->get_downloader_modules()) + { + if(m->get_module_info().name == downloads[i.download_id()].module_name) + { + auto dm = static_cast<module_downloader *>(m); + if(!dm->stop_download(i.download_id())) + { + //TODO: handle error + } + break; + } + } + } + } + break; + case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_DELETE: + { + for(auto i : msg->download_delete_request()) + { + for(auto m : modules->get_downloader_modules()) + { + if(m->get_module_info().name == downloads[i.download_id()].module_name) + { + auto dm = static_cast<module_downloader *>(m); + if(!dm->delete_download(i.download_id(), i.with_data())); + { + //TODO: handle error + } + break; + } } } } @@ -493,6 +539,42 @@ bool server_session::handle_command(client_msg *msg) return true; } +void server_session::send_download_list() +{ + //TODO: thread safety + //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()) + { + if(dm->get_module_info().name == i.second.module_name) + { + module = dm; + break; + } + } + 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); + d->set_state(ds.state); + } + send_message(&m); +} + void server_session::send_message(server_msg *msg) { int size = 0; |