diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/message.h | 15 | ||||
-rw-r--r-- | src/messagehandler.cc | 19 | ||||
-rw-r--r-- | src/messageparser.cc | 64 | ||||
-rw-r--r-- | src/messageparser.h | 1 | ||||
-rw-r--r-- | src/tasktree.cc | 35 |
5 files changed, 72 insertions, 62 deletions
diff --git a/src/message.h b/src/message.h index e309f5d..383fa73 100644 --- a/src/message.h +++ b/src/message.h @@ -39,8 +39,8 @@ namespace cmd { unobserve, update, move, - add, - del, + create, + remove, error } cmd_t; }; @@ -56,13 +56,11 @@ typedef struct { typedef struct { taskid_t id; taskid_t parentid; - char title[256]; - char desc[256]; -} add_t; +} create_t; typedef struct { taskid_t id; -} del_t; +} remove_t; typedef struct { taskid_t id; @@ -72,7 +70,6 @@ typedef struct { typedef struct { taskid_t id; char title[256]; - char desc[256]; } update_t; @@ -82,8 +79,8 @@ typedef struct { union { observe_t observe; unobserve_t unobserve; - add_t add; - del_t del; + create_t create; + remove_t remove; move_t move; update_t update; }; diff --git a/src/messagehandler.cc b/src/messagehandler.cc index 3065e60..0d2dd3c 100644 --- a/src/messagehandler.cc +++ b/src/messagehandler.cc @@ -44,31 +44,29 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { message_t &m = *it; switch(m.cmd) { - case cmd::add: + case cmd::create: { - INFO(messagehandler, "Handling add command\n"); + INFO(messagehandler, "Handling create command\n"); task_t t = task_manager.createTask(); - t.title = m.add.title; - t.desc = m.add.desc; try { - m.nodes = task_manager.addTask(t, m.add.parentid); + m.nodes = task_manager.addTask(t, m.create.parentid); outmsgs.push_back(m); } catch (std::exception& e) { - DEBUG(messagehandler, "Error adding task\n"); + DEBUG(messagehandler, "Error creating task\n"); } } break; - case cmd::del: + case cmd::remove: { - INFO(messagehandler, "Handling del command\n"); + INFO(messagehandler, "Handling remove command\n"); try { - m.nodes = task_manager.deleteTask(m.del.id); + m.nodes = task_manager.deleteTask(m.remove.id); outmsgs.push_back(m); } catch (std::exception& e) { - DEBUG(messagehandler, "Error deleting task\n"); + DEBUG(messagehandler, "Error remove task\n"); } } break; @@ -104,7 +102,6 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { try { task_t t; t.title = m.update.title; - t.desc = m.update.desc; m.nodes = task_manager.updateTask(m.update.id, t); outmsgs.push_back(m); } diff --git a/src/messageparser.cc b/src/messageparser.cc index 3b19b86..b3fc173 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -110,8 +110,8 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, if(t[0] == "observe") m.cmd = cmd::observe; else if(t[0] == "unobserve") m.cmd = cmd::unobserve; - else if(t[0] == "add") m.cmd = cmd::add; -// else if(t[0] == "del") m.cmd = cmd::del; + else if(t[0] == "create") m.cmd = cmd::create; + else if(t[0] == "remove") m.cmd = cmd::remove; else if(t[0] == "move") m.cmd = cmd::move; else if(t[0] == "update") m.cmd = cmd::update; else m.cmd = cmd::error; @@ -135,25 +135,22 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, m.unobserve.id = atoi(t[1].c_str()); break; } - case cmd::add: { - if(t.size() != 3+1) { + case cmd::create: { + if(t.size() != 1+1) { + printf("Wrong number of parameters\n"); + continue; + } + m.create.parentid = atoi(t[1].c_str()); + break; + } + case cmd::remove: { + if(t.size() != 1+1) { printf("Wrong number of parameters\n"); continue; } - sprintf(m.add.title, "%s", t[1].c_str()); - sprintf(m.add.desc, "%s", t[2].c_str()); - m.add.parentid = atoi(t[3].c_str()); - printf("addcmd: %s %s %d\n", m.add.title, m.add.desc, m.add.parentid); + m.remove.id = atoi(t[1].c_str()); break; } -// case cmd::del: { -// if(t.size() != 1+1) { -// printf("Wrong number of parameters\n"); -// continue; -// } -// m.del.id = atoi(t[1].c_str()); -// break; -// } case cmd::move: { if(t.size() != 2+1) { printf("Wrong number of parameters\n"); @@ -164,13 +161,12 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, break; } case cmd::update: { - if(t.size() != 3+1) { + if(t.size() != 2+1) { printf("Wrong number of parameters\n"); continue; } m.update.id = atoi(t[1].c_str()); sprintf(m.update.title, "%s", t[2].c_str()); - sprintf(m.update.desc, "%s", t[3].c_str()); break; } default: @@ -195,24 +191,22 @@ MessageList parse_msg(std::string data) { std::string msg_tostring(message_t m) { char* buf = NULL; switch(m.cmd) { - case cmd::add: { - asprintf(&buf, "add %d \"%s\" \"%s\" %d;", - m.add.id, - m.add.title, m.add.desc, - m.add.parentid); + case cmd::create: { + asprintf(&buf, "create %d %d;", + m.create.id, + m.create.parentid); + break; + } + case cmd::remove: { + asprintf(&buf, "remove %d;", m.remove.id); break; } -// case cmd::del: { -// asprintf(&buf, "del %d;", m.del.id); -// break; -// } case cmd::move: { asprintf(&buf, "move %d %d;", m.move.id, m.move.parentid); break; } case cmd::update: { - //todo - asprintf(&buf, "update %d \"%s\" \"%s\";", m.update.id, m.update.title, m.update.desc); + asprintf(&buf, "update %d \"%s\";", m.update.id, m.update.title); break; }; default: @@ -230,8 +224,8 @@ std::string msg_tostring(message_t m) { message_t create_msg_create(task_t t) { message_t m; - m.cmd = cmd::add; - m.add.id = t.id; + m.cmd = cmd::create; + m.create.id = t.id; return m; } @@ -239,10 +233,16 @@ message_t create_msg_update(task_t t) { message_t m; m.cmd = cmd::update; m.update.id = t.id; - sprintf(m.add.title, "%s", t.title.c_str()); + sprintf(m.update.title, "%s", t.title.c_str()); return m; } +message_t create_msg_remove(task_t t) { + message_t m; + m.cmd = cmd::remove; + m.remove.id = t.id; + return m; +} #ifdef TEST_MSGPARSER //Additional dependency files diff --git a/src/messageparser.h b/src/messageparser.h index aa0ec79..6ebac3e 100644 --- a/src/messageparser.h +++ b/src/messageparser.h @@ -37,5 +37,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); #endif/*__MUNIA_MESSAGEPARSER_H__*/ diff --git a/src/tasktree.cc b/src/tasktree.cc index 0a9ad46..c66e665 100644 --- a/src/tasktree.cc +++ b/src/tasktree.cc @@ -267,27 +267,42 @@ void TaskTree::toStdOut() { #ifdef TEST_TASKTREE //Additional dependency files -//deps: +//deps: debug.cc log.cc //Required cflags (autoconf vars may be used) -//cflags: +//cflags: -I.. //Required link options (autoconf vars may be used) //libs: #include "test.h" #include <exception> +#define ROOT_ID 0 +#define LOSTFOUND_ID 1 +#define FINISHED_ID 2 +#define BACKLOG_ID 3 +#define PROJECTS_ID 4 +#define FIRST_TASK_ID 10 + TEST_BEGIN; TaskTree tree; task_t t; -try { - tree.insertAsChild(-1, t); - } - catch(std::exeception& e) { - } - -// TODO: Put some testcode here (see test.h for usable macros). -TEST_TRUE(false, "No tests yet!"); +t.title = "root"; +tree.insertAsChild(0, ROOT_ID, t); + +t.title = "Finished"; +tree.insertAsChild(ROOT_ID, FINISHED_ID, t); + +t.title = "Backlog"; +tree.insertAsChild(ROOT_ID, BACKLOG_ID, t); + +t.title = "Lost+Found"; +tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t); + +t.title = "Projects"; +tree.insertAsChild(ROOT_ID, PROJECTS_ID, t); + +TEST_EQUAL_INT(5, tree.bfs(0).size(), "Testing BFS function"); TEST_END; |