summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/client.cpp5
-rw-r--r--server/src/server_session.cpp35
2 files changed, 36 insertions, 4 deletions
diff --git a/server/src/client.cpp b/server/src/client.cpp
index 0990317..fdfd513 100644
--- a/server/src/client.cpp
+++ b/server/src/client.cpp
@@ -29,7 +29,10 @@ client::client(std::string &client_auth_token, server_session *sess) : auth_toke
void client::add_event_subscription(event_subscription_base* e)
{
}
-
+const std::list<event_subscription_base*>& client::get_subscriptions()
+{
+ return subscriptions;
+}
client::~client()
{
//dtor
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp
index cc08b18..5287900 100644
--- a/server/src/server_session.cpp
+++ b/server/src/server_session.cpp
@@ -22,7 +22,7 @@
#include <boost/bind.hpp>
#include <boost/log/trivial.hpp>
#include "server_session.h"
-#include "../../protocol/udm.pb.h"
+
#include "utilities.h"
#include "socket_wraper.h"
#include "client.h"
@@ -470,8 +470,8 @@ bool server_session::handle_command(client_msg *msg)
d->set_state(dl.state);
d->set_module_name(msg->download_add_request().module_name());
d->set_downloaded(dl.downloaded);
- send_message(&m);
- //TODO: fire event
+ //TODO: fill event with info ?
+ fire_event(SUBSCRIPTION_TYPE::ST_DOWNLOAD_ADDED, m);
break;
}
}
@@ -488,10 +488,12 @@ bool server_session::handle_command(client_msg *msg)
auto dm = static_cast<module_downloader *>(m);
if(!dm->start_download(i.download_id()))
{
+
//TODO: handle error
}
else
{
+ //fire_event(SUBSCRIPTION_TYPE::);
//TODO: fire event
}
break;
@@ -634,6 +636,33 @@ void server_session::handle_write(const boost::system::error_code& error)
// boost::asio::async_read(socket_, boost::asio::buffer(recv_data_, 4), boost::bind(&server_session::handle_read, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
+bool operator==(event_subscription_base* const e, const SUBSCRIPTION_TYPE t)
+{
+ return *e == t;
+}
+
+
+void server_session::fire_event(SUBSCRIPTION_TYPE type, server_msg &msg)
+{
+ for(auto i : clients)
+ {
+ for(auto s = std::find(i.second->get_subscriptions().begin(), i.second->get_subscriptions().end(), type); s != i.second->get_subscriptions().end(); s = std::find(s, i.second->get_subscriptions().end(), type))
+ {
+ if((*s)->get_subtype() != EVENT_SUBTYPE::EVENT_SUBTYPE_EVENT)
+ continue;
+ switch(type)
+ {
+ case SUBSCRIPTION_TYPE::ST_DOWNLOAD_ADDED:
+ {
+ send_message(&msg);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+}
server_session::~server_session()
{