summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client-qt/udm-client-qt/udm_main.cpp1
-rw-r--r--protocol/events.proto25
-rw-r--r--protocol/udm.proto8
-rw-r--r--server/include/api_module_base.h2
-rw-r--r--server/include/client.h30
-rw-r--r--server/include/event_subscription_base.h42
-rw-r--r--server/include/event_subscription_event.h35
-rw-r--r--server/include/event_subscription_repeated.h38
-rw-r--r--server/modules/downloaders/curl/main.cpp6
-rw-r--r--server/modules/metadata/flat_files/main.cpp4
-rw-r--r--server/src/client.cpp27
-rw-r--r--server/src/event_subscription_event.cpp32
-rw-r--r--server/src/event_subscription_repeated.cpp32
-rw-r--r--server/src/server_session.cpp42
-rw-r--r--server/udm-server.project5
15 files changed, 299 insertions, 30 deletions
diff --git a/client-qt/udm-client-qt/udm_main.cpp b/client-qt/udm-client-qt/udm_main.cpp
index 62b8195..3b546c3 100644
--- a/client-qt/udm-client-qt/udm_main.cpp
+++ b/client-qt/udm-client-qt/udm_main.cpp
@@ -258,6 +258,7 @@ void udm_main::server_message_received(server_msg msg)
auth_token = msg.auth_reply().auth_token();
btn_add->setEnabled(true); //we can add downloads now
lbl_state->setText(tr("State") + ": " + tr("Connected") + ", " + tr("Authenticated"));
+ //TODO: subscript to events
//request modules and settings here
{
client_msg msg;
diff --git a/protocol/events.proto b/protocol/events.proto
index f543577..9b3d676 100644
--- a/protocol/events.proto
+++ b/protocol/events.proto
@@ -20,12 +20,8 @@
import "ui.proto";
-//TODO: extended ui updates subscriptions proto part (ui data messages on timer, e.t.c.)
-
-// event subscription part begin
//TODO: rework
-//TODO: download state chage events
message subscription_download_ui_info {
@@ -49,6 +45,11 @@ enum SUBSCRIPTION_TYPE {
S_DOWNLOAD_DELETED = 4;
}
+enum SUBSCRIPTION_MODE {
+ S_MODE_EVENT = 0;
+ S_MODE_REPEATED = 1;
+}
+
//download state subscription for download state changes (can be module defined)
enum SUBSCRIPTION_DOWNLOAD_STATE {
S_D_STARTED = 0;
@@ -56,15 +57,18 @@ enum SUBSCRIPTION_DOWNLOAD_STATE {
}
message subscription_download_state_change {
- repeated SUBSCRIPTION_DOWNLOAD_STATE states = 1;
+ repeated SUBSCRIPTION_DOWNLOAD_STATE states = 1; //list of states on which event should be sent
}
//information about subscription request
message client_event_subscription_request {
required SUBSCRIPTION_TYPE type = 1; //type must be set
- required string module_name = 2; //module name must be set, can be "" for all installed modules supported subscription type
- optional subscription_download_ui_info download_ui_info = 3;
- optional subscription_download_state_change download_state_change = 4;
+ required SUBSCRIPTION_MODE mode = 2; //mode must be set
+ required string module_name = 3; //module name must be set, can be "" for all installed modules supported subscription type
+ optional int64 interval = 4 [default = 5000]; //event fire interval in milliseconds, valid for repeated event mode
+ optional bool one_time = 5 [default = false]; //is event should fire only once ?
+ optional subscription_download_ui_info download_ui_info = 6;
+ optional subscription_download_state_change download_state_change = 7;
}
@@ -73,8 +77,8 @@ message client_event_subscription_request {
//1. can be customized to unsubscript from few aubscriptions at once
message client_event_unsubscription_request {
- required SUBSCRIPTION_TYPE type = 1;
- required string module_name = 2;
+ required SUBSCRIPTION_TYPE type = 1; //type must be set
+ required string module_name = 2; //module name must be set, can be "" for all installed modules supported subscription type
optional unsubscription_download_ui_info ui_info = 3;
optional subscription_download_state_change download_state_change = 4; //reusing defined structure to avoid code duplication
}
@@ -104,4 +108,3 @@ message server_event_unsubscription_reply {
optional int32 subscription_id = 1002;
}
-//event subscription part end
diff --git a/protocol/udm.proto b/protocol/udm.proto
index 4b0fa34..d80e1f0 100644
--- a/protocol/udm.proto
+++ b/protocol/udm.proto
@@ -23,8 +23,8 @@
import "ui.proto";
import "events.proto";
import "download.proto";
-import "misc.proto";
-import "settings.proto";
+//import "misc.proto";
+//import "settings.proto";
import "module.proto";
import "auth.proto";
import "core.proto";
@@ -54,8 +54,8 @@ enum CLIENT_MSG_TYPE {
CLIENT_UI_DATA_REQUEST = 2;
CLIENT_MODULES_REQUEST = 3;
CLIENT_CORE_INFO_REQUEST = 4;
- CLIENT_SUBSCRIPTIONS_REQUEST = 5;
- CLIENT_UNSUBSCRIPTIONS_REQUEST = 6;
+ CLIENT_SUBSCRIPTION_REQUEST = 5;
+ CLIENT_UNSUBSCRIPTION_REQUEST = 6;
CLIENT_DOWNLOADS_LIST_REQUEST = 7;
CLIENT_DOWNLOAD_ADD = 8;
CLIENT_DOWNLOAD_START = 9;
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">