diff options
-rw-r--r-- | src/connectionhandler.cc | 15 | ||||
-rw-r--r-- | src/connectionhandler.h | 3 | ||||
-rw-r--r-- | src/munia_proto.cc | 23 | ||||
-rw-r--r-- | src/tasktree.cc | 27 |
4 files changed, 52 insertions, 16 deletions
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<clientid_t> ConnectionHandler::observerlist(TaskIdList tasks) +std::list<std::pair<clientid_t, taskid_t> > +ConnectionHandler::observerlist(TaskIdList tasks) { printf("Observerlist request\n"); - std::set<clientid_t> clients; + std::list<std::pair<clientid_t, taskid_t> > clients; for(TaskIdList::iterator i = tasks.begin(); i != tasks.end(); i++) { taskid_t tid = *i; + // std::set<clientid_t> clientList; + // std::map<clientid_t, taskid_t> + printf("Locating observers of node %d\n", tid); for(ConnectionList::iterator ci = connlist.begin(); ci != connlist.end(); ci++) { std::set<taskid_t>::iterator ti = ci->second.find(tid); - if(ti != ci->second.end()) clients.insert(ci->first); + if(ti != ci->second.end()) { + std::pair<clientid_t, taskid_t> 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<clientid_t> observerlist(TaskIdList tasklist); + + std::list<std::pair<clientid_t, taskid_t> > 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<clientid_t> clients = + std::list<std::pair<clientid_t, taskid_t> > clients = connection_handler.observerlist(omi->nodes); printf("Writing message to %d clients\n", clients.size()); - std::set<clientid_t>::iterator ci = clients.begin(); + std::list<std::pair<clientid_t, taskid_t> >::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; } |