summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/ConfigManager.cpp10
-rw-r--r--src/Common/ConfigManager.h7
-rw-r--r--src/Common/Configurable.cpp35
-rw-r--r--src/Common/Configurable.h8
-rw-r--r--src/Common/Logger.cpp17
-rw-r--r--src/Common/Logger.h17
-rw-r--r--src/Common/Makefile.am2
-rw-r--r--src/Common/Makefile.in8
8 files changed, 94 insertions, 10 deletions
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp
index 20a6110..a7270e2 100644
--- a/src/Common/ConfigManager.cpp
+++ b/src/Common/ConfigManager.cpp
@@ -31,11 +31,19 @@ namespace Common {
ConfigManager ConfigManager::configManager;
+bool ConfigManager::Compare::operator() (const Configurable *c1, const Configurable *c2) {
+ if(c1->getPriority() != c2->getPriority())
+ return c1->getPriority() > c2->getPriority();
+ else
+ return c1 < c2;
+}
+
+
void ConfigManager::handleConfigEntry(const std::vector<std::vector<std::string> > &entry) {
bool handled = false;
for(std::set<Configurable*>::iterator c = configurables.begin(); c != configurables.end(); ++c) {
- if((*c)->handleConfigEntry(entry))
+ if((*c)->handleConfigEntry(entry, handled))
handled = true;
}
diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h
index ccf5d13..b447fc4 100644
--- a/src/Common/ConfigManager.h
+++ b/src/Common/ConfigManager.h
@@ -31,9 +31,14 @@ class Configurable;
class ConfigManager {
private:
+ struct Compare {
+ bool operator() (const Configurable *c1, const Configurable *c2);
+ };
+
static ConfigManager configManager;
- std::set<Configurable*> configurables;
+ std::set<Configurable*, Compare> configurables;
+
bool finished;
ConfigManager() : finished(false) {}
diff --git a/src/Common/Configurable.cpp b/src/Common/Configurable.cpp
new file mode 100644
index 0000000..4d689ed
--- /dev/null
+++ b/src/Common/Configurable.cpp
@@ -0,0 +1,35 @@
+/*
+ * Configurable.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "Configurable.h"
+#include "ConfigManager.h"
+
+namespace Mad {
+namespace Common {
+
+Configurable::Configurable() {
+ ConfigManager::getConfigManager()->registerConfigurable(this);
+}
+
+Configurable::~Configurable() {
+ ConfigManager::getConfigManager()->unregisterConfigurable(this);
+}
+
+}
+}
diff --git a/src/Common/Configurable.h b/src/Common/Configurable.h
index 0c471c7..8c2c083 100644
--- a/src/Common/Configurable.h
+++ b/src/Common/Configurable.h
@@ -29,10 +29,16 @@ namespace Common {
class ConfigManager;
class Configurable {
+ public:
+ Configurable();
+ virtual ~Configurable();
+
+ virtual int getPriority() const {return 0;}
+
protected:
friend class ConfigManager;
- virtual bool handleConfigEntry(const std::vector<std::vector<std::string> >&) {return false;}
+ virtual bool handleConfigEntry(const std::vector<std::vector<std::string> >&, bool) {return false;}
virtual void configFinished() {}
};
diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp
index a7d3bd1..f99d31f 100644
--- a/src/Common/Logger.cpp
+++ b/src/Common/Logger.cpp
@@ -18,15 +18,30 @@
*/
#include "Logger.h"
+#include "ConfigManager.h"
+#include "Util.h"
+
#include <cstdlib>
-#include <ctime>
namespace Mad {
namespace Common {
+std::auto_ptr<Logger::ConfigHelper> Logger::configHelper;
std::list<Logger*> Logger::loggers;
+bool Logger::ConfigHelper::handleConfigEntry(const std::vector<std::vector<std::string> > &entry, bool handled) {
+ if(handled)
+ return false;
+
+ if(entry.size() == 1 && entry.front().size() == 2 && Util::tolower(entry.front().front()) == "logger") {
+ logf(WARNING, "Invalid logger '%s'.", entry.back().back().c_str());
+ return true;
+ }
+
+ return false;
+}
+
void Logger::logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap) {
int size = 100;
char *buf = (char*)std::malloc(size);
diff --git a/src/Common/Logger.h b/src/Common/Logger.h
index 1fff654..d8f105a 100644
--- a/src/Common/Logger.h
+++ b/src/Common/Logger.h
@@ -21,17 +21,26 @@
#define MAD_COMMON_LOGGER_H_
#include "LoggerBase.h"
+#include "Configurable.h"
+
#include <algorithm>
-#include <list>
-#include <string>
#include <cstdarg>
#include <ctime>
+#include <list>
+#include <memory>
+#include <string>
namespace Mad {
namespace Common {
class Logger : public LoggerBase {
private:
+ class ConfigHelper : private Configurable {
+ protected:
+ virtual bool handleConfigEntry(const std::vector<std::vector<std::string> > &entry, bool handled);
+ };
+
+ static std::auto_ptr<ConfigHelper> configHelper;
static std::list<Logger*> loggers;
static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap);
@@ -40,6 +49,10 @@ class Logger : public LoggerBase {
virtual void logMessage(MessageCategory category, MessageLevel level, time_t messageTimestamp, const std::string &message) = 0;
public:
+ static void initConfigHelper() {
+ configHelper.reset(new ConfigHelper());
+ }
+
static void log(MessageCategory category, MessageLevel level, const std::string &message);
static void log(MessageCategory category, const std::string &message) {
log(category, DEFAULT, message);
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index d104cac..95b3d50 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -1,7 +1,7 @@
SUBDIRS = Backends Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
-libcommon_la_SOURCES = RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp
+libcommon_la_SOURCES = Configurable.cpp RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp
libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la
noinst_HEADERS = Configurable.h LoggerBase.h RemoteLogger.h Logger.h ConfigManager.h Exception.h HostInfo.h Request.h RequestBase.h \
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 6bcffb7..8b9300c 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -49,8 +49,9 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libcommon_la_DEPENDENCIES = Backends/libbackends.la \
Requests/librequests.la RequestHandlers/librequesthandlers.la
-am_libcommon_la_OBJECTS = RemoteLogger.lo Logger.lo ConfigManager.lo \
- Exception.lo RequestManager.lo SystemBackend.lo Util.lo
+am_libcommon_la_OBJECTS = Configurable.lo RemoteLogger.lo Logger.lo \
+ ConfigManager.lo Exception.lo RequestManager.lo \
+ SystemBackend.lo Util.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -200,7 +201,7 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Backends Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
-libcommon_la_SOURCES = RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp
+libcommon_la_SOURCES = Configurable.cpp RemoteLogger.cpp Logger.cpp ConfigManager.cpp Exception.cpp RequestManager.cpp SystemBackend.cpp Util.cpp
libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la
noinst_HEADERS = Configurable.h LoggerBase.h RemoteLogger.h Logger.h ConfigManager.h Exception.h HostInfo.h Request.h RequestBase.h \
RequestHandler.h RequestManager.h SystemBackend.h Util.h
@@ -257,6 +258,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Configurable.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Exception.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Logger.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RemoteLogger.Plo@am__quote@