From 5df006d6a7c3b23864838b7b3b1f6b379ee103f3 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Fri, 4 May 2012 11:33:14 +0200 Subject: Renamed add to create, renamed del to remove and remove task desc --- src/message.h | 15 +++++------- src/messagehandler.cc | 19 +++++++-------- src/messageparser.cc | 64 +++++++++++++++++++++++++-------------------------- src/messageparser.h | 1 + 4 files changed, 47 insertions(+), 52 deletions(-) diff --git a/src/message.h b/src/message.h index d566400..dc4386b 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 c768579..b39548d 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(taskid_t task); message_t create_msg_update(taskid_t task); +message_t create_msg_remove(taskid_t task); #endif/*__MUNIA_MESSAGEPARSER_H__*/ -- cgit v1.2.3