From e3c0c95f2ad3d25411c007ce4ffdb25084a1bc0d Mon Sep 17 00:00:00 2001 From: Jonas Suhr Christensen Date: Thu, 12 Apr 2012 15:12:18 +0200 Subject: Added observer id as prefix to server->client commands. --- src/connectionhandler.cc | 15 ++++++++++++--- src/connectionhandler.h | 3 ++- src/munia_proto.cc | 23 +++++++++++++++-------- src/tasktree.cc | 27 +++++++++++++++++++++++---- 4 files changed, 52 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index 85ae4a7..56c465f 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -65,18 +65,27 @@ void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid) connlist[clientid].erase(taskid); } -std::set ConnectionHandler::observerlist(TaskIdList tasks) +std::list > +ConnectionHandler::observerlist(TaskIdList tasks) { printf("Observerlist request\n"); - std::set clients; + std::list > 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(); ci != connlist.end(); ci++) { std::set::iterator ti = ci->second.find(tid); - if(ti != ci->second.end()) clients.insert(ci->first); + if(ti != ci->second.end()) { + std::pair m; + m.first = ci->first; + m.second = tid; + clients.push_back(m); + } } } diff --git a/src/connectionhandler.h b/src/connectionhandler.h index 464128b..b09e944 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -49,7 +49,8 @@ public: void observe(clientid_t clientid, taskid_t taskid); void unobserve(clientid_t clientid, taskid_t taskid); - std::set observerlist(TaskIdList tasklist); + + std::list > observerlist(TaskIdList tasklist); private: ConnectionList connlist; diff --git a/src/munia_proto.cc b/src/munia_proto.cc index 3679a81..b801009 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -153,22 +153,29 @@ int callback_lws_task(struct libwebsocket_context * context, MessageList::iterator omi = omsgs.begin(); while(omi != omsgs.end()) { - std::string msg; - msg.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' '); - msg.append(msg_tostring(*omi)); - msg.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' '); + std::string msgcmd = msg_tostring(*omi); printf("%d nodes affected by command\n", omi->nodes.size()); - std::set clients = + std::list > clients = connection_handler.observerlist(omi->nodes); printf("Writing message to %d clients\n", clients.size()); - std::set::iterator ci = clients.begin(); + std::list >::iterator ci = clients.begin(); while(ci != clients.end()) { - clientid_t clientid = *ci; + std::string msg; + clientid_t clientid = (*ci).first; + char tidstr[32]; + sprintf(tidstr, "%u", (*ci).second); printf("\tAdding data to %p's queue\n", clientid); - msgqueue[*ci].push(msg); + + msg.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' '); + msg.append(tidstr); + msg.append(" "); + msg.append(msgcmd); + msg.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' '); + + msgqueue[clientid].push(msg); ci++; } diff --git a/src/tasktree.cc b/src/tasktree.cc index 0df23d6..3a72046 100644 --- a/src/tasktree.cc +++ b/src/tasktree.cc @@ -29,6 +29,13 @@ #include "debug.h" +static void concatTaskIdLists(TaskIdList& pre, TaskIdList& post) { + pre.insert(pre.end(), post.begin(), post.end()); + // for(TaskIdList::iterator it = post.begin(); + // it != post.end(); it++) { + // pre.push_back( + // } +} TaskTree::TaskTree() { root = NULL; @@ -60,9 +67,11 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data) child->data = data; insertChild(parent, child); - affectedNodes.push_back(parentid); + // affectedNodes.push_back(parentid); affectedNodes.push_back(id); - + TaskIdList ancestors = ancestorList(id); + concatTaskIdLists(affectedNodes, ancestors); + goto finish; } catch(std::exception& e) { @@ -112,8 +121,11 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid) newparent->children.push_back(child); affectedNodes.push_back(id); - affectedNodes.push_back(child->parent->id); - affectedNodes.push_back(toid); + // affectedNodes.push_back(child->parent->id); + TaskIdList ancestors = ancestorList(id); + concatTaskIdLists(affectedNodes, ancestors); + affectedNodes.push_back(toid); + ancestors = ancestorList(toid); goto finish; } @@ -135,6 +147,8 @@ TaskIdList TaskTree::updateData(taskid_t id, task_t t) node->data = t; affectedNodes.push_back(id); + TaskIdList ancestors = ancestorList(id); + concatTaskIdLists(affectedNodes, ancestors); goto finish; } catch(std::exception& e) { @@ -181,6 +195,11 @@ TaskIdList TaskTree::ancestorList(taskid_t id) } finish: + printf("Collected %d ancestors to %u\n", ancestors.size(), id); + for(TaskIdList::iterator it = ancestors.begin(); + it != ancestors.end(); it++) { + printf("\tancestor %u\n", *it); + } return ancestors; } -- cgit v1.2.3