summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/messagehandler.cc31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index 18d5fed..3065e60 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -31,13 +31,17 @@
// Defines global task_manager object
#include "taskmanager.h"
+#include "messageparser.h"
+
MessageList handle_msg(MessageList msgList, clientid_t wsi) {
+ MessageList outmsgs;
+
MessageList::iterator it;
for(it = msgList.begin();
it != msgList.end();
it++) {
- message_t m = *it;
+ message_t &m = *it;
switch(m.cmd) {
case cmd::add:
@@ -47,41 +51,53 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
t.title = m.add.title;
t.desc = m.add.desc;
try {
- it->nodes = task_manager.addTask(t, m.add.parentid);
+ m.nodes = task_manager.addTask(t, m.add.parentid);
+ outmsgs.push_back(m);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error adding task\n");
}
}
break;
+
case cmd::del:
{
INFO(messagehandler, "Handling del command\n");
try {
- it->nodes = task_manager.deleteTask(m.del.id);
+ m.nodes = task_manager.deleteTask(m.del.id);
+ outmsgs.push_back(m);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error deleting task\n");
}
}
break;
+
case cmd::move:
{
INFO(messagehandler, "Handling move command\n");
try {
- it->nodes = task_manager.moveTask(m.move.id, m.move.parentid);
+ m.nodes = task_manager.moveTask(m.move.id, m.move.parentid);
+ outmsgs.push_back(m);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error moving task\n");
}
}
break;
+
case cmd::observe:
- connection_handler.observe(wsi, m.observe.id);
+ {
+ connection_handler.observe(wsi, m.observe.id);
+ outmsgs.push_back(m);
+ }
break;
+
case cmd::unobserve:
connection_handler.unobserve(wsi, m.observe.id);
+ outmsgs.push_back(m);
break;
+
case cmd::update:
{
INFO(messagehandler, "Handling update command\n");
@@ -89,7 +105,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
task_t t;
t.title = m.update.title;
t.desc = m.update.desc;
- it->nodes = task_manager.updateTask(m.update.id, t);
+ m.nodes = task_manager.updateTask(m.update.id, t);
+ outmsgs.push_back(m);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error updating task\n");
@@ -104,7 +121,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
printf("%d affected nodes registered\n", m.nodes.size());
}
- return msgList;
+ return outmsgs;
}
#ifdef TEST_MSGHANDLER