summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-01-10 15:51:33 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2013-01-10 15:51:33 +0100
commitd935b195a2246fa24d35df7c6fc354ae628a6777 (patch)
treec739e709ad3898df094d6779e50eaefa4f9cf82c
parent93415d809989afc341472ea598579c924dc1e745 (diff)
Added attributes to nodes as well as messages for manipulating and transporting them. Switched debug interface to hugin.
-rw-r--r--proto.js16
-rw-r--r--src/Makefile.am30
-rw-r--r--src/connectionhandler.cc16
-rw-r--r--src/debug.cc253
-rw-r--r--src/debug.h133
-rw-r--r--src/log.cc43
-rw-r--r--src/log.h38
-rw-r--r--src/message.h17
-rw-r--r--src/messagehandler.cc15
-rw-r--r--src/messageparser.cc50
-rw-r--r--src/messageparser.h4
-rw-r--r--src/munia_proto.cc19
-rw-r--r--src/muniad.cc5
-rw-r--r--src/saxparser.cc3
-rw-r--r--src/task.h4
-rw-r--r--src/taskmanager.cc29
-rw-r--r--src/taskmanager.h9
-rw-r--r--src/tasktree.cc63
-rw-r--r--src/tasktree.h5
-rw-r--r--src/xmlparser.cc8
-rw-r--r--src/xmlparser.h1
21 files changed, 170 insertions, 591 deletions
diff --git a/proto.js b/proto.js
index 0630bbf..b382a75 100644
--- a/proto.js
+++ b/proto.js
@@ -208,13 +208,15 @@ try {
}
}
else if(cmd == "update") {
- var title = msg[3];
- //var task = document.getElementById(createId(observeid, id));
- var txtdiv = document.getElementById(createId(observeid, id) + "_txt");
- txtdiv.removeChild(txtdiv.firstChild);
-
- var txt = document.createTextNode(title);
- txtdiv.appendChild(txt);
+ var name = msg[3];
+ var value = msg[4];
+ if(name == "title") {
+ var txtdiv = document.getElementById(createId(observeid, id) + "_txt");
+ txtdiv.removeChild(txtdiv.firstChild);
+
+ var txt = document.createTextNode(value);
+ txtdiv.appendChild(txt);
+ }
}
f++;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index c256f54..996849e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,16 +1,16 @@
SUBDIRS =
-bin_PROGRAMS = muniad muniacli
+bin_PROGRAMS = muniad
+# muniacli
muniad_LDADD = $(LIBWEBSOCKETS_LIBS) $(EXPAT_LIBS)
-muniad_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS) $(EXPAT_CFLAGS) -I/usr/local/include
+muniad_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS) $(EXPAT_CFLAGS) -I../hugin \
+ -I/usr/local/include
muniad_SOURCES = \
muniad.cc \
connectionhandler.cc \
- debug.cc \
- log.cc \
http.cc \
messagehandler.cc \
messageparser.cc \
@@ -21,20 +21,19 @@ muniad_SOURCES = \
tasktree.cc \
testclient.cc \
xml_encode_decode.cc \
- xmlparser.cc
+ xmlparser.cc \
+ ../hugin/hugin.c
-muniacli_LDADD = $(LIBWEBSOCKETS_LIBS)
-
-muniacli_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS)
-
-muniacli_SOURCES = \
- messageparser.cc \
- muniacli.cc
+#muniacli_LDADD = $(LIBWEBSOCKETS_LIBS)
+#
+#muniacli_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS)
+#
+#muniacli_SOURCES = \
+# messageparser.cc \
+# muniacli.cc
EXTRA_DIST = \
- debug.h \
connectionhandler.h \
- log.h \
http.h \
message.h \
messageparser.h \
@@ -46,7 +45,8 @@ EXTRA_DIST = \
tasktree.h \
testclient.h \
xml_encode_decode.h \
- xmlparser.h
+ xmlparser.h \
+ ../hugin/hugin.h
################
# Test Section #
diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc
index da94cb8..d78c053 100644
--- a/src/connectionhandler.cc
+++ b/src/connectionhandler.cc
@@ -29,6 +29,8 @@
#include <stdio.h>
+#include "hugin.hpp"
+
// Global ConnectionHandler.
ConnectionHandler connection_handler;
@@ -38,26 +40,26 @@ ConnectionHandler::ConnectionHandler()
void ConnectionHandler::init(clientid_t clientid)
{
- printf("Adding client %p to connection list\n", clientid);
+ DEBUG(conn, "Adding client %p to connection list\n", clientid);
connlist[clientid] = std::set<taskid_t>();
- printf("Connections (%d):\n", connlist.size());
+ DEBUG(conn, "Connections (%d):\n", connlist.size());
ConnectionList::iterator it;
for(it = connlist.begin(); it != connlist.end(); it++) {
- printf("\t%p\n", it->first);
+ DEBUG(conn, "\t%p\n", it->first);
}
}
void ConnectionHandler::close(clientid_t clientid)
{
connlist.erase(clientid);
- printf("Removed connection\n");
+ DEBUG(conn, "Removed connection\n");
}
void ConnectionHandler::observe(clientid_t clientid, taskid_t taskid)
{
connlist[clientid].insert(taskid);
- printf("Added observer of %d\n", taskid);
+ DEBUG(conn, "Added observer of %d\n", taskid);
}
void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid)
@@ -67,13 +69,13 @@ void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid)
ObserverList ConnectionHandler::observerlist(TaskIdList tasks)
{
- printf("Observerlist request (#tasks: %d)\n", tasks.size());
+ DEBUG(conn, "Observerlist request (#tasks: %d)\n", tasks.size());
ObserverList clients;
for(TaskIdList::iterator i = tasks.begin(); i != tasks.end(); i++) {
taskid_t tid = *i;
- printf("Locating observers of node %d\n", tid);
+ DEBUG(conn, "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);
diff --git a/src/debug.cc b/src/debug.cc
deleted file mode 100644
index c68ce2d..0000000
--- a/src/debug.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set et sw=2 ts=2: */
-/***************************************************************************
- * debug.cc
- *
- * Wed Feb 11 11:22:12 CET 2009
- * Copyright 2009 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro 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.
- *
- * Pracro 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 Pracro; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "debug.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-
-#include <string>
-
-#include "log.h"
-
-static FILE *logfp = stderr;
-
-#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
-struct __debug_channel
-{
- char name[32];
- unsigned flags;
-};
-
-static const char * const debug_class_str[] =
- { "fixme", "err", "warn", "info", "debug" };
-
-#define __DEBUG_CHANNEL_MAX 256
-
-static struct __debug_channel debug_channel[__DEBUG_CHANNEL_MAX];
-static unsigned n_debug_channel = 0;
-static unsigned debug_flags = (1 << __class_err) | (1 << __class_fixme);
-
-static int __debug_enabled(const enum __debug_class cl, const char *ch)
-{
- unsigned i;
- for(i = 0; i < n_debug_channel; i++) {
- if(!strcmp(ch, debug_channel[i].name)) {
- return (debug_channel[i].flags & (1 << cl)) != 0;
- }
- }
- return debug_flags & (1 << cl);
-}
-
-
-#ifdef WITH_DEBUG
-int __debug(const char *func, const int line,
- const enum __debug_class cl,
- const char *ch, const char *fmt, ...)
-{
- int ret = 0;
- if(__debug_enabled(cl, ch)) {
- if((unsigned)cl < NELEM(debug_class_str))
- ret += fprintf(logfp, "%s:%s:%s:%d ",
- debug_class_str[(unsigned)cl], ch, func, line);
- if(fmt) {
- va_list va;
- va_start(va, fmt);
- ret += vfprintf(logfp, fmt, va);
- va_end(va);
- }
- }
- if(ret){
- fflush(logfp);
- }
- return ret;
-}
-
-int __debug_va(const char *func, const int line,
- const enum __debug_class cl,
- const char *ch, const char *fmt, va_list va)
-{
- int ret = 0;
- if(__debug_enabled(cl, ch)) {
- if((unsigned)cl < NELEM(debug_class_str))
- ret += fprintf(logfp, "%s:%s:%s:%d ",
- debug_class_str[(unsigned)cl], ch, func, line);
- if(fmt)
- ret += vfprintf(logfp, fmt, va);
- }
- if(ret) {
- fflush(logfp);
- }
- return ret;
-}
-
-#endif
-
-int __log(const char *func, const int line, const enum __debug_class cl,
- const char *ch, const char *fmt, ...)
-{
- std::string logmsg;
- char str[8];
-
-#ifdef WITH_DEBUG
- int ret = 0;
-#endif
- if(__debug_enabled(cl, ch)) {
- if((unsigned)cl < NELEM(debug_class_str))
- if((unsigned)cl < NELEM(debug_class_str))
-#ifdef WITH_DEBUG
- ret = fprintf(logfp, "%s:%s:%s:%d ", debug_class_str[(unsigned)cl], ch, func, line);
-#endif
- sprintf(str, "%d", line);
- logmsg = std::string(debug_class_str[(unsigned)cl]) + ":" + ch + ":" + func + ":" + str;
- if(fmt) {
- va_list va;
- va_start(va, fmt);
-#ifdef WITH_DEBUG
- ret += vfprintf(logfp, fmt, va);
-#endif
- char* ptr;
- if(vasprintf(&ptr, fmt, va) == -1) {}
- logmsg += ptr;
- va_end(va);
- }
- }
-#ifdef WITH_DEBUG
- if(ret) {
- fprintf(logfp, "\n");
- fflush(logfp);
- }
-#endif
- log(logmsg);
- return logmsg.size();
-}
-
-int __log_va(const char *func, const int line, const enum __debug_class cl,
- const char *ch, const char *fmt, va_list va)
-{
- std::string logmsg;
- char str[8];
-#ifdef WITH_DEBUG
- int ret = 0;
-#endif
- if(__debug_enabled(cl, ch)) {
- if((unsigned)cl < NELEM(debug_class_str))
-#ifdef WITH_DEBUG
- ret = fprintf(logfp, "%s:%s:%s:%d ", debug_class_str[(unsigned)cl], ch, func, line);
-#endif
- sprintf(str, "%d", line);
- logmsg = std::string(debug_class_str[(unsigned)cl]) + ":" + ch + ":" + func + ":" + str;
- if(fmt) {
-#ifdef WITH_DEBUG
- ret += vfprintf(logfp, fmt, va);
-#endif
- char* ptr;
- if(vasprintf(&ptr, fmt, va) == -1) {}
- logmsg += ptr;
- }
- }
-#ifdef WITH_DEBUG
- if(ret) {
- fprintf(logfp, "\n");
- fflush(logfp);
- }
-#endif
- return logmsg.size();
-}
-
-void debug_init(FILE *fp)
-{
- logfp = fp;
-}
-
-
-/*
- * fmt := [set[,set]*]*
- * set := [+-]channel
- * | class[+-]channel
- * | [+-]all
- */
-void debug_parse(const char *fmt)
-{
- char *s;
- char *next;
- char *opt;
-
- if(!(s = strdup(fmt))) return;
-
- for(opt = s; opt; opt = next) {
- int set = 0;
- int clr = 0;
- unsigned i;
- if((next = strchr(opt, ','))) *next++ = '\0';
- char *p = opt + strcspn(opt, "+-");
- if(!*p) p = opt; // All chars -> a channel name
- if(p > opt) {
- // we have a class
- for(i = 0; i < NELEM(debug_class_str); i++) {
- int n = strlen(debug_class_str[i]);
- if(n != (p - opt)) continue;
- if(!memcmp(opt, debug_class_str[i], n)) {
- // Found the class
- if(*p == '+')
- set = 1 << i;
- else
- clr = 1 << i;
- break;
- }
- }
- if(i == NELEM(debug_class_str)) continue;
- } else {
- if(*p == '-')
- clr = ~0;
- else
- set = ~0;
- }
- if(*p == '+' || *p == '-') p++;
- if(!*p) continue;
- if(!strcmp("all", p)) {
- debug_flags = (debug_flags & ~clr) | set;
- } else {
- if(strlen(p) >= sizeof(debug_channel[0].name)) continue;
- for(i = 0; i < n_debug_channel; i++) {
- if(!strcmp(p, debug_channel[i].name)) {
- debug_channel[i].flags = (debug_channel[i].flags & ~clr) | set;
- break;
- }
- }
- if(i == n_debug_channel && n_debug_channel < __DEBUG_CHANNEL_MAX) {
- strcpy(debug_channel[i].name, p);
- debug_channel[i].flags = (debug_flags & ~clr) | set;
- n_debug_channel++;
- }
- }
- }
- free(s);
-}
-
diff --git a/src/debug.h b/src/debug.h
deleted file mode 100644
index a5f199d..0000000
--- a/src/debug.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set et sw=2 ts=2: */
-/***************************************************************************
- * debug.h
- *
- * Wed Feb 11 11:22:12 CET 2009
- * Copyright 2009 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Pracro.
- *
- * Pracro 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.
- *
- * Pentominos 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 Pentominos; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#ifndef __PENTOMINOS_DEBUG_H__
-#define __PENTOMINOS_DEBUG_H__
-
-#include <stdarg.h>
-#include <stdio.h>
-
-#ifdef HAVE_CONFIG_H
-// For USE_EFENCE
-#include <config.h>
-#ifdef USE_EFENCE
-#include <new>
-#include <stdlib.h>
-#include <efencepp.h>
-#include <efence.h>
-
-// Lazy static alocations makes efence freak out.
-// Use this to use hardcoded values instead.
-// Currently it disables:
-// - gethostbyname
-// - getsockname
-// - getpeername
-// - iconv
-//#define BYPASS_STATICALLOCATIONS
-
-#endif/*USE_EFENCE*/
-#endif/*HAVE_CONFIG*/
-
-void debug_init(FILE *fp);
-void debug_parse(const char *fmt);
-
-enum __debug_class
-{
- __class_fixme = 0,
- __class_err = 1,
- __class_warn = 2,
- __class_info = 3,
- __class_debug = 4
-};
-
-#ifdef WITH_DEBUG
-int __debug(const char *func, const int line, enum __debug_class cl,
- const char *ch, const char *fmt, ...)
- __attribute__((format (printf,5,6)));
-
-int __debug_va(const char *func, const int line, enum __debug_class cl,
- const char *ch, const char *fmt, va_list va);
-
-#define __DEBUG_PRINT(cl, ch, fmt...) \
- do { __debug(__func__, __LINE__, cl, ch, fmt); } while(0)
-#define __DEBUG_PRINT_VA(cl, ch, fmt, a) \
- do { __debug_va(__func__, __LINE__, cl, ch, fmt, a); } while(0)
-#define __DEBUG(cl, ch, fmt...) \
- __DEBUG_PRINT(__class##cl, #ch, fmt)
-#define __DEBUG_VA(cl, ch, fmt, a) \
- __DEBUG_PRINT_VA(__class##cl, #ch, fmt, a)
-
-#define FIXME(ch, fmt...) __DEBUG(_fixme, ch, fmt)
-#define ERR(ch, fmt...) __DEBUG(_err, ch, fmt)
-#define WARN(ch, fmt...) __DEBUG(_warn, ch, fmt)
-#define INFO(ch, fmt...) __DEBUG(_info, ch, fmt)
-#define DEBUG(ch, fmt...) __DEBUG(_debug, ch, fmt)
-
-#define FIXME_VA(ch, fmt, a) __DEBUG_VA(_fixme, ch, fmt, a)
-#define ERR_VA(ch, fmt, a) __DEBUG_VA(_err, ch, fmt, a)
-#define WARN_VA(ch, fmt, a) __DEBUG_VA(_warn, ch, fmt, a)
-#define INFO_VA(ch, fmt, a) __DEBUG_VA(_info, ch, fmt, a)
-#define DEBUG_VA(ch, fmt, a) __DEBUG_VA(_debug, ch, fmt, a)
-
-#else
-
-// If we compile without debug support, we want them all to go away
-#define FIXME(ch, fmt...)
-#define INFO(ch, fmt...)
-#define WARN(ch, fmt...)
-#define ERR(ch, fmt...)
-#define DEBUG(ch, fmt...)
-#define FIXME_VA(ch, fmt...)
-#define INFO_VA(ch, fmt...)
-#define WARN_VA(ch, fmt...)
-#define ERR_VA(ch, fmt...)
-#define DEBUG_VA(ch, fmt...)
-
-#endif/*WITH_DEBUG*/
-
-int __log(const char *func, const int line,
- enum __debug_class cl, const char *ch, const char *fmt, ...)
- __attribute__((format (printf,5,6)));
-
-int __log_va(const char *func, const int line, enum __debug_class cl,
- const char *ch, const char *fmt, va_list va);
-
-#define __LOG_PRINT(cl, ch, fmt...) \
- do { __log(__func__, __LINE__, cl, ch, fmt); } while(0)
-#define __LOG_PRINT_VA(cl, ch, fmt, a) \
- do { __log_va(__func__, __LINE__, cl, ch, fmt, a); } while(0)
-#define __LOG(cl, ch, fmt...) __LOG_PRINT(__class##cl, #ch, fmt)
-#define __LOG_VA(cl, ch, fmt, a) __LOG_PRINT_VA(__class##cl, #ch, fmt, a)
-
-#define INFO_LOG(ch, fmt...) __LOG(_info, ch, fmt)
-#define WARN_LOG(ch, fmt...) __LOG(_warn, ch, fmt)
-#define ERR_LOG(ch, fmt...) __LOG(_err, ch, fmt)
-#define INFO_LOG_VA(ch, fmt, a) __LOG_VA(_info, ch, fmt, a)
-#define WARN_LOG_VA(ch, fmt, a) __LOG_VA(_warn, ch, fmt, a)
-#define ERR_LOG_VA(ch, fmt, a) __LOG_VA(_err, ch, fmt, a)
-
-#endif/*__PENTOMINOS_DEBUG_H__*/
diff --git a/src/log.cc b/src/log.cc
deleted file mode 100644
index fe72422..0000000
--- a/src/log.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * log.cc
- *
- * Tue Oct 24 17:44:47 CEST 2006
- * Copyright 2006 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Artefact.
- *
- * Artefact 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.
- *
- * Artefact 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 Artefact; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#include "log.h"
-
-#include "debug.h"
-
-#include <syslog.h>
-
-/*
- void openlog(const char *ident, int option, int facility); // Optional
- void syslog(int priority, const char *format, ...);
- void closelog(void); // Optional
-*/
-
-void log(std::string message)
-{
- syslog(LOG_CONS, // Write to console if error sending to system logger.
- "%s", message.c_str());
-}
diff --git a/src/log.h b/src/log.h
deleted file mode 100644
index 14a5585..0000000
--- a/src/log.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * log.h
- *
- * Tue Oct 24 17:44:46 CEST 2006
- * Copyright 2006 Bent Bisballe Nyeng
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * This file is part of Artefact.
- *
- * Artefact 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.
- *
- * Artefact 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 Artefact; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-#ifndef __ARTEFACT_LOG_H__
-#define __ARTEFACT_LOG_H__
-
-#include <string>
-
-/**
- * log appends a message to the syslog queue.\n
- * @param message An STL string containing the string to be appended.
- */
-void log(std::string message);
-
-#endif/*__ARTEFACT_LOG_H__*/
diff --git a/src/message.h b/src/message.h
index 383fa73..92e58ac 100644
--- a/src/message.h
+++ b/src/message.h
@@ -69,21 +69,20 @@ typedef struct {
typedef struct {
taskid_t id;
- char title[256];
+ std::string name;
+ std::string value;
} update_t;
typedef struct {
cmd::cmd_t cmd;
- union {
- observe_t observe;
- unobserve_t unobserve;
- create_t create;
- remove_t remove;
- move_t move;
- update_t update;
- };
+ observe_t observe;
+ unobserve_t unobserve;
+ create_t create;
+ remove_t remove;
+ move_t move;
+ update_t update;
TaskIdList nodes;
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index fbe2237..0178d76 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -26,7 +26,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "messagehandler.h"
-#include "debug.h"
+
+#include "hugin.hpp"
// Defines global task_manager object
#include "taskmanager.h"
@@ -73,7 +74,6 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
outmsgs.push_back(m);
id++;
- printf("!!!\n");
}
}
catch (std::exception& e) {
@@ -87,7 +87,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
INFO(messagehandler, "Handling move command\n");
try {
task_t removetask = task_manager.task(m.move.id);
- TaskIdListPair tilpair = task_manager.moveTask(m.move.id, m.move.parentid);
+ TaskIdListPair tilpair =
+ task_manager.moveTask(m.move.id, m.move.parentid);
task_t createtask = task_manager.task(m.move.id);
/*
@@ -154,10 +155,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
{
INFO(messagehandler, "Handling update command\n");
try {
- task_t t;
- t.title = m.update.title;
- t.id = m.update.id;
- m.nodes = task_manager.updateTask(m.update.id, t);
+ m.nodes = task_manager.updateTask(m.update.id,
+ m.update.name, m.update.value);
outmsgs.push_back(m);
}
catch (std::exception& e) {
@@ -170,7 +169,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
break;
}
task_manager.tree.toStdOut();
- printf("%d affected nodes registered\n", m.nodes.size());
+ DEBUG(messagehandler, "%d affected nodes registered\n", m.nodes.size());
}
return outmsgs;
diff --git a/src/messageparser.cc b/src/messageparser.cc
index 1aba5ee..9e5e7ab 100644
--- a/src/messageparser.cc
+++ b/src/messageparser.cc
@@ -26,11 +26,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "messageparser.h"
+#include "taskmanager.h"
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include <vector>
+#include <map>
+
+#include "hugin.hpp"
typedef std::vector<std::string> TokenVector;
typedef std::list<TokenVector> MsgTokensList;
@@ -54,12 +58,12 @@ inline static void parse_into_msg_tokens(std::string& data,
break;
case ' ':
if(inside_quote) {
- //printf("Appending %c\n", ch);
+ //DEBUG(msgparser, "Appending %c\n", ch);
token += ch;
}
else {
if(token.empty()) continue; // skip multiple white spaces and pre white space
-// printf("Adding token %s\n", token.c_str());
+// DEBUG(msgparser, "Adding token %s\n", token.c_str());
tokenVector.push_back(token);
token.clear();
}
@@ -92,8 +96,7 @@ inline static void parse_into_msg_tokens(std::string& data,
tokenVector.clear();
}
}
-#include <map>
-static taskid_t baseid = 10000;
+
static taskid_t getId(std::map<std::string, taskid_t> &sym, std::string token)
{
bool isnumeric = true;
@@ -103,7 +106,7 @@ static taskid_t getId(std::map<std::string, taskid_t> &sym, std::string token)
if(isnumeric) return atoi(token.c_str());
- if(sym.find(token) == sym.end()) sym[token] = baseid++;
+ if(sym.find(token) == sym.end()) sym[token] = task_manager.createId();
return sym[token];
}
@@ -126,9 +129,9 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
message_t m;
- printf("t[%d] : %s, running in clientmode: %d\n", origin, t[origin].c_str(), clientmode);
+ DEBUG(msgparser, "t[%d] : %s, running in clientmode: %d\n", origin, t[origin].c_str(), clientmode);
-// printf("%d\n", t.size());
+// DEBUG(msgparser, "%d\n", t.size());
if(t[origin] == "observe") m.cmd = cmd::observe;
else if(t[origin] == "unobserve") m.cmd = cmd::unobserve;
@@ -138,12 +141,12 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
else if(t[origin] == "update") m.cmd = cmd::update;
else m.cmd = cmd::error;
-// printf("Number of tokens %d\n", t.size());
+// DEBUG(msgparser, "Number of tokens %d\n", t.size());
switch(m.cmd) {
case cmd::observe: {
if(t.size() != origin+1+1) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
m.observe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
@@ -151,7 +154,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
case cmd::unobserve: {
if(t.size() != origin+1+1) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
m.unobserve.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
@@ -159,11 +162,11 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
case cmd::create: {
if(!clientmode && t.size() != origin+1+2) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
if(clientmode && t.size() != origin+1+2) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
if(clientmode) {
@@ -178,7 +181,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
case cmd::remove: {
if(t.size() != origin+1+1) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
m.remove.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
@@ -186,7 +189,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
case cmd::move: {
if(t.size() != origin+2+1) {
- printf("Wrong number of parameters\n");
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
m.move.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
@@ -194,12 +197,13 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
break;
}
case cmd::update: {
- if(t.size() != origin+2+1) {
- printf("Wrong number of parameters\n");
+ if(t.size() != origin+3+1) {
+ DEBUG(msgparser, "Wrong number of parameters\n");
continue;
}
m.update.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str());
- sprintf(m.update.title, "%s", t[origin+2].c_str());
+ m.update.name = t[origin+2];
+ m.update.value = t[origin+3];
break;
}
default:
@@ -210,7 +214,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList,
}
MessageList parse_msg(std::string data) {
- printf("Parsing: %s\n", data.c_str());
+ DEBUG(msgparser, "Parsing: %s\n", data.c_str());
MsgTokensList msgTokensList;
parse_into_msg_tokens(data, msgTokensList);
@@ -222,7 +226,7 @@ MessageList parse_msg(std::string data) {
}
MessageList parse_msg_client(std::string data) {
- printf("Parsing: \n%s\n", data.c_str());
+ DEBUG(msgparser, "Parsing: \n%s\n", data.c_str());
MsgTokensList msgTokensList;
parse_into_msg_tokens(data, msgTokensList);
@@ -250,7 +254,8 @@ std::string msg_tostring(message_t m) {
break;
}
case cmd::update: {
- asprintf(&buf, "update %d \"%s\";", m.update.id, m.update.title);
+ asprintf(&buf, "update %d \"%s\" \"%s\";",
+ m.update.id, m.update.name.c_str(), m.update.value.c_str());
break;
};
default:
@@ -274,11 +279,12 @@ message_t create_msg_create(task_t t) {
return m;
}
-message_t create_msg_update(task_t t) {
+message_t create_msg_update(task_t t, const std::string &attr) {
message_t m;
m.cmd = cmd::update;
m.update.id = t.id;
- sprintf(m.update.title, "%s", t.title.c_str());
+ m.update.name = attr;
+ m.update.value = t.attributes[attr];
return m;
}
diff --git a/src/messageparser.h b/src/messageparser.h
index 95208f2..4cbacfa 100644
--- a/src/messageparser.h
+++ b/src/messageparser.h
@@ -30,6 +30,8 @@
#include "message.h"
+#include <string>
+
MessageList parse_msg(std::string msg);
MessageList parse_msg_client(std::string msg);
@@ -37,7 +39,7 @@ MessageList parse_msg_client(std::string msg);
std::string msg_tostring(message_t msg);
message_t create_msg_create(task_t task);
-message_t create_msg_update(task_t task);
+message_t create_msg_update(task_t task, const std::string &attr);
message_t create_msg_remove(task_t task);
message_t create_msg_move(taskid_t id, taskid_t to);
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index 6a165db..977bf60 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -33,7 +33,7 @@
#include <queue>
#include <map>
-#include "debug.h"
+#include "hugin.hpp"
#include "task.h"
#include "messageparser.h"
@@ -94,7 +94,7 @@ int callback_lws_task(struct libwebsocket_context * context,
{
task_manager.tree.toStdOut();
- printf("Callback on %p\n", wsi);
+ DEBUG(proto, "Callback on %p\n", wsi);
switch (reason) {
case LWS_CALLBACK_ESTABLISHED:
@@ -187,7 +187,7 @@ int callback_lws_task(struct libwebsocket_context * context,
current_client = wsi;
- printf("%s\n", (char*)in);
+ DEBUG(proto, "%s\n", (char*)in);
std::string data;
data.append((char*)in, len);
@@ -215,11 +215,16 @@ int callback_lws_task(struct libwebsocket_context * context,
message_t createmsg = create_msg_create(task);
createmsg.tid = omi->observe.id;
- message_t updatemsg = create_msg_update(task);
- updatemsg.tid = omi->observe.id;
-
msgqueue[wsi].push_back(createmsg);
- msgqueue[wsi].push_back(updatemsg);
+
+ std::map<std::string, std::string>::iterator ai =
+ task.attributes.begin();
+ while(ai != task.attributes.end()) {
+ message_t updatemsg = create_msg_update(task, ai->first);
+ updatemsg.tid = omi->observe.id;
+ msgqueue[wsi].push_back(updatemsg);
+ ai++;
+ }
id++;
}
diff --git a/src/muniad.cc b/src/muniad.cc
index b9651dd..3ea7d6c 100644
--- a/src/muniad.cc
+++ b/src/muniad.cc
@@ -37,9 +37,8 @@
#include "http.h"
#include "munia_proto.h"
-#include "debug.h"
+#include "hugin.hpp"
#include "taskmanager.h"
-extern TaskManager task_manager;
static struct libwebsocket_protocols protocols[] = {
// first protocol must always be HTTP handler
@@ -116,7 +115,7 @@ int main(int argc, char **argv)
}
}
- debug_parse("+all");
+ //_parse("+all");
task_manager.init(db_filename);
diff --git a/src/saxparser.cc b/src/saxparser.cc
index d261b72..52e8d3c 100644
--- a/src/saxparser.cc
+++ b/src/saxparser.cc
@@ -25,7 +25,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "saxparser.h"
-#include "debug.h"
+
+#include "hugin.hpp"
#include <string.h>
#include <stdio.h>
diff --git a/src/task.h b/src/task.h
index 840e657..0c64c04 100644
--- a/src/task.h
+++ b/src/task.h
@@ -30,6 +30,7 @@
#include <string>
#include <list>
+#include <map>
typedef unsigned int taskid_t;
typedef std::list<taskid_t> TaskIdList;
@@ -37,8 +38,7 @@ typedef std::list<taskid_t> TaskIdList;
typedef struct {
taskid_t id;
taskid_t parentid;
- std::string title;
- std::string desc;
+ std::map<std::string, std::string> attributes;
} task_t;
#endif/*__MUNIA_TASK_H__*/
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 41c1c8d..7857d12 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -29,6 +29,8 @@
#include <stdio.h>
+#include "hugin.hpp"
+
// Global TaskManager object.
TaskManager task_manager;
@@ -46,7 +48,6 @@ static bool isProtected(taskid_t id)
TaskManager::TaskManager() {
idCount = FIRST_TASK_ID;
-
}
TaskManager::~TaskManager() {
@@ -54,7 +55,7 @@ TaskManager::~TaskManager() {
void TaskManager::init(std::string filename)
{
- printf("Reading tasks from file: %s\n", filename.c_str());
+ DEBUG(taskmgr, "Reading tasks from file: %s\n", filename.c_str());
file = filename;
FILE *fp = fopen(file.c_str(), "r");
@@ -71,23 +72,24 @@ void TaskManager::init(std::string filename)
// Create new basis config
task_t t;
- t.title = "root";
+
+ t.attributes["title"] = "root";
t.id = ROOT_ID;
tree.insertAsChild(0, ROOT_ID, t);
- t.title = "Finished";
+ t.attributes["title"] = "Finished";
t.id = FINISHED_ID;
tree.insertAsChild(ROOT_ID, FINISHED_ID, t);
- t.title = "Backlog";
+ t.attributes["title"] = "Backlog";
t.id = BACKLOG_ID;
tree.insertAsChild(ROOT_ID, BACKLOG_ID, t);
- t.title = "Lost+Found";
+ t.attributes["title"] = "Lost+Found";
t.id = LOSTFOUND_ID;
tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t);
- t.title = "Projects";
+ t.attributes["title"] = "Projects";
t.id = PROJECTS_ID;
tree.insertAsChild(ROOT_ID, PROJECTS_ID, t);
}
@@ -144,7 +146,8 @@ TaskIdList TaskManager::removeTask(taskid_t id)
return affectedTasks;
}
-TaskIdList TaskManager::updateTask(taskid_t id, task_t t)
+TaskIdList TaskManager::updateTask(taskid_t id, const std::string &name,
+ const std::string &value)
throw (std::exception) {
if(isProtected(id)) return TaskIdList();
@@ -152,7 +155,7 @@ TaskIdList TaskManager::updateTask(taskid_t id, task_t t)
TaskIdList affectedTasks;
try {
- affectedTasks = tree.updateData(id, t);
+ affectedTasks = tree.updateData(id, name, value);
}
catch (std::exception& e) {
throw e;
@@ -169,7 +172,7 @@ TaskIdList TaskManager::createTask(taskid_t parentid, taskid_t *pid)
task_t t;
taskid_t id = *pid;//createId();
- t.title = "";
+ t.attributes["title"] = "";
t.id = id;
if(pid) *pid = id;
@@ -235,7 +238,7 @@ task_t create_task(std::string title, std::string desc) {
task_t t;
t.parent_id = current_id_count();
- t.title = title;
+ t.attributes["title"] = title;
t.desc = desc;
t.id = id_count; id_count++;
@@ -271,8 +274,8 @@ bool save_tasklist_to_file(TaskList list, std::string file) {
// printf("Flushing task %d\n", t.id);
r |= fprintf(fp, " <task id=\"%d\" parent_id=\"%d\">\n", t.id, t.parent_id);
- r |= fprintf(fp, " <title>%s</title>\n", xml_encode(t.title).c_str());
- r |= fprintf(fp, " <desc>%s</desc>\n", xml_encode(t.desc).c_str());
+ r |= fprintf(fp, " <title>%s</title>\n", xml_encode(t.attributes["title"]).c_str());
+ r |= fprintf(fp, " <desc>%s</desc>\n", xml_encode(t.attributes["description"]).c_str());
r |= fprintf(fp, " </task>)\n");
if(!r) {
diff --git a/src/taskmanager.h b/src/taskmanager.h
index e11736b..11601a4 100644
--- a/src/taskmanager.h
+++ b/src/taskmanager.h
@@ -46,7 +46,8 @@ public:
void init(std::string filename);
TaskIdList createTask(taskid_t parentid, taskid_t *id) throw (std::exception);
- TaskIdList updateTask(taskid_t id, task_t task) throw (std::exception);
+ TaskIdList updateTask(taskid_t id, const std::string &name,
+ const std::string &value) throw (std::exception);
TaskIdList removeTask(taskid_t id) throw (std::exception);
TaskIdListPair moveTask(taskid_t id, taskid_t newParent) throw (std::exception);
@@ -59,16 +60,20 @@ public:
void flushTasks();
+ taskid_t createId();
+
private:
// TaskIdList ancestorList(taskid_t task);
- taskid_t createId();
taskid_t idCount;
task_t nextTask();
std::string file;
};
+#ifndef FOOBAR
extern TaskManager task_manager;
+#endif
+
#if 0
diff --git a/src/tasktree.cc b/src/tasktree.cc
index e2e2bf6..b404cf5 100644
--- a/src/tasktree.cc
+++ b/src/tasktree.cc
@@ -27,9 +27,11 @@
*/
#include "tasktree.h"
+#include <stdio.h>
+
#include "xmlparser.h"
-#include "debug.h"
+#include "hugin.hpp"
#include "xml_encode_decode.h"
@@ -47,7 +49,14 @@ std::string node::toXML(std::string prefix)
std::string xml;
xml += prefix + "<task id=\""+id2str(id)+"\">\n";
- xml += prefix + " <title>" + xml_encode(data.title) + "</title>\n";
+ xml += prefix + " <attributes>\n";
+ std::map<std::string, std::string>::iterator ai = data.attributes.begin();
+ while(ai != data.attributes.end()) {
+ xml += prefix + " <attribute name=\"" + xml_encode(ai->first) + "\">"
+ + xml_encode(ai->second) + "</attribute>\n";
+ ai++;
+ }
+ xml += prefix + " </attributes>\n";
xml += prefix + " <children>\n";
NodeList::iterator ni = children.begin();
while(ni != children.end()) {
@@ -78,7 +87,13 @@ TaskTree::~TaskTree() {
}
taskid_t TaskTree::createId() {
- return nextid++;
+ taskid_t taskid;
+
+ do {
+ taskid = nextid++;
+ } while(id2node.find(taskid) != id2node.end());
+
+ return taskid;
}
static taskid_t rootid = -1;
@@ -102,7 +117,7 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data)
try {
node_t* parent = id2node.at(parentid);
node_t* child = createNode(id);
-// printf("!!!!!!!id in insert: %d\n", data.id);
+// DEBUG(tasktree, "!!!!!!!id in insert: %d\n", data.id);
child->data = data;
insertChild(parent, child);
@@ -116,7 +131,7 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data)
}
}
-// printf("Child %d added to %d, affecting %d nodes\n",
+// DEBUG(tasktree, "Child %d added to %d, affecting %d nodes\n",
// id, parentid, affectedNodes.size());
return affectedNodes;
}
@@ -129,22 +144,22 @@ TaskIdList TaskTree::remove(taskid_t id)
TaskIdList ancestors = ancestorList(id);
concatTaskIdLists(affectedNodes, ancestors);
-// printf("Removing %d\n", id);
+// DEBUG(tasktree, "Removing %d\n", id);
-// printf("!!!!!affected nodes %d\n", affectedNodes.size());
+// DEBUG(tasktree, "!!!!!affected nodes %d\n", affectedNodes.size());
node_t* node = id2node[id];
-// printf("node: %p, id %d, parent %p\n", node, node->data.id, node->parent);
+// DEBUG(tasktree, "node: %p, id %d, parent %p\n", node, node->data.id, node->parent);
-// printf("!!!!!size %d\n", node->parent->children.size());
+// DEBUG(tasktree, "!!!!!size %d\n", node->parent->children.size());
node->parent->children.remove(node);
for(NodeList::iterator it = node->parent->children.begin();
it != node->parent->children.end();
it++) {
-// printf("%p\n", *it);
+// DEBUG(tasktree, "%p\n", *it);
}
-// printf("!!!!!size %d\n", node->parent->children.size());
+// DEBUG(tasktree, "!!!!!size %d\n", node->parent->children.size());
TaskIdList idlist = bfs(id);
TaskIdList::reverse_iterator it = idlist.rbegin();
@@ -194,7 +209,8 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
*/
-TaskIdList TaskTree::updateData(taskid_t id, task_t t)
+TaskIdList TaskTree::updateData(taskid_t id, const std::string &name,
+ const std::string &value)
throw (std::exception)
{
@@ -202,7 +218,7 @@ TaskIdList TaskTree::updateData(taskid_t id, task_t t)
try {
node_t* node = id2node.at(id);
- node->data = t;
+ node->data.attributes[name] = name;
affectedNodes.push_back(id);
TaskIdList ancestors = ancestorList(id);
@@ -225,8 +241,8 @@ task_t TaskTree::data(taskid_t id)
node_t* node = id2node.at(id);
task_t tmp = node->data;
t.id = node->id;
- t.title = tmp.title;
-// printf("!!!!t.id and tmp.id in data: %d and %d\n", t.id, tmp.id);
+ t.attributes["title"] = tmp.attributes["title"];
+// DEBUG(tasktree, "!!!!t.id and tmp.id in data: %d and %d\n", t.id, tmp.id);
if(node->parent) t.parentid = node->parent->id;
else {
if(t.id != rootid) throw std::exception();
@@ -287,10 +303,10 @@ TaskIdList TaskTree::ancestorList(taskid_t id)
throw e;
}
-// printf("Collected %d ancestors to %u\n", ancestors.size(), id);
+// DEBUG(tasktree, "Collected %d ancestors to %u\n", ancestors.size(), id);
// for(TaskIdList::iterator it = ancestors.begin();
// it != ancestors.end(); it++) {
-// printf("\tancestor %u\n", *it);
+// DEBUG(tasktree, "\tancestor %u\n", *it);
// }
return ancestors;
}
@@ -315,7 +331,8 @@ void TaskTree::insertChild(node_t* parent, node_t* child) {
static void printNode(node_t* node, std::string prefix) {
if(!node) return;
task_t t = node->data;
- printf("%s- %u - %s (%p)\n", prefix.c_str(), node->id, t.title.c_str(), node);
+ DEBUG(tasktree, "%s- %u - %s (%p)\n", prefix.c_str(), node->id,
+ t.attributes["title"].c_str(), node);
NodeList::iterator it;
for(it = node->children.begin(); it != node->children.end(); it++) {
@@ -370,23 +387,23 @@ TEST_BEGIN;
TaskTree tree;
task_t t;
-t.title = "root";
+t.attributes["title"] = "root";
t.id = ROOT_ID;
tree.insertAsChild(0, ROOT_ID, t);
-t.title = "Finished";
+t.attributes["title"] = "Finished";
t.id = FINISHED_ID;
tree.insertAsChild(ROOT_ID, FINISHED_ID, t);
-t.title = "Backlog";
+t.attributes["title"] = "Backlog";
t.id = BACKLOG_ID;
tree.insertAsChild(ROOT_ID, BACKLOG_ID, t);
-t.title = "Lost+Found";
+t.attributes["title"] = "Lost+Found";
t.id = LOSTFOUND_ID;
tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t);
-t.title = "Projects";
+t.attributes["title"] = "Projects";
t.id = PROJECTS_ID;
tree.insertAsChild(ROOT_ID, PROJECTS_ID, t);
diff --git a/src/tasktree.h b/src/tasktree.h
index 15d9c44..0fd2540 100644
--- a/src/tasktree.h
+++ b/src/tasktree.h
@@ -61,7 +61,8 @@ public:
TaskIdList insertAsChild(taskid_t parentid, taskid_t id, task_t data) throw (std::exception);
TaskIdList remove(taskid_t id) throw (std::exception);
// TaskIdList move(taskid_t id, taskid_t newParentId) throw (std::exception);
- TaskIdList updateData(taskid_t id, task_t t) throw (std::exception);
+ TaskIdList updateData(taskid_t id, const std::string &name,
+ const std::string &value) throw (std::exception);
task_t data(taskid_t id) throw (std::exception);
TaskIdList bfs(taskid_t id) throw (std::exception);
@@ -73,9 +74,9 @@ public:
std::string toXML();
void fromXML(std::string xml);
-private:
taskid_t nextid;
+private:
node_t* createNode(taskid_t id);
void insertChild(node_t* parent, node_t* child);
diff --git a/src/xmlparser.cc b/src/xmlparser.cc
index a362f95..03a54a1 100644
--- a/src/xmlparser.cc
+++ b/src/xmlparser.cc
@@ -64,6 +64,10 @@ void XmlParser::startTag(std::string name, attributes_t &attr)
parents.push(node->id);
}
+ if(name == "attribute") {
+ attr_name = attr["name"];
+ }
+
cdata = "";
}
@@ -76,7 +80,7 @@ void XmlParser::endTag(std::string name)
parents.pop();
}
- if(name == "title") {
- node->data.title = cdata;
+ if(name == "attribute") {
+ node->data.attributes[attr_name] = cdata;
}
}
diff --git a/src/xmlparser.h b/src/xmlparser.h
index 6f05650..92e0529 100644
--- a/src/xmlparser.h
+++ b/src/xmlparser.h
@@ -48,6 +48,7 @@ private:
std::string cdata;
node_t *node;
TaskTree *tree;
+ std::string attr_name;
};
#endif/*__MUNIA_XMLPARSER_H__*/