diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/include/api_module_base.h | 2 | ||||
-rw-r--r-- | server/include/client.h | 30 | ||||
-rw-r--r-- | server/include/event_subscription_base.h | 42 | ||||
-rw-r--r-- | server/include/event_subscription_event.h | 35 | ||||
-rw-r--r-- | server/include/event_subscription_repeated.h | 38 | ||||
-rw-r--r-- | server/modules/downloaders/curl/main.cpp | 6 | ||||
-rw-r--r-- | server/modules/metadata/flat_files/main.cpp | 4 | ||||
-rw-r--r-- | server/src/client.cpp | 27 | ||||
-rw-r--r-- | server/src/event_subscription_event.cpp | 32 | ||||
-rw-r--r-- | server/src/event_subscription_repeated.cpp | 32 | ||||
-rw-r--r-- | server/src/server_session.cpp | 42 | ||||
-rw-r--r-- | server/udm-server.project | 5 |
12 files changed, 280 insertions, 15 deletions
diff --git a/server/include/api_module_base.h b/server/include/api_module_base.h index 6f01746..9c1b639 100644 --- a/server/include/api_module_base.h +++ b/server/include/api_module_base.h @@ -49,7 +49,7 @@ class module_base { return settings; } - virtual ~module_base() = 0; + virtual ~module_base(){}; protected: std::map<std::string, setting_s> settings; module_info_base info; diff --git a/server/include/client.h b/server/include/client.h index f9daff6..d6668a3 100644 --- a/server/include/client.h +++ b/server/include/client.h @@ -1,19 +1,47 @@ +/* + 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 CLIENT_H #define CLIENT_H #include <string> +#include <list> +#include "event_subscription_base.h" + +class server_session; class client { public: - client(std::string &client_auth_token); + client(std::string &client_auth_token, server_session *sess = nullptr); + void add_event_subscription(event_subscription_base* e); virtual ~client(); protected: private: //TODO: client subscriptions should be stored here //TODO: list of timers with direct callbacks to functions for periodic subscription (bost::asio::deadline_timer) //TODO: store sessions ptr list + //TODO: some way to call core and mopdules api from here std::string auth_token; + server_session *session; + std::list<event_subscription_base*> subscriptions; }; #endif // CLIENT_H diff --git a/server/include/event_subscription_base.h b/server/include/event_subscription_base.h new file mode 100644 index 0000000..19b184f --- /dev/null +++ b/server/include/event_subscription_base.h @@ -0,0 +1,42 @@ +/* + 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 EVENT_SUBSCRIPTION_H +#define EVENT_SUBSCRIPTION_H + +#include "../../protocol/udm.pb.h" + +//TODO: rework (events and polls separated ?) + +enum EVENT_SUBTYPE { + EVENT_SUBTYPE_REPEATED = 0, //periodic firing based on timer + EVENT_SUBTYPE_EVENT = 1, //fired on event occurs (only can be used for data which support this event type) +}; + +class event_subscription_base +{ +public: + event_subscription_base(){}; + virtual ~event_subscription_base(){}; +protected: + SUBSCRIPTION_TYPE type = SUBSCRIPTION_TYPE::S_DOWNLOAD_STATE_CHANGE; + EVENT_SUBTYPE subtype = EVENT_SUBTYPE::EVENT_SUBTYPE_EVENT; +}; +#endif // EVENT_SUBSCRIPTION_H diff --git a/server/include/event_subscription_event.h b/server/include/event_subscription_event.h new file mode 100644 index 0000000..16172cf --- /dev/null +++ b/server/include/event_subscription_event.h @@ -0,0 +1,35 @@ +/* + 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 EVENT_SUBSCRIPTION_EVENT_H +#define EVENT_SUBSCRIPTION_EVENT_H + +#include "event_subscription_base.h" + +class event_subscription_event : public event_subscription_base +{ +public: + event_subscription_event(client_event_subscription_request *req); + ~event_subscription_event(); + +}; + +#endif // EVENT_SUBSCRIPTION_EVENT_H diff --git a/server/include/event_subscription_repeated.h b/server/include/event_subscription_repeated.h new file mode 100644 index 0000000..bb676a3 --- /dev/null +++ b/server/include/event_subscription_repeated.h @@ -0,0 +1,38 @@ +/* + 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 EVENT_SUBSCRIPTION_PERIODIC_H +#define EVENT_SUBSCRIPTION_PERIODIC_H + +#include "event_subscription_base.h" + +class event_subscription_repeated : public event_subscription_base +{ +public: + event_subscription_repeated(client_event_subscription_request *req); + ~event_subscription_repeated(); +private: + bool one_time; + int64_t interval; + +}; + +#endif // EVENT_SUBSCRIPTION_PERIODIC_H diff --git a/server/modules/downloaders/curl/main.cpp b/server/modules/downloaders/curl/main.cpp index 0317f32..1a5e02b 100644 --- a/server/modules/downloaders/curl/main.cpp +++ b/server/modules/downloaders/curl/main.cpp @@ -28,12 +28,6 @@ #include "curl_download.h" - -module_base::~module_base() -{ -} - - downloader::downloader() { if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) diff --git a/server/modules/metadata/flat_files/main.cpp b/server/modules/metadata/flat_files/main.cpp index 5fe2182..079644f 100644 --- a/server/modules/metadata/flat_files/main.cpp +++ b/server/modules/metadata/flat_files/main.cpp @@ -180,10 +180,6 @@ storage_impl::storage_impl() { } -module_base::~module_base() -{ -} - extern "C" module_metadata_storage* udm_metadata_module_load() { diff --git a/server/src/client.cpp b/server/src/client.cpp index 858b230..0990317 100644 --- a/server/src/client.cpp +++ b/server/src/client.cpp @@ -1,10 +1,35 @@ +/* + 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/>. + +*/ + #include "client.h" +#include "server_session.h" -client::client(std::string &client_auth_token) : auth_token(client_auth_token) +client::client(std::string &client_auth_token, server_session *sess) : auth_token(client_auth_token), session(sess) { //ctor } +void client::add_event_subscription(event_subscription_base* e) +{ +} + client::~client() { //dtor diff --git a/server/src/event_subscription_event.cpp b/server/src/event_subscription_event.cpp new file mode 100644 index 0000000..10ca824 --- /dev/null +++ b/server/src/event_subscription_event.cpp @@ -0,0 +1,32 @@ +/* + 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/>. + +*/ + + +#include "event_subscription_event.h" + +event_subscription_event::event_subscription_event(client_event_subscription_request *req) +{ + subtype = EVENT_SUBTYPE_EVENT; +} + +event_subscription_event::~event_subscription_event() +{ +} + diff --git a/server/src/event_subscription_repeated.cpp b/server/src/event_subscription_repeated.cpp new file mode 100644 index 0000000..13e0165 --- /dev/null +++ b/server/src/event_subscription_repeated.cpp @@ -0,0 +1,32 @@ +/* + 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/>. + +*/ + + +#include "event_subscription_repeated.h" + +event_subscription_repeated::event_subscription_repeated(client_event_subscription_request *req) +{ + subtype = EVENT_SUBTYPE_REPEATED; +} + +event_subscription_repeated::~event_subscription_repeated() +{ +} + diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp index 43d8837..113a756 100644 --- a/server/src/server_session.cpp +++ b/server/src/server_session.cpp @@ -27,6 +27,8 @@ #include "socket_wraper.h" #include "client.h" #include "modules_handler.h" +#include "event_subscription_event.h" +#include "event_subscription_repeated.h" extern std::map<std::string, client> clients; extern modules_handler *modules; @@ -280,7 +282,6 @@ bool server_session::handle_command(client_msg *msg) { server_msg m; m.set_type(SERVER_MSG_TYPE::SERVER_AUTH_REPLY); - //TODO: check for already existing auth token std::string server_password = runtime_config.config_file.get<std::string>("server.password", ""); if(server_password.empty()) m.mutable_auth_reply()->set_status(true); @@ -470,6 +471,7 @@ 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); + //TODO: fire event break; } } @@ -488,6 +490,10 @@ bool server_session::handle_command(client_msg *msg) { //TODO: handle error } + else + { + //TODO: fire event + } break; } } @@ -507,6 +513,10 @@ bool server_session::handle_command(client_msg *msg) { //TODO: handle error } + else + { + //TODO: fire event + } break; } } @@ -522,16 +532,44 @@ bool server_session::handle_command(client_msg *msg) 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())); + if(!dm->delete_download(i.download_id(), i.with_data())) { //TODO: handle error } + else + { + //TODO: fire event + } break; } } } } break; + case CLIENT_MSG_TYPE::CLIENT_SUBSCRIPTION_REQUEST: + { + for(auto i : msg->subscription_request()) + { + switch(i.mode()) + { + case SUBSCRIPTION_MODE::S_MODE_EVENT: + { + event_subscription_event *e = new event_subscription_event(&i); + client_->add_event_subscription(e); + } + break; + case SUBSCRIPTION_MODE::S_MODE_REPEATED: + { + event_subscription_repeated *e = new event_subscription_repeated(&i); + client_->add_event_subscription(e); + } + break; + default: + break; + } + } + } + break; default: return false; break; diff --git a/server/udm-server.project b/server/udm-server.project index 0c59c5a..723dbd4 100644 --- a/server/udm-server.project +++ b/server/udm-server.project @@ -28,6 +28,8 @@ <File Name="src/server.cpp"/> <File Name="src/server_session.cpp"/> <File Name="src/utilities.cpp"/> + <File Name="src/event_subscription_event.cpp"/> + <File Name="src/event_subscription_repeated.cpp"/> </VirtualDirectory> <VirtualDirectory Name="include"> <File Name="../protocol/udm.pb.h"/> @@ -45,6 +47,9 @@ <File Name="include/server_session.h"/> <File Name="include/socket_wraper.h"/> <File Name="include/utilities.h"/> + <File Name="include/event_subscription_base.h"/> + <File Name="include/event_subscription_event.h"/> + <File Name="include/event_subscription_repeated.h"/> </VirtualDirectory> <Dependencies Name="Debug"/> <VirtualDirectory Name="protocol"> |