summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/messagehandler.cc47
-rw-r--r--src/messageparser.cc8
-rw-r--r--src/messageparser.h1
-rw-r--r--src/munia_proto.cc53
-rw-r--r--src/taskmanager.cc19
-rw-r--r--src/taskmanager.h5
-rw-r--r--src/tasktree.cc3
-rw-r--r--src/tasktree.h2
8 files changed, 120 insertions, 18 deletions
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index cdc7246..a394f08 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -86,8 +86,51 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
{
INFO(messagehandler, "Handling move command\n");
try {
- m.nodes = task_manager.moveTask(m.move.id, m.move.parentid);
- outmsgs.push_back(m);
+ task_t removetask = task_manager.task(m.move.id);
+ TaskIdListPair tilpair = task_manager.moveTask(m.move.id, m.move.parentid);
+ task_t createtask = task_manager.task(m.move.id);
+
+ /*
+ TaskIdList commonAncestors;
+ TaskIdList removeAncestors;
+ TaskIdList createAncestors;
+
+ // find command ancestors and fill ancestors for remove command
+ for(TaskIdList::iterator it_remove = tilpair.first.begin();
+ it_remove != tilpair.first.end(); it_remove++) {
+ taskid_t removeid = *it;
+ bool common = false;
+ for(TaskIdList::iterator it_create = tilpair.second.begin();
+ it_create = != tilpair.second.end(); it_create++) {
+ taskid_t createid = *id;
+ if(removeid == createid) {
+ commandAncestors.push_back(removeid);
+ common = true;
+ }
+ }
+ if(!common) {
+ removeAncestors.push_back(removeid);
+ }
+ }
+
+ // fill ancestors for create command
+ for(TaskIdList::iterator it_create = tilpair.second.begin();
+ it_create = != tilpair.second.end(); it_create++) {
+ taskid_t createid = *id;
+ if(removeid == createid) {
+ commandAncestors.push_back(removeid);
+ common = true;
+ }
+ }
+ */
+
+ message_t removemsg = create_msg_remove(removetask);
+ removemsg.nodes = tilpair.first;
+ message_t createmsg = create_msg_create(createtask);
+ createmsg.nodes = tilpair.second;
+
+ outmsgs.push_back(removemsg);
+ outmsgs.push_back(createmsg);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error moving task\n");
diff --git a/src/messageparser.cc b/src/messageparser.cc
index 804eb12..62923be 100644
--- a/src/messageparser.cc
+++ b/src/messageparser.cc
@@ -245,6 +245,14 @@ message_t create_msg_remove(task_t t) {
return m;
}
+message_t create_msg_move(taskid_t id, taskid_t to) {
+ message_t m;
+ m.cmd = cmd::move;
+ m.move.id = id;
+ m.move.parentid = to;
+ return m;
+}
+
#ifdef TEST_MSGPARSER
//Additional dependency files
//deps:
diff --git a/src/messageparser.h b/src/messageparser.h
index 6ebac3e..11b11cb 100644
--- a/src/messageparser.h
+++ b/src/messageparser.h
@@ -38,5 +38,6 @@ std::string msg_tostring(message_t msg);
message_t create_msg_create(task_t task);
message_t create_msg_update(task_t task);
message_t create_msg_remove(task_t task);
+message_t create_msg_move(taskid_t id, taskid_t to);
#endif/*__MUNIA_MESSAGEPARSER_H__*/
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index d9b068f..3022042 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -147,30 +147,62 @@ int callback_lws_task(struct libwebsocket_context * context,
std::string msgstr;
msgstr.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' ');
+ int c = 0;
+ message_t prevmsg;
+ std::queue<message_t> messages;
while(msgqueue[wsi].size() > 0) {
message_t msg = msgqueue[wsi].front();
msgqueue[wsi].pop();
+
+ //Rewriting delete id followed by create id to move to_id from_id
+ // look at previous message from create commands
+ if(c > 0 && // look backward (skip first entry)
+ msg.cmd == cmd::create && // look from create commands
+ prevmsg.cmd == cmd::remove && // if previous msg is a remove command
+ msg.create.id == prevmsg.remove.id) { // and commands have same id
+
+ printf("\tprevmsg: %s, msg: %s\n", msg_tostring(prevmsg).c_str(),
+ msg_tostring(msg).c_str());
+ message_t movemsg = create_msg_move(msg.create.id, msg.create.parentid);
+ msg = movemsg;
+ }
+ else if(c > 0) {
+ messages.push(prevmsg);
+ }
+
+ prevmsg = msg;
+ c++;
+ }
+ if(c > 0) { // Push last msg
+ messages.push(prevmsg);
+ }
+
+ // create msg string
+ // while(msgqueue[wsi].size() > 0) {
+ while(messages.size() > 0) {
+ message_t msg = messages.front();
+ messages.pop();
char buf[32];
sprintf(buf, "%d", msg.tid);
+ printf("msg: %s\n", msg_tostring(msg).c_str());
if(msgstr.size() > LWS_SEND_BUFFER_PRE_PADDING) msgstr += " ";
msgstr += std::string(buf) + " " + msg_tostring(msg);
}
msgstr.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' ');
-
+
int n = libwebsocket_write(wsi, (unsigned char *)
- msgstr.c_str() +
- LWS_SEND_BUFFER_PRE_PADDING,
- msgstr.length() -
- LWS_SEND_BUFFER_POST_PADDING -
- LWS_SEND_BUFFER_PRE_PADDING,
- LWS_WRITE_TEXT);
+ msgstr.c_str() +
+ LWS_SEND_BUFFER_PRE_PADDING,
+ msgstr.length() -
+ LWS_SEND_BUFFER_POST_PADDING -
+ LWS_SEND_BUFFER_PRE_PADDING,
+ LWS_WRITE_TEXT);
if(n < 0) {
fprintf(stderr, "ERROR writing to socket");
exit(1);
- }
- }
-
+ } }
+
break;
/*
@@ -228,7 +260,6 @@ int callback_lws_task(struct libwebsocket_context * context,
id++;
}
-
} else {
printf("%d nodes affected by command\n", omi->nodes.size());
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 87cf2b0..89de0b3 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -82,10 +82,12 @@ taskid_t TaskManager::createId() {
return idCount++;
}
-TaskIdList TaskManager::moveTask(taskid_t id, taskid_t to)
+TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
throw (std::exception) {
- if(isProtected(id)) return TaskIdList();
+ if(isProtected(id)) return TaskIdListPair();
+
+ /*
TaskIdList affectedTasks;
@@ -95,8 +97,19 @@ TaskIdList TaskManager::moveTask(taskid_t id, taskid_t to)
catch (std::exception& e) {
throw e;
}
+ */
- return affectedTasks;
+ task_t t = tree.data(id);
+ t.parentid = to;
+
+ TaskIdList tilremove = tree.remove(id);
+ TaskIdList tilcreate = tree.insertAsChild(to, id, t);
+
+ TaskIdListPair tilpair;
+ tilpair.first = tilremove;
+ tilpair.second = tilcreate;
+
+ return tilpair;
}
TaskIdList TaskManager::removeTask(taskid_t id)
diff --git a/src/taskmanager.h b/src/taskmanager.h
index dc0cf1c..0f0d96e 100644
--- a/src/taskmanager.h
+++ b/src/taskmanager.h
@@ -36,6 +36,8 @@
#include "task.h"
#include "tasktree.h"
+typedef std::pair<TaskIdList, TaskIdList> TaskIdListPair;
+
class TaskManager {
public:
TaskManager();
@@ -44,7 +46,8 @@ public:
TaskIdList createTask(taskid_t parentid, taskid_t *id) throw (std::exception);
TaskIdList updateTask(taskid_t id, task_t task) throw (std::exception);
TaskIdList removeTask(taskid_t id) throw (std::exception);
- TaskIdList moveTask(taskid_t id, taskid_t newParent) throw (std::exception);
+
+ TaskIdListPair moveTask(taskid_t id, taskid_t newParent) throw (std::exception);
TaskIdList subTasks(taskid_t) throw (std::exception);
diff --git a/src/tasktree.cc b/src/tasktree.cc
index fc84efa..5c58e3c 100644
--- a/src/tasktree.cc
+++ b/src/tasktree.cc
@@ -124,6 +124,7 @@ TaskIdList TaskTree::remove(taskid_t id)
return affectedNodes;
}
+/*
TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
throw (std::exception)
{
@@ -156,7 +157,9 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
return affectedNodes;
}
+*/
+
TaskIdList TaskTree::updateData(taskid_t id, task_t t)
throw (std::exception)
{
diff --git a/src/tasktree.h b/src/tasktree.h
index d82b9a4..41a29be 100644
--- a/src/tasktree.h
+++ b/src/tasktree.h
@@ -52,7 +52,7 @@ public:
TaskIdList insertAsChild(taskid_t parentid, taskid_t id, task_t data) throw (std::exception);
TaskIdList remove(taskid_t id) throw (std::exception);
- TaskIdList move(taskid_t id, taskid_t newParentId) throw (std::exception);
+ // TaskIdList move(taskid_t id, taskid_t newParentId) throw (std::exception);
TaskIdList updateData(taskid_t id, task_t t) throw (std::exception);
task_t data(taskid_t id) throw (std::exception);