summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-10-27 05:44:22 +0300
committerGluzskiy Alexandr <sss@sss.chaoslab.ru>2015-10-27 05:44:22 +0300
commit3d2c1d3c24e40573e391040048ff734cd052c295 (patch)
treef5b72764a4431841b996df8540664b5167a6eed4
parent89dbfd1a2e9cee5bb7c219ba121e7e922d7dfa7a (diff)
protocol:
tiny enum value names correction server: event subscription subsystem: a bit of implementation of repeated event type
-rw-r--r--protocol/events.proto18
-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
8 files changed, 59 insertions, 21 deletions
diff --git a/protocol/events.proto b/protocol/events.proto
index 9b3d676..553ada5 100644
--- a/protocol/events.proto
+++ b/protocol/events.proto
@@ -38,22 +38,22 @@ message unsubscription_download_ui_info {
//subscription type
enum SUBSCRIPTION_TYPE {
- S_UI_CHANGE = 0;
- S_SETTING_CHANGE = 1;
- S_DOWNLOAD_STATE_CHANGE = 2;
- S_DOWNLOAD_ADDED = 3;
- S_DOWNLOAD_DELETED = 4;
+ ST_UI_CHANGE = 0;
+ ST_SETTING_CHANGE = 1;
+ ST_DOWNLOAD_STATE_CHANGE = 2;
+ ST_DOWNLOAD_ADDED = 3;
+ ST_DOWNLOAD_DELETED = 4;
}
enum SUBSCRIPTION_MODE {
- S_MODE_EVENT = 0;
- S_MODE_REPEATED = 1;
+ SM_EVENT = 0;
+ SM_REPEATED = 1;
}
//download state subscription for download state changes (can be module defined)
enum SUBSCRIPTION_DOWNLOAD_STATE {
- S_D_STARTED = 0;
- S_D_STOPPED = 1;
+ SDS_STARTED = 0;
+ SDS_STOPPED = 1;
}
message subscription_download_state_change {
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);