From 6706acbad07cf543499d59897d20642cdf894f72 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 14:05:24 +0200 Subject: Fixed missing semicolon and whitespace --- src/testclient.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/testclient.cc b/src/testclient.cc index 26dc572..c0c5797 100644 --- a/src/testclient.cc +++ b/src/testclient.cc @@ -183,8 +183,8 @@ int client(const char *address, int port, struct test tests[]) } TEST_BEGIN; -#define BASE "0 create 0 -1;0 update 0 \"root\"; 0 create 1 0; 0 update 1 \"Finished\"; 0 create 2 0; 0 update 2 \"Backlog\"; 0 create 3 0; 0 update 3 \"Lost+Found\"; 0 create 4 0; 0 update 4 \"Projects\"" -#define RMBASE "0 remove 4; 0 remove 3; 0 remove 2; 0 remove 1; 0 remove 0" +#define BASE "0 create 0 -1; 0 update 0 \"root\"; 0 create 1 0; 0 update 1 \"Finished\"; 0 create 2 0; 0 update 2 \"Backlog\"; 0 create 3 0; 0 update 3 \"Lost+Found\"; 0 create 4 0; 0 update 4 \"Projects\";" +#define RMBASE "0 remove 4; 0 remove 3; 0 remove 2; 0 remove 1; 0 remove 0;" static struct test tests[] = { { "observe 0", BASE, false }, -- cgit v1.2.3 From e9ac50851f3dd18c0d9cf30e1686f5cc7a193b0d Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 14:06:02 +0200 Subject: Setting parentid in create update msg --- src/messageparser.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/messageparser.cc b/src/messageparser.cc index b3fc173..804eb12 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -226,6 +226,7 @@ message_t create_msg_create(task_t t) { message_t m; m.cmd = cmd::create; m.create.id = t.id; + m.create.parentid = t.parentid; return m; } -- cgit v1.2.3 From 71f15b9dd59ee21983c00b9e74c2a1e100e02fb8 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 14:06:29 +0200 Subject: Setting correct observe id on messages. --- src/munia_proto.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/munia_proto.cc b/src/munia_proto.cc index 36c6e5c..d9b068f 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -203,23 +203,27 @@ int callback_lws_task(struct libwebsocket_context * context, TaskIdList::iterator id = ids.begin(); while(id != ids.end()) { task_t task = task_manager.task(*id); - + message_t createmsg = create_msg_create(task); + createmsg.tid = omi->observe.id; message_t updatemsg = create_msg_update(task); + updatemsg.tid = omi->observe.id; + msgqueue[wsi].push(createmsg); msgqueue[wsi].push(updatemsg); - + id++; } } else if(omi->cmd == cmd::unobserve) { TaskIdList ids = task_manager.subTasks(omi->observe.id); - TaskIdList::iterator id = ids.begin(); - while(id != ids.end()) { + TaskIdList::reverse_iterator id = ids.rbegin(); + while(id != ids.rend()) { task_t task = task_manager.task(*id); message_t removemsg = create_msg_remove(task); + removemsg.tid = omi->observe.id; msgqueue[wsi].push(removemsg); id++; @@ -236,6 +240,8 @@ int callback_lws_task(struct libwebsocket_context * context, clientid_t clientid = (*ci).first; taskid_t tid = (*ci).second; + printf("Observer id of task: %d\n", tid); + message_t msg = *omi; msg.tid = tid; -- cgit v1.2.3 From 8a231b1dc00d29026cded3938c5d5f95829146e1 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 14:06:44 +0200 Subject: Added parentid as field --- src/task.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/task.h b/src/task.h index e95b9ea..840e657 100644 --- a/src/task.h +++ b/src/task.h @@ -36,7 +36,7 @@ typedef std::list TaskIdList; typedef struct { taskid_t id; -// int parentid; + taskid_t parentid; std::string title; std::string desc; } task_t; -- cgit v1.2.3 From f4595145308e24e3f6edcbaa2e30ee05fc90fd55 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 14:07:49 +0200 Subject: Renamed getData to data and setting correct parentid --- src/tasktree.cc | 96 ++++++++++++++++++++++++++++++++------------------------- src/tasktree.h | 2 +- 2 files changed, 55 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/tasktree.cc b/src/tasktree.cc index d652eae..4d6099e 100644 --- a/src/tasktree.cc +++ b/src/tasktree.cc @@ -29,6 +29,8 @@ #include "debug.h" +#define ROOT_PARENT_ID -1 + static void concatTaskIdLists(TaskIdList& pre, TaskIdList& post) { pre.insert(pre.end(), post.begin(), post.end()); // for(TaskIdList::iterator it = post.begin(); @@ -45,47 +47,48 @@ TaskTree::~TaskTree() { // cleanup tree } +static taskid_t rootid = -1; + TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data) - throw (std::exception) { + throw (std::exception) +{ TaskIdList affectedNodes; // Initialize if(!root) { + rootid = id; node_t* node = createNode(id); root = node; node->data = data; - affectedNodes.push_back(id); - - goto finish; - } - try { - node_t* parent = id2node.at(parentid); - node_t* child = createNode(id); - child->data = data; - insertChild(parent, child); + } else { - // affectedNodes.push_back(parentid); - affectedNodes.push_back(id); - TaskIdList ancestors = ancestorList(id); - concatTaskIdLists(affectedNodes, ancestors); - - goto finish; - } - catch(std::exception& e) { - throw e; + try { + node_t* parent = id2node.at(parentid); + node_t* child = createNode(id); + child->data = data; + insertChild(parent, child); + + // affectedNodes.push_back(parentid); + affectedNodes.push_back(id); + TaskIdList ancestors = ancestorList(id); + concatTaskIdLists(affectedNodes, ancestors); + } + catch(std::exception& e) { + throw e; + } } - - finish: - printf("Child %d added to %d, affecting %d nodes\n", - id, parentid, affectedNodes.size()); + +// printf("Child %d added to %d, affecting %d nodes\n", +// id, parentid, affectedNodes.size()); return affectedNodes; } TaskIdList TaskTree::remove(taskid_t id) - throw (std::exception) { + throw (std::exception) +{ //todo: move all childrin to lost+found WARN(tasktree, "Feature not implemneted yet\n"); TaskIdList affectedNodes; @@ -105,14 +108,15 @@ TaskIdList TaskTree::remove(taskid_t id) } TaskIdList TaskTree::move(taskid_t id, taskid_t toid) - throw (std::exception) { + throw (std::exception) +{ TaskIdList affectedNodes; try { node_t* child = id2node.at(id); node_t* newparent = id2node.at(toid); - + if(!child->parent) { throw std::exception(); } @@ -126,19 +130,17 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid) concatTaskIdLists(affectedNodes, ancestors); affectedNodes.push_back(toid); ancestors = ancestorList(toid); - - goto finish; } catch(std::exception& e) { throw e; } - - finish: + return affectedNodes; } TaskIdList TaskTree::updateData(taskid_t id, task_t t) - throw (std::exception) { + throw (std::exception) +{ TaskIdList affectedNodes; @@ -149,37 +151,41 @@ TaskIdList TaskTree::updateData(taskid_t id, task_t t) affectedNodes.push_back(id); TaskIdList ancestors = ancestorList(id); concatTaskIdLists(affectedNodes, ancestors); - goto finish; } catch(std::exception& e) { throw e; } - finish: return affectedNodes; } -task_t TaskTree::getData(taskid_t id) - throw (std::exception) { +task_t TaskTree::data(taskid_t id) + throw (std::exception) +{ task_t t; try { node_t* node = id2node.at(id); t = node->data; - goto finish; + t.id = node->id; + if(node->parent) t.parentid = node->parent->id; + else { + if(t.id != rootid) throw std::exception(); + t.parentid = -1; + } } catch(std::exception& e) { throw e; } - - finish: + return t; } // bfs search from id in tree TaskIdList TaskTree::bfs(taskid_t id) - throw (std::exception) { + throw (std::exception) +{ TaskIdList lst; lst.push_back(id); @@ -207,7 +213,8 @@ TaskIdList TaskTree::bfs(taskid_t id) } TaskIdList TaskTree::ancestorList(taskid_t id) - throw (std::exception) { + throw (std::exception) +{ TaskIdList ancestors; @@ -217,13 +224,11 @@ TaskIdList TaskTree::ancestorList(taskid_t id) ancestors.push_back(current->parent->id); current = current->parent; } - goto finish; } catch(std::exception& e) { throw e; } - finish: printf("Collected %d ancestors to %u\n", ancestors.size(), id); for(TaskIdList::iterator it = ancestors.begin(); it != ancestors.end(); it++) { @@ -288,21 +293,28 @@ TaskTree tree; task_t t; t.title = "root"; +t.id = ROOT_ID; tree.insertAsChild(0, ROOT_ID, t); t.title = "Finished"; +t.id = FINISHED_ID; tree.insertAsChild(ROOT_ID, FINISHED_ID, t); t.title = "Backlog"; +t.id = BACKLOG_ID; tree.insertAsChild(ROOT_ID, BACKLOG_ID, t); t.title = "Lost+Found"; +t.id = LOSTFOUND_ID; tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t); t.title = "Projects"; +t.id = PROJECTS_ID; tree.insertAsChild(ROOT_ID, PROJECTS_ID, t); TEST_EQUAL_INT(5, tree.bfs(0).size(), "Testing BFS function"); +TEST_EQUAL_INT(PROJECTS_ID, tree.data(PROJECTS_ID).id, "Testing project id"); +TEST_EQUAL_INT(ROOT_ID, tree.data(ROOT_ID).id, "Testing root id"); TEST_END; diff --git a/src/tasktree.h b/src/tasktree.h index aeeddfc..d82b9a4 100644 --- a/src/tasktree.h +++ b/src/tasktree.h @@ -54,7 +54,7 @@ public: TaskIdList remove(taskid_t id) 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 getData(taskid_t id) throw (std::exception); + task_t data(taskid_t id) throw (std::exception); TaskIdList bfs(taskid_t id) throw (std::exception); -- cgit v1.2.3