summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/include/client.h2
-rw-r--r--server/include/event_subscription_base.h9
-rw-r--r--server/include/event_subscription_repeated.h9
-rw-r--r--server/src/event_subscription_event.cpp2
-rw-r--r--server/src/event_subscription_repeated.cpp33
-rw-r--r--server/src/main.cpp3
-rw-r--r--server/src/server_session.cpp4
7 files changed, 50 insertions, 12 deletions
diff --git a/server/include/client.h b/server/include/client.h
index d6668a3..239ae4b 100644
--- a/server/include/client.h
+++ b/server/include/client.h
@@ -37,7 +37,7 @@ class client
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: store sessions ptr
//TODO: some way to call core and mopdules api from here
std::string auth_token;
server_session *session;
diff --git a/server/include/event_subscription_base.h b/server/include/event_subscription_base.h
index 19b184f..0e5b790 100644
--- a/server/include/event_subscription_base.h
+++ b/server/include/event_subscription_base.h
@@ -33,10 +33,13 @@ enum EVENT_SUBTYPE {
class event_subscription_base
{
public:
- event_subscription_base(){};
- virtual ~event_subscription_base(){};
+ event_subscription_base(client_event_subscription_request *req)
+ {
+ subscription_request = *req;
+ }
+ virtual ~event_subscription_base(){}
protected:
- SUBSCRIPTION_TYPE type = SUBSCRIPTION_TYPE::S_DOWNLOAD_STATE_CHANGE;
EVENT_SUBTYPE subtype = EVENT_SUBTYPE::EVENT_SUBTYPE_EVENT;
+ client_event_subscription_request subscription_request;
};
#endif // EVENT_SUBSCRIPTION_H
diff --git a/server/include/event_subscription_repeated.h b/server/include/event_subscription_repeated.h
index bb676a3..3b2936b 100644
--- a/server/include/event_subscription_repeated.h
+++ b/server/include/event_subscription_repeated.h
@@ -23,16 +23,19 @@
#define EVENT_SUBSCRIPTION_PERIODIC_H
#include "event_subscription_base.h"
+#include <boost/asio.hpp>
+
+typedef boost::asio::basic_deadline_timer<boost::posix_time::ptime> deadline_timer;
class event_subscription_repeated : public event_subscription_base
{
public:
event_subscription_repeated(client_event_subscription_request *req);
~event_subscription_repeated();
+
+ void timer_handler(const boost::system::error_code &e);
private:
- bool one_time;
- int64_t interval;
-
+ deadline_timer *timer;
};
#endif // EVENT_SUBSCRIPTION_PERIODIC_H
diff --git a/server/src/event_subscription_event.cpp b/server/src/event_subscription_event.cpp
index 10ca824..f209f67 100644
--- a/server/src/event_subscription_event.cpp
+++ b/server/src/event_subscription_event.cpp
@@ -21,7 +21,7 @@
#include "event_subscription_event.h"
-event_subscription_event::event_subscription_event(client_event_subscription_request *req)
+event_subscription_event::event_subscription_event(client_event_subscription_request *req) : event_subscription_base(req)
{
subtype = EVENT_SUBTYPE_EVENT;
}
diff --git a/server/src/event_subscription_repeated.cpp b/server/src/event_subscription_repeated.cpp
index 13e0165..bc41f7a 100644
--- a/server/src/event_subscription_repeated.cpp
+++ b/server/src/event_subscription_repeated.cpp
@@ -20,13 +20,44 @@
#include "event_subscription_repeated.h"
+#include <boost/bind.hpp>
-event_subscription_repeated::event_subscription_repeated(client_event_subscription_request *req)
+extern boost::asio::io_service io_service_server;
+
+
+event_subscription_repeated::event_subscription_repeated(client_event_subscription_request *req) : event_subscription_base(req)
{
subtype = EVENT_SUBTYPE_REPEATED;
+ timer = new deadline_timer(io_service_server, boost::posix_time::milliseconds(req->interval()));
+ timer->async_wait(boost::bind(&event_subscription_repeated::timer_handler, this, _1));
}
event_subscription_repeated::~event_subscription_repeated()
{
+ delete timer;
}
+
+void event_subscription_repeated::timer_handler(const boost::system::error_code &e)
+{
+ if(!e)
+ {
+ //TODO: fire event
+ if(!subscription_request.one_time())
+ {
+ timer->expires_from_now(boost::posix_time::milliseconds(subscription_request.interval()));
+ timer->async_wait(boost::bind(&event_subscription_repeated::timer_handler, this, _1));
+ }
+ else
+ {
+ //TODO: remove entry from events subscription list in client object
+ delete this;
+ }
+ }
+ else
+ {
+ //TODO: handle error
+ //TODO: remove entry from events subscription list in client object
+ delete this;
+ }
+}
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 214b6b5..5ca4422 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -75,6 +75,8 @@ void sig_handler(int sig)
}
}
+boost::asio::io_service io_service_server;
+
extern "C" int main(int argc, char *argv[])
{
//handle signals
@@ -248,7 +250,6 @@ extern "C" int main(int argc, char *argv[])
{
//TODO: fork here
}
- boost::asio::io_service io_service_server;
try{
//TODO: server options ip address, interface name
serv = new server(io_service_server, runtime_config, clients, downloads, runtime_config.config_file.get<int>("server.port", 6613));
diff --git a/server/src/server_session.cpp b/server/src/server_session.cpp
index 113a756..cc08b18 100644
--- a/server/src/server_session.cpp
+++ b/server/src/server_session.cpp
@@ -552,13 +552,13 @@ bool server_session::handle_command(client_msg *msg)
{
switch(i.mode())
{
- case SUBSCRIPTION_MODE::S_MODE_EVENT:
+ case SUBSCRIPTION_MODE::SM_EVENT:
{
event_subscription_event *e = new event_subscription_event(&i);
client_->add_event_subscription(e);
}
break;
- case SUBSCRIPTION_MODE::S_MODE_REPEATED:
+ case SUBSCRIPTION_MODE::SM_REPEATED:
{
event_subscription_repeated *e = new event_subscription_repeated(&i);
client_->add_event_subscription(e);