diff options
-rw-r--r-- | client-qt/udm-client-qt/udm_main.cpp | 7 | ||||
-rw-r--r-- | protocol/download.proto | 6 | ||||
-rw-r--r-- | protocol/udm.proto | 3 | ||||
-rw-r--r-- | server/include/event_subscription_base.h | 4 | ||||
-rw-r--r-- | server/src/server_session.cpp | 30 |
5 files changed, 47 insertions, 3 deletions
diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp index 9fe80b3..49a5c61 100644 --- a/client-qt/udm-client-qt/udm_main.cpp +++ b/client-qt/udm-client-qt/udm_main.cpp @@ -289,6 +289,13 @@ void udm_main::server_message_received(server_msg msg) s->set_mode(SUBSCRIPTION_MODE::SM_EVENT); //this type of event support only "event" mode s->set_module_name(""); //we need this event for all installed modules + s = msg.add_subscription_request(); + s->set_type(SUBSCRIPTION_TYPE::ST_DOWNLOAD_STATE_CHANGE); //fire event than download state changed + s->set_mode(SUBSCRIPTION_MODE::SM_EVENT); + s->set_module_name(""); + s->mutable_download_state_change()->add_states(SDS_STARTED); //subscript to download started event + s->mutable_download_state_change()->add_states(SDS_STOPPED); //subscript to download stopped event + session->send_message(msg); } } diff --git a/protocol/download.proto b/protocol/download.proto index d40ecb9..7684db3 100644 --- a/protocol/download.proto +++ b/protocol/download.proto @@ -19,6 +19,7 @@ */ import "misc.proto"; +import "events.proto"; message client_download_add_request { required string module_name = 1; @@ -80,3 +81,8 @@ message download { message server_download_reply { required download download = 1; } + +message download_state_change { + required int32 download_id = 1; + required SUBSCRIPTION_DOWNLOAD_STATE state = 2; +} diff --git a/protocol/udm.proto b/protocol/udm.proto index d80e1f0..78793fb 100644 --- a/protocol/udm.proto +++ b/protocol/udm.proto @@ -74,6 +74,7 @@ message client_msg { repeated client_event_unsubscription_request unsubscription_request = 6; optional client_download_request download_info_request = 7; optional client_download_add_request download_add_request = 8; + //TODO: use new download_state_change_request instaed of all download_*_request structures (simplification) repeated client_download_start_request download_start_request = 9; repeated client_download_stop_request download_stop_request = 10; repeated client_download_delete_request download_delete_request = 11; @@ -92,6 +93,7 @@ enum SERVER_MSG_TYPE { SERVER_UNSUBSCRIPTIONS_REPLY = 5; SERVER_DOWNLOADS_LIST_REPLY = 6; SERVER_DOWNLOAD_INFO_REPLY = 7; + SERVER_DOWNLOAD_STATE_CHANGE = 8; } @@ -106,6 +108,7 @@ message server_msg { repeated server_event_unsubscription_reply unsubscription_reply = 7; optional server_download_reply download = 8; repeated server_download_reply downloads = 9; + repeated download_state_change download_state_changes = 10; } //top level messages end diff --git a/server/include/event_subscription_base.h b/server/include/event_subscription_base.h index 97c6e62..aac316b 100644 --- a/server/include/event_subscription_base.h +++ b/server/include/event_subscription_base.h @@ -45,6 +45,10 @@ public: { return subtype; } + const client_event_subscription_request& get_subscription_request() + { + return subscription_request; + } virtual ~event_subscription_base(){} protected: diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp index ee15426..0d92341 100644 --- a/server/src/server_session.cpp +++ b/server/src/server_session.cpp @@ -478,6 +478,8 @@ bool server_session::handle_command(client_msg *msg) break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_START: { + server_msg s_msg; + s_msg.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_STATE_CHANGE); for(auto i : msg->download_start_request()) { for(auto m : modules->get_downloader_modules()) @@ -492,17 +494,21 @@ bool server_session::handle_command(client_msg *msg) } else { - //fire_event(SUBSCRIPTION_TYPE::); - //TODO: fire event + auto dsc = s_msg.add_download_state_changes(); + dsc->set_download_id(i.download_id()); + dsc->set_state(SUBSCRIPTION_DOWNLOAD_STATE::SDS_STARTED); } break; } } } + fire_event(SUBSCRIPTION_TYPE::ST_DOWNLOAD_STATE_CHANGE, s_msg); } break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_STOP: { + server_msg s_msg; + s_msg.set_type(SERVER_MSG_TYPE::SERVER_DOWNLOAD_STATE_CHANGE); for(auto i : msg->download_stop_request()) { for(auto m : modules->get_downloader_modules()) @@ -516,12 +522,15 @@ bool server_session::handle_command(client_msg *msg) } else { - //TODO: fire event + auto dsc = s_msg.add_download_state_changes(); + dsc->set_download_id(i.download_id()); + dsc->set_state(SUBSCRIPTION_DOWNLOAD_STATE::SDS_STOPPED); } break; } } } + fire_event(SUBSCRIPTION_TYPE::ST_DOWNLOAD_STATE_CHANGE, s_msg); } break; case CLIENT_MSG_TYPE::CLIENT_DOWNLOAD_DELETE: @@ -657,6 +666,21 @@ void server_session::fire_event(SUBSCRIPTION_TYPE type, server_msg &msg) send_message(&msg); } break; + case SUBSCRIPTION_TYPE::ST_DOWNLOAD_STATE_CHANGE: + { + server_msg filtered_message; //use new message to send only events from subscription and filter out all other download state change events + filtered_message.set_type(msg.type()); + for(auto sc : msg.download_state_changes()) + { + auto dsc = std::find((*s)->get_subscription_request().download_state_change().states().begin(), (*s)->get_subscription_request().download_state_change().states().end(), sc.state()); + if(dsc != (*s)->get_subscription_request().download_state_change().states().end()) + { + auto sc2 = filtered_message.add_download_state_changes(); + *sc2 = sc; + } + } + send_message(&filtered_message); + } default: break; } |