diff options
-rw-r--r-- | proto.js | 14 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/connectionhandler.cc | 7 | ||||
-rw-r--r-- | src/connectionhandler.h | 2 | ||||
-rw-r--r-- | src/messagehandler.cc | 10 | ||||
-rw-r--r-- | src/messagehandler.h | 3 | ||||
-rw-r--r-- | src/munia_proto.cc (renamed from src/task_proto.cc) | 22 | ||||
-rw-r--r-- | src/munia_proto.h (renamed from src/task_proto.h) | 8 | ||||
-rw-r--r-- | src/muniad.cc | 6 | ||||
-rw-r--r-- | src/observe_proto.cc | 85 | ||||
-rw-r--r-- | src/observe_proto.h | 44 |
11 files changed, 53 insertions, 154 deletions
@@ -93,7 +93,7 @@ var no_last = 1; var last_x = 0, last_y = 0; var ctx; var socket_task; -var socket_observe; +//var socket_observe; var color = "#000000"; var dragged = ""; @@ -106,10 +106,10 @@ board.setAttribute("ondragleave", "return dragleave(this)"); if (BrowserDetect.browser == "Firefox") { socket_task = new MozWebSocket(get_appropriate_ws_url(), "lws-task-protocol"); - socket_observe = new MozWebSocket(get_appropriate_ws_url(), "lws-observe-protocol"); +// socket_observe = new MozWebSocket(get_appropriate_ws_url(), "lws-observe-protocol"); } else { socket_task = new WebSocket(get_appropriate_ws_url(), "lws-task-protocol"); - socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-protocol"); +// socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-protocol"); } try { @@ -121,7 +121,7 @@ try { socket_task.onmessage = function got_packet(msg) { document.getElementById("wstask_lastmsg").textContent = msg.data; - + var msgs = new Array(); var idx = 0; msgs[idx] = ''; @@ -252,6 +252,7 @@ try { alert('<p>Error' + exception + '</p>'); } +/* try { socket_observe.onopen = function() { document.getElementById("wsobserve_status").style.backgroundColor = "#40ff40"; @@ -391,6 +392,7 @@ try { } catch(exception) { alert('<p>Error' + exception + '</p>'); } +*/ //var canvas = document.createElement('canvas'); //canvas.height = 600; @@ -436,12 +438,12 @@ function task_submit() { var data = document.getElementById("input_task_data").value; socket_task.send(data); } - +/* function observe_submit() { var data = document.getElementById("input_observe_data").value; socket_observe.send(data); } - +*/ function clear() { document.getElementById("input_data").value = ""; } diff --git a/src/Makefile.am b/src/Makefile.am index 4d087d8..9fccb45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,12 +14,11 @@ muniad_SOURCES = \ http.cc \ messagehandler.cc \ messageparser.cc \ + munia_proto.cc \ saxparser.cc \ task.cc \ - task_proto.cc \ taskmanager.cc \ tasktree.cc \ - observe_proto.cc \ xml_encode_decode.cc \ xmlparser.cc @@ -31,12 +30,11 @@ EXTRA_DIST = \ message.h \ messageparser.h \ messagehandler.h \ + munia_proto.h \ saxparser.h \ task.h \ - task_proto.h \ taskmanager.h \ tasktree.h \ - observe_proto.h \ xml_encode_decode.h \ xmlparser.h diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index 9362965..85ae4a7 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -38,7 +38,14 @@ ConnectionHandler::ConnectionHandler() void ConnectionHandler::init(clientid_t clientid) { + printf("Adding client %p to connection list\n", clientid); connlist[clientid] = std::set<taskid_t>(); + + printf("Connections (%d):\n", connlist.size()); + ConnectionList::iterator it; + for(it = connlist.begin(); it != connlist.end(); it++) { + printf("\t%p\n", it->first); + } } void ConnectionHandler::close(clientid_t clientid) diff --git a/src/connectionhandler.h b/src/connectionhandler.h index f5e63d7..464128b 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -32,6 +32,8 @@ #include <set> #include <map> +#include <libwebsockets.h> + #include "task.h" typedef struct libwebsocket* clientid_t; diff --git a/src/messagehandler.cc b/src/messagehandler.cc index 5f3cafb..89b476a 100644 --- a/src/messagehandler.cc +++ b/src/messagehandler.cc @@ -32,7 +32,7 @@ TaskManager taskman; -MessageList handle_msg(MessageList msgList) { +MessageList handle_msg(MessageList msgList, clientid_t wsi) { MessageList::iterator it; for(it = msgList.begin(); @@ -48,7 +48,7 @@ MessageList handle_msg(MessageList msgList) { t.title = m.add.title; t.desc = m.add.desc; try { - it->nodes = taskman.addTask(t, m.add.parentid); + it->nodes = taskman.addTask(t, m.add.parentid); } catch (std::exception& e) { DEBUG(messagehandler, "Error adding task\n"); @@ -77,6 +77,12 @@ MessageList handle_msg(MessageList msgList) { } } break; + case cmd::observe: + connection_handler.observe(wsi, m.observe.id); + break; + case cmd::unobserve: + connection_handler.unobserve(wsi, m.observe.id); + break; case cmd::update: { INFO(messagehandler, "Handling update command\n"); diff --git a/src/messagehandler.h b/src/messagehandler.h index 2651255..cc2c8a0 100644 --- a/src/messagehandler.h +++ b/src/messagehandler.h @@ -30,8 +30,9 @@ #include "messageparser.h" +#include "connectionhandler.h" -MessageList handle_msg(MessageList inMsgList); +MessageList handle_msg(MessageList inMsgList, clientid_t wsi); #endif/*__MUNIA_MSGHANDLER_H__*/ diff --git a/src/task_proto.cc b/src/munia_proto.cc index 24be3b0..3679a81 100644 --- a/src/task_proto.cc +++ b/src/munia_proto.cc @@ -1,7 +1,7 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** - * task_proto.cc + * munia_proto.cc * * Fri Feb 24 08:23:16 CET 2012 * Copyright 2012 Bent Bisballe Nyeng @@ -25,7 +25,7 @@ * along with Munia; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "task_proto.h" +#include "munia_proto.h" #include <stdio.h> #include <string.h> @@ -91,9 +91,20 @@ int callback_lws_task(struct libwebsocket_context * context, { taskman.tree.toStdOut(); + printf("Callback on %p\n", wsi); + switch (reason) { + case LWS_CALLBACK_ESTABLISHED: + connection_handler.init(wsi); + break; + + case LWS_CALLBACK_CLOSED: + connection_handler.close(wsi); + break; + case LWS_CALLBACK_SERVER_WRITEABLE: { + printf("Socket for client %p writable\n", wsi); if(msgqueue[wsi].size() > 0) { std::string msg = msgqueue[wsi].front(); msgqueue[wsi].pop(); @@ -108,6 +119,9 @@ int callback_lws_task(struct libwebsocket_context * context, exit(1); } } + else { + printf("\tNo queued data awaiting transmission\n"); + } if(msgqueue[wsi].size()) { libwebsocket_rx_flow_control(wsi, 1); @@ -134,7 +148,7 @@ int callback_lws_task(struct libwebsocket_context * context, MessageList mlst = parse_msg(data); printf("Handling %d incoming message\n", mlst.size()); - MessageList omsgs = handle_msg(mlst); + MessageList omsgs = handle_msg(mlst, wsi); printf("Handling %d outgoing messages\n", omsgs.size()); MessageList::iterator omi = omsgs.begin(); @@ -152,6 +166,8 @@ int callback_lws_task(struct libwebsocket_context * context, std::set<clientid_t>::iterator ci = clients.begin(); while(ci != clients.end()) { + clientid_t clientid = *ci; + printf("\tAdding data to %p's queue\n", clientid); msgqueue[*ci].push(msg); ci++; } diff --git a/src/task_proto.h b/src/munia_proto.h index 160dee9..db10c16 100644 --- a/src/task_proto.h +++ b/src/munia_proto.h @@ -1,7 +1,7 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** - * task_proto.h + * munia_proto.h * * Fri Feb 24 08:23:15 CET 2012 * Copyright 2012 Bent Bisballe Nyeng @@ -25,8 +25,8 @@ * along with Munia; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __MUNIA_TASK_PROTO_H__ -#define __MUNIA_TASK_PROTO_H__ +#ifndef __MUNIA_MUNIA_PROTO_H__ +#define __MUNIA_MUNIA_PROTO_H__ #include <stdlib.h> @@ -41,4 +41,4 @@ struct per_session_data__lws_task { struct libwebsocket *wsi; }; -#endif/*__MUNIA_TASK_PROTO_H__*/ +#endif/*__MUNIA_MUNIA_PROTO_H__*/ diff --git a/src/muniad.cc b/src/muniad.cc index 2307160..34f5c6a 100644 --- a/src/muniad.cc +++ b/src/muniad.cc @@ -36,8 +36,7 @@ #include <libwebsockets.h> #include "http.h" -#include "task_proto.h" -#include "observe_proto.h" +#include "munia_proto.h" #include "debug.h" static struct libwebsocket_protocols protocols[] = { @@ -46,9 +45,6 @@ static struct libwebsocket_protocols protocols[] = { { "lws-task-protocol", callback_lws_task, sizeof(struct per_session_data__lws_task) }, - { "lws-observe-protocol", callback_lws_observe, - sizeof(struct per_session_data__lws_observe) - }, { NULL, NULL, 0 } // End of list }; diff --git a/src/observe_proto.cc b/src/observe_proto.cc deleted file mode 100644 index e8f78de..0000000 --- a/src/observe_proto.cc +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * observe_proto.cc - * - * Fri Mar 23 15:29:13 CET 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 "observe_proto.h" - -#include <stdio.h> -#include <string.h> - -#include <queue> -#include <map> - -#include "task.h" -#include "messageparser.h" - -#include "connectionhandler.h" - -int callback_lws_observe(struct libwebsocket_context *context, - struct libwebsocket *wsi, - enum libwebsocket_callback_reasons reason, - void *user, void *in, size_t len) -{ - switch (reason) { - case LWS_CALLBACK_ESTABLISHED: - connection_handler.init(wsi); - break; - - case LWS_CALLBACK_CLOSED: - connection_handler.close(wsi); - break; - - case LWS_CALLBACK_RECEIVE: - { - std::string data; - data.append((char*)in, len); - - MessageList mlst = parse_msg(data); - for(MessageList::iterator i = mlst.begin(); i != mlst.end(); i++) { - message_t m = *i; - switch(m.cmd) { - case cmd::observe: { - connection_handler.observe(wsi, m.observe.id); - break; - } - case cmd::unobserve: { - connection_handler.unobserve(wsi, m.observe.id); - break; - } - default: - printf("Wrong command :(\n"); - break; - } - } - } - break; - - default: - break; - } - - return 0; -} diff --git a/src/observe_proto.h b/src/observe_proto.h deleted file mode 100644 index 6ef1e66..0000000 --- a/src/observe_proto.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - * observe_proto.h - * - * Fri Mar 23 15:29:13 CET 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_OBSERVE_PROTO_H__ -#define __MUNIA_OBSERVE_PROTO_H__ - -#include <stdlib.h> - -#include <libwebsockets.h> - -int callback_lws_observe(struct libwebsocket_context *context, - struct libwebsocket *wsi, - enum libwebsocket_callback_reasons reason, - void *user, void *in, size_t len); - -struct per_session_data__lws_observe { - struct libwebsocket *wsi; -}; - -#endif/*__MUNIA_OBSERVE_PROTO_H__*/ |