From 39396a2660150770c3fd14aac8b4be0dcbae8497 Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Sat, 10 Mar 2012 14:56:34 +0100 Subject: Added new task hierarchy based protocol. Drag and drop works somehow - maybe some weirdness in html5 drag and drop. --- src/msgparser.cc | 36 +++++++++++++++++++++++------------- src/msgparser.h | 9 ++++----- src/muniad.cc | 9 +++++---- src/task.cc | 7 ++++--- src/task.h | 31 +++++++++++++++++++++++++++++-- src/task_proto.cc | 18 +++++++++++------- 6 files changed, 76 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/msgparser.cc b/src/msgparser.cc index 1ea2f31..f3bafe1 100644 --- a/src/msgparser.cc +++ b/src/msgparser.cc @@ -32,6 +32,7 @@ #include #include +/* inline void parse_add(msg_t& m, std::string data) { int offset = 0; std::string title = data.substr(offset, data.find(' ', offset) - offset); @@ -73,6 +74,7 @@ inline void parse_move(msg_t& m, std::string data) { m.move.x = x; m.move.y = y; } +*/ MsgVector parse_msg(std::string data) { @@ -165,14 +167,15 @@ MsgVector parse_msg(std::string data) { switch(m.cmd) { case cmd::add: { - if(t.size() != 4+1) { + if(t.size() != 3+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.x = atoi(t[3].c_str()); - m.add.y = atoi(t[4].c_str()); + m.add.parent_id = atoi(t[3].c_str()); +// m.add.x = atoi(t[3].c_str()); +// m.add.y = atoi(t[4].c_str()); // printf("addcmd: %s %s %d %d\n", m.add.title, m.add.desc, m.add.x, m.add.y); break; } @@ -185,13 +188,14 @@ MsgVector parse_msg(std::string data) { break; } case cmd::move: { - if(t.size() != 3+1) { + if(t.size() != 2+1) { printf("Wrong number of parameters\n"); continue; } m.move.id = atoi(t[1].c_str()); - m.move.x = atoi(t[2].c_str()); - m.move.y = atoi(t[3].c_str()); + m.move.parent_id = atoi(t[2].c_str()); +// m.move.x = atoi(t[2].c_str()); +// m.move.y = atoi(t[3].c_str()); break; } case cmd::update: { @@ -217,8 +221,9 @@ msg_t create_msg(cmd::cmd_t type, task_t t) { switch(type) { case cmd::add: { m.add.id = t.id; - m.add.x = t.x; - m.add.y = t.y; + m.add.parent_id = t.parent_id; +// m.add.x = t.x; +// m.add.y = t.y; // m.add.title = t.title.c_str(); // m.add.desc = t.desc.c_str(); snprintf(m.add.title, sizeof(m.add.title), "%s", t.title.c_str()); @@ -231,8 +236,9 @@ msg_t create_msg(cmd::cmd_t type, task_t t) { } case cmd::move: { m.move.id = t.id; - m.move.x = t.x; - m.move.y = t.y; +// m.move.x = t.x; +// m.move.y = t.y; + m.move.parent_id = t.parent_id; break; } case cmd::update: { @@ -258,10 +264,14 @@ std::string msg_tostring(msg_t m) { case cmd::add: { // printf("msg: %d, %d, %d, %s, %s\n", m.add.id, m.add.x, m.add.y, m.add.title, m.add.desc); // snprintf(buf, BUF_SIZE, "add %d %s %s %d %d;", - asprintf(&buf, "add %d \"%s\" \"%s\" %d %d;", +// asprintf(&buf, "add %d \"%s\" \"%s\" %d %d;", +// m.add.id, +// m.add.title, m.add.desc, +// m.add.x, m.add.y); + asprintf(&buf, "add %d \"%s\" \"%s\" %d;", m.add.id, m.add.title, m.add.desc, - m.add.x, m.add.y); + m.add.parent_id); break; } case cmd::del: { @@ -271,7 +281,7 @@ std::string msg_tostring(msg_t m) { } case cmd::move: { // snprintf(buf, BUF_SIZE, "move %d %d %d;", m.move.id, m.move.x, m.move.y); - asprintf(&buf, "move %d %d %d;", m.move.id, m.move.x, m.move.y); + asprintf(&buf, "move %d %d;", m.move.id, m.move.parent_id); break; } case cmd::update: { diff --git a/src/msgparser.h b/src/msgparser.h index fa853fa..58f68da 100644 --- a/src/msgparser.h +++ b/src/msgparser.h @@ -45,8 +45,9 @@ namespace cmd { typedef struct { int id; - int x; - int y; + int parent_id; +// int x; +// int y; char title[256]; char desc[256]; } add_t; @@ -55,8 +56,7 @@ typedef struct { } del_t; typedef struct { int id; - int x; - int y; + int parent_id; } move_t; typedef struct { int id; @@ -74,7 +74,6 @@ typedef struct msg_t { move_t move; update_t update; }; - } msg_types; diff --git a/src/muniad.cc b/src/muniad.cc index ef76ff1..ab69456 100644 --- a/src/muniad.cc +++ b/src/muniad.cc @@ -82,9 +82,10 @@ int main(int argc, char **argv) char interface_name[128] = ""; const char * interface = NULL; - fprintf(stderr, "libwebsockets test server\n" - "(C) Copyright 2010-2011 Andy Green " - "licensed under LGPL2.1\n"); + fprintf(stderr, "Munia test server\n" + "(C) Copyright 2012 Bent Bisballe Nyeng (deva@aasimon.org)\n" + " & Jonas Suhr Christensen (jsc@umbraculum.org)\n" + "Licensed under LGPL2.1\n"); while(n >= 0) { n = getopt_long(argc, argv, "ci:khsp:", options, NULL); @@ -105,7 +106,7 @@ int main(int argc, char **argv) interface = interface_name; break; case 'h': - fprintf(stderr, "Usage: test-server [--port=

] [--ssl]\n"); + fprintf(stderr, "Usage: muniad [--port=

] [--ssl]\n"); exit(1); } } diff --git a/src/task.cc b/src/task.cc index 24e94a1..9940fc6 100644 --- a/src/task.cc +++ b/src/task.cc @@ -35,11 +35,12 @@ int current_id_count() { } task_t create_task(std::string title, std::string desc, - int x, int y) { + /*int x, int y,*/ int parent_id) { task_t t; - t.x = x; - t.y = y; + t.parent_id = parent_id; +// t.x = x; +// t.y = y; t.title = title; t.desc = desc; t.id = id_count; id_count++; diff --git a/src/task.h b/src/task.h index 4365c1c..43541bc 100644 --- a/src/task.h +++ b/src/task.h @@ -32,6 +32,16 @@ #include /* +Task: + id + subtasks +// tags + title + description +// primary_assignment +// secondary_assignment + + Protocol: Server -> client: @@ -51,18 +61,35 @@ x and y are integers as strings id are an integer as a string */ - +/* typedef struct { int x, y; int id; std::string title; std::string desc; } task_t; +*/ +/* +protocol: + add_task title description parent_id + del_task id + update_task id title description + move_task id parent + copy_task id parent +*/ + +typedef struct { + int id; + int parent_id; + std::string title; + std::string desc; +} task_t; + typedef std::list TaskList; extern TaskList tasklist; task_t create_task(std::string title, std::string desc, - int x, int y); + /*int x, int y*/ int parent_id); #endif/*__MUNIA_TASK_H__*/ diff --git a/src/task_proto.cc b/src/task_proto.cc index 4bcc3a8..717ca3e 100644 --- a/src/task_proto.cc +++ b/src/task_proto.cc @@ -184,9 +184,11 @@ int callback_lws_task(struct libwebsocket_context * context, case cmd::add: { printf("Handling add cmd\n"); +// task_t t = create_task(m.add.title, m.add.desc, +// m.add.x, m.add.y); task_t t = create_task(m.add.title, m.add.desc, - m.add.x, m.add.y); - tasklist.push_back(t); + m.add.parent_id); + tasklist.push_back(t); // buf_len = sprintf(buf, "add %d %s %s %d %d;", // t.id, t.title.c_str(), t.desc.c_str(), // t.x, t.y); @@ -202,6 +204,7 @@ int callback_lws_task(struct libwebsocket_context * context, printf("Delete\n"); printf("Deleting task with id %d\n", m.del.id); + // todo: delete all children recursively task_t del_task; bool id_found = false; TaskList::iterator it; @@ -228,21 +231,22 @@ int callback_lws_task(struct libwebsocket_context * context, case cmd::move: { printf("Move\n"); - printf("Moving task with id %d to (%d,%d)\n", m.move.id, m.move.x, m.move.y); + printf("Moving task with id %d to %d\n", m.move.id, m.move.parent_id); bool id_found = false; TaskList::iterator it; - int x = m.move.x / 300 * 300; +// int x = m.move.x / 300 * 300; task_t moved_task; for(it = tasklist.begin(); it != tasklist.end(); it++) { task_t &t = *it; if(t.id == m.move.id) { id_found = true; - t.x = x; - t.y = m.move.y; - moved_task = t; +// t.x = x; +// t.y = m.move.y; + t.parent_id = m.move.parent_id; + moved_task = t; break; } } -- cgit v1.2.3