From 5b03a3c914cf02c63d1db36328c2ea77b10cfa70 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 3 May 2012 18:35:06 +0200 Subject: Update to correct license (GPLv3) --- src/muniad.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/muniad.cc b/src/muniad.cc index 34f5c6a..741241a 100644 --- a/src/muniad.cc +++ b/src/muniad.cc @@ -76,9 +76,13 @@ int main(int argc, char **argv) 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"); - + " & Jonas Suhr Christensen (jsc@umbraculum.org)\n" + "License GPLv3+: GNU GPL version 3 or later " + "\n" + "\n" + "This is free software; you are free to change and redistribute it.\n" + "There is NO WARRANTY, to the extent permitted by law.\n"); + while(n >= 0) { n = getopt_long(argc, argv, "ci:khsp:", options, NULL); if(n < 0) continue; -- cgit v1.2.3 From b36a3176dfb080b5ce58713dcb83d9489948acb4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 3 May 2012 18:35:37 +0200 Subject: Add test client. --- src/Makefile.am | 2 + src/testclient.cc | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testclient.h | 30 ++++++++ 3 files changed, 240 insertions(+) create mode 100644 src/testclient.cc create mode 100644 src/testclient.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 9fccb45..a56ae39 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,6 +19,7 @@ muniad_SOURCES = \ task.cc \ taskmanager.cc \ tasktree.cc \ + testclient.cc \ xml_encode_decode.cc \ xmlparser.cc @@ -35,6 +36,7 @@ EXTRA_DIST = \ task.h \ taskmanager.h \ tasktree.h \ + testclient.h \ xml_encode_decode.h \ xmlparser.h diff --git a/src/testclient.cc b/src/testclient.cc new file mode 100644 index 0000000..5df0d56 --- /dev/null +++ b/src/testclient.cc @@ -0,0 +1,208 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * testclient.cc + * + * Thu May 3 10:06:49 CEST 2012 + * Copyright 2012 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Munia. + * + * Munia is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Munia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Munia; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "testclient.h" + +#ifdef TEST_TESTCLIENT +//deps: +//cflags: $(LIBWEBSOCKETS_CFLAGS) +//libs: $(LIBWEBSOCKETS_LIBS) +#include "test.h" + +#include +#include +#include +#include +#include + +#include + +struct test { + const char *command; + const char *result; + bool success; +}; + +enum demo_protocols { + PROTOCOL_TASK, +}; + +struct test *current_test = NULL; + +static int callback_task(struct libwebsocket_context *me, + struct libwebsocket *wsi, + enum libwebsocket_callback_reasons reason, + void *user, void *in, size_t len) +{ + unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 + + LWS_SEND_BUFFER_POST_PADDING]; + int l; + + switch (reason) { + + case LWS_CALLBACK_CLOSED: + fprintf(stderr, "mirror: LWS_CALLBACK_CLOSED\n"); + // wsi_mirror = NULL; + break; + + case LWS_CALLBACK_CLIENT_ESTABLISHED: + + /* + * start the ball rolling, + * LWS_CALLBACK_CLIENT_WRITEABLE will come next service + */ + + libwebsocket_callback_on_writable(me, wsi); + break; + + case LWS_CALLBACK_CLIENT_RECEIVE: + fprintf(stderr, "rx %d '%s'\n", (int)len, (char *)in); + current_test->success = strncmp(current_test->result, (char*)in, len) == 0; + current_test++; + break; + + case LWS_CALLBACK_CLIENT_WRITEABLE: + + + l = sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING], + "%s", current_test->command); + + libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], + l, LWS_WRITE_TEXT); + + if(current_test->result == NULL) current_test++; + + libwebsocket_callback_on_writable(me, wsi); + + /* + * without at least this delay, we choke the browser + * and the connection stalls, despite we now take care about + * flow control + */ + + //usleep(200); + sleep(1); + break; + + default: + break; + } + + return 0; +} + +static struct libwebsocket_protocols protocols[] = { + { "lws-task-protocol", callback_task, 0, }, + { NULL, NULL, 0 } +}; + +int client(const char *address, int port, struct test tests[]) +{ + current_test = &tests[0]; + + struct libwebsocket_context *context; + struct libwebsocket *wsi_task = NULL; + int ietf_version = -1; // latest + + context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL, + protocols, + libwebsocket_internal_extensions, + NULL, NULL, -1, -1, 0); + if (context == NULL) { + fprintf(stderr, "Creating libwebsocket context failed\n"); + return 1; + } + + + /* + * sit there servicing the websocket context to handle incoming + * packets, and drawing random circles on the mirror protocol websocket + */ + int n = 1; + while(n >= 0 && current_test->command) { + n = libwebsocket_service(context, 1000); + + if (wsi_task == NULL) { + wsi_task = libwebsocket_client_connect(context, address, port, + 0, "/", address, address, + protocols[PROTOCOL_TASK].name, + ietf_version); + + if (wsi_task == NULL) { + fprintf(stderr, "libwebsocket task connect failed\n"); + return -1; + } + + } else { + + /* + fprintf(stderr, "closing mirror session\n"); + libwebsocket_close_and_free_session(context, + wsi_mirror, LWS_CLOSE_STATUS_GOINGAWAY); + */ + } + } + + fprintf(stderr, "Exiting\n"); + + libwebsocket_context_destroy(context); + + return 0; +} + +TEST_BEGIN; + +#define BASE "0 create 0 -1; 0 update 0 \"root\"; " +static struct test tests[] = { + { "observe 0", BASE"", false }, + { "unobserve 0", "0 remove 0", false }, + /* + { "create 0", "", false }, + { "observe 0", BASE"0 create 0 5", false }, + { "unobserve 0", NULL, false }, + { "observe 0", BASE"0 add title description 5", false }, + { "add title2 description 0", BASE"0 add title2 description 6", false }, + { "unobserve 0", NULL, false }, + { "observe 0", BASE"0 add title description 5; add title description 6", false }, + { "unobserve 0", NULL, false }, + */ + { NULL, NULL, false } +}; + +client("holger", 10001, tests); + +struct test *t = &tests[0]; +while(t->command) { + TEST_TRUE(t->success, "%s", t->command); + t++; +} +// TODO: Put some testcode here (see test.h for usable macros). +//TEST_TRUE(false, "No tests yet!"); + +TEST_END; + +#endif/*TEST_TESTCLIENT*/ diff --git a/src/testclient.h b/src/testclient.h new file mode 100644 index 0000000..d92bd9c --- /dev/null +++ b/src/testclient.h @@ -0,0 +1,30 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * testclient.h + * + * Thu May 3 10:06:49 CEST 2012 + * Copyright 2012 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Munia. + * + * Munia is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Munia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Munia; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __MUNIA_TESTCLIENT_H__ +#define __MUNIA_TESTCLIENT_H__ +#endif/*__MUNIA_TESTCLIENT_H__*/ -- cgit v1.2.3 From 7be1c348e6323889479639df6b7d5b4d6a972b65 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 4 May 2012 08:50:20 +0200 Subject: Make TaskManager and ConnectionHandler objects global. --- src/connectionhandler.cc | 24 ++++++++++++------------ src/connectionhandler.h | 3 ++- src/messagehandler.cc | 15 +++++++-------- src/munia_proto.cc | 5 ++--- src/taskmanager.cc | 3 +++ src/taskmanager.h | 2 ++ 6 files changed, 28 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index 56c465f..b2b6973 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -29,6 +29,9 @@ #include +// Defines global task_manager object +#include "taskmanager.h" + // Global ConnectionHandler. ConnectionHandler connection_handler; @@ -65,16 +68,13 @@ void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid) connlist[clientid].erase(taskid); } -std::list > -ConnectionHandler::observerlist(TaskIdList tasks) +ObserverList ConnectionHandler::observerlist(TaskIdList tasks) { printf("Observerlist request\n"); - std::list > clients; + ObserverList clients; for(TaskIdList::iterator i = tasks.begin(); i != tasks.end(); i++) { taskid_t tid = *i; - // std::set clientList; - // std::map printf("Locating observers of node %d\n", tid); for(ConnectionList::iterator ci = connlist.begin(); @@ -118,7 +118,7 @@ h.observe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)1); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -128,7 +128,7 @@ h.observe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)3); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -138,7 +138,7 @@ h.observe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)4); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -150,7 +150,7 @@ h.observe((clientid_t)3, (taskid_t)3); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -163,7 +163,7 @@ h.close((clientid_t)1); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -176,7 +176,7 @@ h.close((clientid_t)2); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -189,7 +189,7 @@ h.close((clientid_t)3); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - std::set clst = h.observerlist(tasks); + ObserverList clst = h.observerlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); diff --git a/src/connectionhandler.h b/src/connectionhandler.h index b09e944..7779b1f 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -39,6 +39,7 @@ typedef struct libwebsocket* clientid_t; typedef std::map > ConnectionList; +typedef std::list > ObserverList; class ConnectionHandler { public: @@ -50,7 +51,7 @@ public: void unobserve(clientid_t clientid, taskid_t taskid); - std::list > observerlist(TaskIdList tasklist); + ObserverList observerlist(TaskIdList tasklist); private: ConnectionList connlist; diff --git a/src/messagehandler.cc b/src/messagehandler.cc index 89b476a..18d5fed 100644 --- a/src/messagehandler.cc +++ b/src/messagehandler.cc @@ -28,10 +28,9 @@ #include "messagehandler.h" #include "debug.h" +// Defines global task_manager object #include "taskmanager.h" -TaskManager taskman; - MessageList handle_msg(MessageList msgList, clientid_t wsi) { MessageList::iterator it; @@ -44,11 +43,11 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { case cmd::add: { INFO(messagehandler, "Handling add command\n"); - task_t t = taskman.createTask(); + task_t t = task_manager.createTask(); t.title = m.add.title; t.desc = m.add.desc; try { - it->nodes = taskman.addTask(t, m.add.parentid); + it->nodes = task_manager.addTask(t, m.add.parentid); } catch (std::exception& e) { DEBUG(messagehandler, "Error adding task\n"); @@ -59,7 +58,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { { INFO(messagehandler, "Handling del command\n"); try { - it->nodes = taskman.deleteTask(m.del.id); + it->nodes = task_manager.deleteTask(m.del.id); } catch (std::exception& e) { DEBUG(messagehandler, "Error deleting task\n"); @@ -70,7 +69,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { { INFO(messagehandler, "Handling move command\n"); try { - it->nodes = taskman.moveTask(m.move.id, m.move.parentid); + it->nodes = task_manager.moveTask(m.move.id, m.move.parentid); } catch (std::exception& e) { DEBUG(messagehandler, "Error moving task\n"); @@ -90,7 +89,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { task_t t; t.title = m.update.title; t.desc = m.update.desc; - it->nodes = taskman.updateTask(m.update.id, t); + it->nodes = task_manager.updateTask(m.update.id, t); } catch (std::exception& e) { DEBUG(messagehandler, "Error updating task\n"); @@ -101,7 +100,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { WARN(messagehandler, "!!! Unknown command\n"); break; } - taskman.tree.toStdOut(); + task_manager.tree.toStdOut(); printf("%d affected nodes registered\n", m.nodes.size()); } diff --git a/src/munia_proto.cc b/src/munia_proto.cc index b801009..a91c204 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -38,10 +38,9 @@ #include "messagehandler.h" #include "connectionhandler.h" +// Defines global task_manager object #include "taskmanager.h" -extern TaskManager taskman; - #if 0 static void dump_handshake_info(struct lws_tokens *lwst) { @@ -89,7 +88,7 @@ int callback_lws_task(struct libwebsocket_context * context, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len) { - taskman.tree.toStdOut(); + task_manager.tree.toStdOut(); printf("Callback on %p\n", wsi); diff --git a/src/taskmanager.cc b/src/taskmanager.cc index a197a79..f757694 100644 --- a/src/taskmanager.cc +++ b/src/taskmanager.cc @@ -29,6 +29,9 @@ #include +// Global TaskManager object. +TaskManager task_manager; + #define ROOT_ID 0 #define LOSTFOUND_ID 1 #define FINISHED_ID 2 diff --git a/src/taskmanager.h b/src/taskmanager.h index d6a418b..6b24208 100644 --- a/src/taskmanager.h +++ b/src/taskmanager.h @@ -55,6 +55,8 @@ private: taskid_t idCount; }; +extern TaskManager task_manager; + #if 0 /* -- cgit v1.2.3 From 068f4577b4ca3da40ac0f4b82b58e90023aa2aef Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 4 May 2012 08:52:53 +0200 Subject: Add stub for node change traversal. --- src/taskmanager.cc | 5 +++++ src/taskmanager.h | 2 ++ 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/taskmanager.cc b/src/taskmanager.cc index f757694..2f6a42a 100644 --- a/src/taskmanager.cc +++ b/src/taskmanager.cc @@ -144,6 +144,11 @@ TaskIdList TaskManager::addTask(task_t t, taskid_t parentid) return affectedTasks; } +TaskIdList TaskManager::recursiveNodeChangeList(taskid_t id) +{ + return TaskIdList; +} + /* TaskIdList TaskManager::ancestorList(taskid_t id) throw (std::exception) { diff --git a/src/taskmanager.h b/src/taskmanager.h index 6b24208..623e1ff 100644 --- a/src/taskmanager.h +++ b/src/taskmanager.h @@ -47,6 +47,8 @@ public: TaskIdList deleteTask(taskid_t id) throw (std::exception); TaskIdList moveTask(taskid_t id, taskid_t newParent) throw (std::exception); + TaskIdList recursiveNodeChangeList(taskid_t id); + TaskTree tree; private: -- cgit v1.2.3 From de7c3ed2ccadcd179449dee6b8e38f6d7d2df3c6 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 4 May 2012 08:59:47 +0200 Subject: Remove stub for node change traversal. --- src/connectionhandler.cc | 3 --- src/taskmanager.cc | 5 ----- src/taskmanager.h | 2 -- 3 files changed, 10 deletions(-) (limited to 'src') diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index b2b6973..c8881a3 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -29,9 +29,6 @@ #include -// Defines global task_manager object -#include "taskmanager.h" - // Global ConnectionHandler. ConnectionHandler connection_handler; diff --git a/src/taskmanager.cc b/src/taskmanager.cc index 2f6a42a..f757694 100644 --- a/src/taskmanager.cc +++ b/src/taskmanager.cc @@ -144,11 +144,6 @@ TaskIdList TaskManager::addTask(task_t t, taskid_t parentid) return affectedTasks; } -TaskIdList TaskManager::recursiveNodeChangeList(taskid_t id) -{ - return TaskIdList; -} - /* TaskIdList TaskManager::ancestorList(taskid_t id) throw (std::exception) { diff --git a/src/taskmanager.h b/src/taskmanager.h index 623e1ff..47c6c10 100644 --- a/src/taskmanager.h +++ b/src/taskmanager.h @@ -46,8 +46,6 @@ public: TaskIdList updateTask(taskid_t id, task_t task) throw (std::exception); TaskIdList deleteTask(taskid_t id) throw (std::exception); TaskIdList moveTask(taskid_t id, taskid_t newParent) throw (std::exception); - - TaskIdList recursiveNodeChangeList(taskid_t id); TaskTree tree; -- cgit v1.2.3