summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-05-04 14:08:58 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-05-04 14:08:58 +0200
commitb4af14f4c3a4fee50dd8ac2c61d2eb79fb648403 (patch)
treece8a0e20b2e24043a3dd2e011956d1bb8d364b3b
parent37135daaaba2ee1945cb1b1163ddd68127b65b1e (diff)
parentf4595145308e24e3f6edcbaa2e30ee05fc90fd55 (diff)
Merge branch 'master' of https://git.oftal.dk/munia
-rw-r--r--src/messageparser.cc1
-rw-r--r--src/munia_proto.cc14
-rw-r--r--src/task.h2
-rw-r--r--src/tasktree.cc96
-rw-r--r--src/tasktree.h2
-rw-r--r--src/testclient.cc4
6 files changed, 69 insertions, 50 deletions
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;
}
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;
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<taskid_t> TaskIdList;
typedef struct {
taskid_t id;
-// int parentid;
+ taskid_t parentid;
std::string title;
std::string desc;
} task_t;
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);
diff --git a/src/testclient.cc b/src/testclient.cc
index b0d59a5..31632d5 100644
--- a/src/testclient.cc
+++ b/src/testclient.cc
@@ -184,8 +184,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 },