summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/connectionhandler.cc24
-rw-r--r--src/connectionhandler.h3
-rw-r--r--src/messagehandler.cc15
-rw-r--r--src/munia_proto.cc5
-rw-r--r--src/taskmanager.cc3
-rw-r--r--src/taskmanager.h2
6 files changed, 28 insertions, 24 deletions
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 <stdio.h>
+// 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<std::pair<clientid_t, taskid_t> >
-ConnectionHandler::observerlist(TaskIdList tasks)
+ObserverList ConnectionHandler::observerlist(TaskIdList tasks)
{
printf("Observerlist request\n");
- std::list<std::pair<clientid_t, taskid_t> > clients;
+ ObserverList 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();
@@ -118,7 +118,7 @@ h.observe((clientid_t)3, (taskid_t)3);
{
TaskIdList tasks;
tasks.push_back((taskid_t)1);
- std::set<clientid_t> 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<clientid_t> 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<clientid_t> 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<clientid_t> 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<clientid_t> 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<clientid_t> 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<clientid_t> 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<clientid_t, std::set<taskid_t> > ConnectionList;
+typedef std::list<std::pair<clientid_t, taskid_t> > ObserverList;
class ConnectionHandler {
public:
@@ -50,7 +51,7 @@ public:
void unobserve(clientid_t clientid, taskid_t taskid);
- std::list<std::pair<clientid_t, taskid_t> > 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 <stdio.h>
+// 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
/*