From 766c56a693e8b1bd4293459bb256abdc0515a0b5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 9 Jun 2009 19:01:02 +0200 Subject: Teile der Namespaces Common und Net in den neuen Namespace Core verschoben --- src/Common/CMakeLists.txt | 9 -- src/Common/ClientConnection.cpp | 5 +- src/Common/ClientConnection.h | 4 +- src/Common/ConfigEntry.cpp | 64 --------- src/Common/ConfigEntry.h | 96 ------------- src/Common/ConfigManager.cpp | 141 ------------------- src/Common/ConfigManager.h | 69 ---------- src/Common/Configurable.h | 47 ------- src/Common/Connection.h | 8 +- src/Common/Initializable.cpp | 71 ---------- src/Common/Initializable.h | 54 -------- src/Common/LogManager.cpp | 146 -------------------- src/Common/LogManager.h | 149 --------------------- src/Common/Logger.cpp | 89 ------------ src/Common/Logger.h | 68 ---------- src/Common/LoggerBase.h | 79 ----------- src/Common/ModuleManager.cpp | 8 +- src/Common/ModuleManager.h | 8 +- src/Common/RemoteLogger.h | 42 ------ src/Common/Request.cpp | 4 +- src/Common/Request.h | 22 +-- src/Common/RequestHandler.h | 8 +- .../RequestHandlers/DisconnectRequestHandler.cpp | 8 +- .../RequestHandlers/SimpleRequestHandler.cpp | 10 +- .../RequestHandlers/StatusRequestHandler.cpp | 2 +- src/Common/RequestManager.cpp | 18 +-- src/Common/RequestManager.h | 5 - src/Common/Requests/DisconnectRequest.cpp | 4 +- src/Common/SystemBackend.h | 24 ++-- src/Common/SystemManager.cpp | 48 +++---- src/Common/SystemManager.h | 14 +- src/Common/Tokenizer.cpp | 131 ------------------ src/Common/Tokenizer.h | 44 ------ 33 files changed, 97 insertions(+), 1402 deletions(-) delete mode 100644 src/Common/ConfigEntry.cpp delete mode 100644 src/Common/ConfigEntry.h delete mode 100644 src/Common/ConfigManager.cpp delete mode 100644 src/Common/ConfigManager.h delete mode 100644 src/Common/Configurable.h delete mode 100644 src/Common/Initializable.cpp delete mode 100644 src/Common/Initializable.h delete mode 100644 src/Common/LogManager.cpp delete mode 100644 src/Common/LogManager.h delete mode 100644 src/Common/Logger.cpp delete mode 100644 src/Common/Logger.h delete mode 100644 src/Common/LoggerBase.h delete mode 100644 src/Common/RemoteLogger.h delete mode 100644 src/Common/Tokenizer.cpp delete mode 100644 src/Common/Tokenizer.h (limited to 'src/Common') diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index 25c3dee..078df71 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -8,25 +8,16 @@ link_directories(${LTDL_LIBRARY_DIR}) add_library(Common Base64Encoder.cpp Base64Encoder.h ClientConnection.cpp ClientConnection.h - ConfigEntry.cpp ConfigEntry.h - ConfigManager.cpp ConfigManager.h - Configurable.h Connection.cpp Connection.h - Initializable.cpp Initializable.h GroupInfo.h HostInfo.h - Logger.cpp Logger.h - LoggerBase.h - LogManager.cpp LogManager.h ModuleManager.cpp ModuleManager.h - RemoteLogger.h Request.cpp Request.h RequestHandler.cpp RequestHandler.h RequestHandlerGroup.h RequestManager.cpp RequestManager.h SystemBackend.h SystemManager.cpp SystemManager.h - Tokenizer.cpp Tokenizer.h UserInfo.h XmlPacket.cpp XmlPacket.h ) diff --git a/src/Common/ClientConnection.cpp b/src/Common/ClientConnection.cpp index b9a6721..ba558f4 100644 --- a/src/Common/ClientConnection.cpp +++ b/src/Common/ClientConnection.cpp @@ -18,9 +18,8 @@ */ #include "ClientConnection.h" -#include -#include "Logger.h" +#include namespace Mad { namespace Common { @@ -33,7 +32,7 @@ bool ClientConnection::send(const Net::Packet &packet) { return connection->send(packet); } -void ClientConnection::connect(const boost::asio::ip::tcp::endpoint &address) throw(Net::Exception) { +void ClientConnection::connect(const boost::asio::ip::tcp::endpoint &address) throw(Core::Exception) { connection->connect(address); } diff --git a/src/Common/ClientConnection.h b/src/Common/ClientConnection.h index a455c29..305df44 100644 --- a/src/Common/ClientConnection.h +++ b/src/Common/ClientConnection.h @@ -21,7 +21,7 @@ #define MAD_COMMON_CLIENTCONNECTION_H_ #include "Connection.h" -#include +#include #include @@ -44,7 +44,7 @@ class ClientConnection : public Connection { ClientConnection(); virtual ~ClientConnection() {} - void connect(const boost::asio::ip::tcp::endpoint &address) throw(Net::Exception); + void connect(const boost::asio::ip::tcp::endpoint &address) throw(Core::Exception); bool isConnecting() const; bool isConnected() const; diff --git a/src/Common/ConfigEntry.cpp b/src/Common/ConfigEntry.cpp deleted file mode 100644 index f47cf7a..0000000 --- a/src/Common/ConfigEntry.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * ConfigEntry.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "ConfigEntry.h" - -namespace Mad { -namespace Common { - -ConfigEntry::String& ConfigEntry::Entry::operator[] (size_t i) { - try { - return value.at(i); - } - catch(std::out_of_range &e) { - zero = String(); - return zero; - } -} - -const ConfigEntry::String& ConfigEntry::Entry::operator[] (size_t i) const { - try { - return value.at(i); - } - catch(std::out_of_range &e) { - return constZero; - } -} - -ConfigEntry::Entry& ConfigEntry::operator[] (size_t i) { - try { - return entries.at(i); - } - catch(std::out_of_range &e) { - zero = Entry(); - return zero; - } -} - -const ConfigEntry::Entry& ConfigEntry::operator[] (size_t i) const { - try { - return entries.at(i); - } - catch(std::out_of_range &e) { - return constZero; - } -} - -} -} diff --git a/src/Common/ConfigEntry.h b/src/Common/ConfigEntry.h deleted file mode 100644 index 8358726..0000000 --- a/src/Common/ConfigEntry.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ConfigEntry.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_CONFIGENTRY_H_ -#define MAD_COMMON_CONFIGENTRY_H_ - -#include -#include -#include -#include - -namespace Mad { -namespace Common { - -class ConfigEntry { - public: - class String : public std::string { - public: - String() {} - String(const std::string &str) : std::string(str) {} - - bool matches(const std::string &str) const { - return (strcasecmp(c_str(), str.c_str()) == 0); - } - }; - - class Entry { - private: - String key; - std::vector value; - - String zero, constZero; - - public: - Entry() {} - Entry(const std::vector &args) { - if(args.empty()) - return; - - key = args.front(); - - value.assign(args.begin()+1, args.end()); - } - - bool empty() const { - return key.empty(); - } - - String &getKey() {return key;} - const String &getKey() const {return key;} - - size_t getSize() const {return value.size();} - - String& operator[] (size_t i); - const String& operator[] (size_t i) const; - }; - - private: - std::vector entries; - Entry zero, constZero; - - public: - size_t getSize() const {return entries.size();} - - Entry& operator[] (size_t i); - const Entry& operator[] (size_t i) const; - - void push(const Entry &entry) { - entries.push_back(entry); - } - - void pop() { - entries.pop_back(); - } -}; - -} -} - -#endif /* MAD_COMMON_CONFIGENTRY_H_ */ diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp deleted file mode 100644 index 3bf0c85..0000000 --- a/src/Common/ConfigManager.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * ConfigManager.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "ConfigManager.h" -#include "ConfigEntry.h" -#include "Configurable.h" -#include "Logger.h" -#include "LogManager.h" -#include "Tokenizer.h" - -#include -#include - -namespace Mad { -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 ConfigEntry &entry) { - bool handled = false; - - for(std::set::iterator c = configurables.begin(); c != configurables.end(); ++c) { - if((*c)->handleConfigEntry(entry, handled)) - handled = true; - } - - if(!handled) - Logger::logf(Logger::WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().c_str()); -} - -bool ConfigManager::loadFile(const std::string &filename) { - if(finished) - return false; - - std::ifstream file(filename.c_str()); - ConfigEntry entry; - std::string line, input; - char delim; - std::vector splitLine, lastConfigLine; - - if(!file.good()) - return false; - - while(!(file.eof() && line.empty() && input.empty())) { - while(input.empty() && !file.eof()) - std::getline(file, input); - - if(input.empty()) - break; - - size_t pos = input.find_first_of("#{}"); - if(pos == std::string::npos) { - line += input; - delim = '\n'; - input.clear(); - } - else { - line += input.substr(0, pos); - delim = input[pos]; - input = input.substr(pos+1); - } - - if(!Tokenizer::tokenize(line, splitLine)) { - line += delim; - continue; - } - - if(!splitLine.empty()) { - pos = line.find_first_of(" \t"); - - entry.push(splitLine); - handleConfigEntry(entry); - entry.pop(); - - lastConfigLine = splitLine; - } - - switch(delim) { - case '#': - input.clear(); - break; - case '{': - entry.push(lastConfigLine); - break; - case '}': - entry.pop(); - } - - line.clear(); - } - - // TODO Depth check - - return true; -} - -void ConfigManager::finish() { - if(finished) - return; - - for(std::set::iterator c = configurables.begin(); c != configurables.end(); ++c) - (*c)->configFinished(); - - finished = true; -} - -ConfigManager::ConfigManager() : finished(false) { - registerConfigurable(LogManager::get()); -} - -ConfigManager::~ConfigManager() { - unregisterConfigurable(LogManager::get()); -} - -} -} diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h deleted file mode 100644 index e7885b8..0000000 --- a/src/Common/ConfigManager.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * ConfigManager.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_CONFIGMANAGER_H_ -#define MAD_COMMON_CONFIGMANAGER_H_ - -#include -#include -#include - -namespace Mad { -namespace Common { - -class ConfigEntry; -class Configurable; - -class ConfigManager { - private: - struct Compare { - bool operator() (const Configurable *c1, const Configurable *c2); - }; - - static ConfigManager configManager; - - std::set configurables; - bool finished; - - ConfigManager(); - ~ConfigManager(); - - void handleConfigEntry(const ConfigEntry &entry); - - public: - bool loadFile(const std::string &filename); - void finish(); - - void registerConfigurable(Configurable *c) { - configurables.insert(c); - } - - void unregisterConfigurable(Configurable *c) { - configurables.erase(c); - } - - static ConfigManager *get() { - return &configManager; - } -}; - -} -} - -#endif /* MAD_COMMON_CONFIGMANAGER_H_ */ diff --git a/src/Common/Configurable.h b/src/Common/Configurable.h deleted file mode 100644 index 47f919d..0000000 --- a/src/Common/Configurable.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Configurable.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_CONFIGURABLE_H_ -#define MAD_COMMON_CONFIGURABLE_H_ - -namespace Mad { -namespace Common { - -class ConfigEntry; -class ConfigManager; - -class Configurable { - public: - virtual ~Configurable() {} - - virtual int getPriority() const {return 0;} - - protected: - friend class ConfigManager; - - Configurable() {} - - virtual bool handleConfigEntry(const ConfigEntry&, bool) {return false;} - virtual void configFinished() {} -}; - -} -} - -#endif /* MAD_COMMON_CONFIGURABLE_H_ */ diff --git a/src/Common/Connection.h b/src/Common/Connection.h index c8ff3e8..6700574 100644 --- a/src/Common/Connection.h +++ b/src/Common/Connection.h @@ -20,7 +20,7 @@ #ifndef MAD_COMMON_CONNECTION_H_ #define MAD_COMMON_CONNECTION_H_ -#include +#include #include #include @@ -39,7 +39,7 @@ class Connection : private boost::noncopyable { private: bool authenticated; - Net::Signals::Signal2, uint16_t> signalReceive; + Core::Signals::Signal2, uint16_t> signalReceive; protected: Connection() : authenticated(0) {} @@ -53,10 +53,10 @@ class Connection : private boost::noncopyable { bool sendPacket(const XmlPacket &packet, uint16_t requestId); - Net::Signals::Connection connectSignalReceive(const Net::Signals::Signal2, uint16_t>::slot_type &slot) { + Core::Signals::Connection connectSignalReceive(const Core::Signals::Signal2, uint16_t>::slot_type &slot) { return signalReceive.connect(slot); } - void disconnectSignalReceive(const Net::Signals::Connection &con) { + void disconnectSignalReceive(const Core::Signals::Connection &con) { signalReceive.disconnect(con); } diff --git a/src/Common/Initializable.cpp b/src/Common/Initializable.cpp deleted file mode 100644 index d2dc9fd..0000000 --- a/src/Common/Initializable.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Initializable.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "Initializable.h" - -#include "ConfigManager.h" -#include "Configurable.h" -#include "Logger.h" - -#include - -namespace Mad { -namespace Common { - -std::stack Initializable::initializedObjects; - -void Initializable::init() { - if(initialized) - return; - - if(initializing) { - Logger::log(Logger::CRITICAL, "Fatal initialization error: cyclic dependencies."); - std::terminate(); - } - - initializing = true; - - doInit(); - - Configurable *c = dynamic_cast(this); - if(c) - ConfigManager::get()->registerConfigurable(c); - - initializing = false; - initialized = true; - initializedObjects.push(this); -} - -void Initializable::deinit() { - while(!initializedObjects.empty()) { - Initializable *in = initializedObjects.top(); - - Configurable *c = dynamic_cast(in); - if(c) - ConfigManager::get()->unregisterConfigurable(c); - - in->doDeinit(); - in->initialized = false; - - initializedObjects.pop(); - } -} - -} -} diff --git a/src/Common/Initializable.h b/src/Common/Initializable.h deleted file mode 100644 index 6f67678..0000000 --- a/src/Common/Initializable.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Initializable.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_INITIALIZABLE_H_ -#define MAD_COMMON_INITIALIZABLE_H_ - -#include - -namespace Mad { -namespace Common { - -class Initializable { - private: - static std::stack initializedObjects; - - bool initializing; - bool initialized; - - protected: - Initializable() : initializing(false), initialized(false) {} - virtual void doInit() {} - virtual void doDeinit() {} - - public: - virtual ~Initializable() {} - - void init(); - - bool isInitialized() const {return initialized;} - bool isInitializing() const {return initializing;} - - static void deinit(); -}; - -} -} - -#endif /* MAD_COMMON_INITIALIZABLE_H_ */ diff --git a/src/Common/LogManager.cpp b/src/Common/LogManager.cpp deleted file mode 100644 index bd83a5e..0000000 --- a/src/Common/LogManager.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * LogManager.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "LogManager.h" -#include "ConfigEntry.h" - -#include - -namespace Mad { -namespace Common { - -LogManager LogManager::logManager; - - -void LogManager::ConsoleLogger::logMessage(MessageCategory category _UNUSED_PARAMETER_, MessageLevel level, time_t timestamp _UNUSED_PARAMETER_, const std::string &message) { - if(level != CRITICAL) {// Critical messages are printed to cerr directly, so don't print them a second time - cerrLock.lock(); - std::cerr << message << std::endl; - cerrLock.unlock(); - } -} - -void LogManager::ConsoleLogger::logMessage(MessageCategory category _UNUSED_PARAMETER_, MessageLevel, time_t timestamp _UNUSED_PARAMETER_, const std::string &message, const std::string &messageSource) { - cerrLock.lock(); - std::cerr << message << " from " << messageSource << std::endl; - cerrLock.unlock(); -} - -void LogManager::ConsoleLogger::logMessageDirect(MessageCategory category _UNUSED_PARAMETER_, MessageLevel level _UNUSED_PARAMETER_, time_t timestamp _UNUSED_PARAMETER_, const std::string &message) { - cerrLock.lock(); - std::cerr << message << std::endl; - cerrLock.unlock(); -} - - -bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { - if(handled) - return false; - - if(entry[0].getKey().matches("Logger")) { - if(entry[0][0].matches("Console")) { - if(entry[1].empty()) { - registerLogger(static_cast(&consoleLogger)); - return true; - } - } - else if(entry[1].empty()) { - Logger::logf(Logger::WARNING, "Unknown logger '%s'.", entry[0][0].c_str()); - return true; - } - } - - return false; -} - -void LogManager::configFinished() { - if(loggers.empty()) - registerLogger(static_cast(&consoleLogger)); - - // TODO Debug - consoleLogger.Logger::setLevel(LoggerBase::DEBUG); - - queueLock.lock(); - configured = true; - queueLock.unlock(); - queueCond.notify_one(); -} - -void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) { - if(level == LoggerBase::CRITICAL) - consoleLogger.logMessageDirect(category, level, timestamp, message); - - queueLock.lock(); - Message m = {category, level, timestamp, message}; - messageQueue.push(m); - queueLock.unlock(); - queueCond.notify_one(); -} - -void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source) { - queueLock.lock(); - RemoteMessage m = {category, level, timestamp, message, source}; - remoteMessageQueue.push(m); - queueLock.unlock(); - queueCond.notify_one(); -} - -void LogManager::loggerThread() { - boost::unique_lock lock(queueLock); - - running = true; - - while(running) { - while(running && ((messageQueue.empty() && messageQueue.empty()) || !configured)) - queueCond.wait(lock); - - while(!messageQueue.empty()) { - Message message = messageQueue.front(); - messageQueue.pop(); - lock.unlock(); - - loggerLock.lock(); - for(std::set::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { - if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) - (*logger)->logMessage(message.category, message.level, message.timestamp, message.message); - } - loggerLock.unlock(); - - lock.lock(); - } - - while(!remoteMessageQueue.empty()) { - RemoteMessage message = remoteMessageQueue.front(); - remoteMessageQueue.pop(); - lock.unlock(); - - remoteLoggerLock.lock(); - for(std::set::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) { - if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) - (*logger)->logMessage(message.category, message.level, message.timestamp, message.message, message.source); - } - remoteLoggerLock.unlock(); - - lock.lock(); - } - } -} - -} -} diff --git a/src/Common/LogManager.h b/src/Common/LogManager.h deleted file mode 100644 index 98bb6f7..0000000 --- a/src/Common/LogManager.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * LogManager.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_LOGMANAGER_H_ -#define MAD_COMMON_LOGMANAGER_H_ - -#include - -#include "Configurable.h" -#include "Logger.h" -#include "RemoteLogger.h" - -#include -#include - -#include -#include - -namespace Mad { - -namespace Net { -class ThreadManager; -} - -namespace Common { - -class LogManager : public Configurable { - private: - friend class Net::ThreadManager; - - typedef LoggerBase::MessageCategory MessageCategory; - typedef LoggerBase::MessageLevel MessageLevel; - - struct Message { - MessageCategory category; - MessageLevel level; - time_t timestamp; - std::string message; - }; - - struct RemoteMessage { - MessageCategory category; - MessageLevel level; - time_t timestamp; - std::string message; - std::string source; - }; - - class ConsoleLogger : public Logger, public RemoteLogger { - private: - // For long messages, writing to cerr is not atomic - // -> lock cerr to prevent mixing messages up - boost::mutex cerrLock; - - protected: - virtual void logMessage(MessageCategory category _UNUSED_PARAMETER_, MessageLevel level, time_t timestamp _UNUSED_PARAMETER_, const std::string &message); - virtual void logMessage(MessageCategory category _UNUSED_PARAMETER_, MessageLevel, time_t timestamp _UNUSED_PARAMETER_, const std::string &message, const std::string &messageSource); - - public: - ConsoleLogger() {} - - void logMessageDirect(MessageCategory category _UNUSED_PARAMETER_, MessageLevel level _UNUSED_PARAMETER_, time_t timestamp _UNUSED_PARAMETER_, const std::string &message); - }; - - - static LogManager logManager; - - ConsoleLogger consoleLogger; - - std::set loggers; - std::set remoteLoggers; - bool configured, running; - - boost::mutex queueLock; - boost::condition_variable queueCond; - - boost::mutex loggerLock; - boost::mutex remoteLoggerLock; - - std::queue messageQueue; - std::queue remoteMessageQueue; - - void loggerThread(); - void stopLoggerThread() { - queueLock.lock(); - running = false; - queueLock.unlock(); - queueCond.notify_one(); - } - - LogManager() : configured(false), running(false) {} - - protected: - virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled); - virtual void configFinished(); - - public: - void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message); - void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source); - - void registerLogger(Logger *logger) { - loggerLock.lock(); - loggers.insert(logger); - loggerLock.unlock(); - } - - void unregisterLogger(Logger *logger) { - loggerLock.lock(); - loggers.erase(logger); - loggerLock.unlock(); - } - - void registerLogger(RemoteLogger *logger) { - remoteLoggerLock.lock(); - remoteLoggers.insert(logger); - remoteLoggerLock.unlock(); - } - - void unregisterLogger(RemoteLogger *logger) { - remoteLoggerLock.lock(); - remoteLoggers.erase(logger); - remoteLoggerLock.unlock(); - } - - static LogManager *get() { - return &logManager; - } -}; - -} -} - -#endif /* MAD_COMMON_LOGMANAGER_H_ */ diff --git a/src/Common/Logger.cpp b/src/Common/Logger.cpp deleted file mode 100644 index e746faf..0000000 --- a/src/Common/Logger.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Logger.cpp - * - * Copyright (C) 2008 Johannes Thorn - * - * 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 . - */ - -#include "Logger.h" -#include "LogManager.h" - -#include - -namespace Mad { -namespace Common { - -void Logger::logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap) { - int size = 100; - char *buf = (char*)std::malloc(size); - - // If buffer is too small, try again with bigger buffer - while(true) { - va_list ap2; - - va_copy(ap2, ap); - int n = std::vsnprintf(buf, size, format, ap2); - va_end(ap2); - - if(n > -1 && n < size) { - log(category, level, buf); - std::free(buf); - return; - } - - if(n > -1) - size = n+1; - else - size *= 2; - - buf = (char*)std::realloc(buf, size); - } - -} - -void Logger::log(MessageCategory category, MessageLevel level, const std::string &message) { - LogManager::get()->log(category, level, std::time(0), message); -} - -void Logger::logf(MessageCategory category, MessageLevel level, const char *format, ...) { - va_list ap; - va_start(ap, format); - logfv(category, level, format, ap); - va_end(ap); -} - -void Logger::logf(MessageCategory category, const char *format, ...) { - va_list ap; - va_start(ap, format); - logfv(category, DEFAULT, format, ap); - va_end(ap); -} - -void Logger::logf(MessageLevel level, const char *format, ...) { - va_list ap; - va_start(ap, format); - logfv(GENERAL, level, format, ap); - va_end(ap); -} - -void Logger::logf(const char *format, ...) { - va_list ap; - va_start(ap, format); - logfv(GENERAL, DEFAULT, format, ap); - va_end(ap); -} - -} -} diff --git a/src/Common/Logger.h b/src/Common/Logger.h deleted file mode 100644 index 436c232..0000000 --- a/src/Common/Logger.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Logger.h - * - * Copyright (C) 2008 Johannes Thorn - * - * 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 . - */ - -#ifndef MAD_COMMON_LOGGER_H_ -#define MAD_COMMON_LOGGER_H_ - -#include "LoggerBase.h" - -#include -#include -#include - -namespace Mad { -namespace Common { - -class LogManager; - -class Logger : public LoggerBase { - private: - friend class LogManager; - - static void logfv(MessageCategory category, MessageLevel level, const char *format, va_list ap); - - protected: - virtual void logMessage(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) = 0; - - public: - static void log(MessageCategory category, MessageLevel level, const std::string &message); - - static void log(MessageCategory category, const std::string &message) { - log(category, DEFAULT, message); - } - - static void log(MessageLevel level, const std::string &message) { - log(GENERAL, level, message); - } - - static void log(const std::string &message) { - log(GENERAL, DEFAULT, message); - } - - - static void logf(MessageCategory category, MessageLevel level, const char *format, ...); - static void logf(MessageCategory category, const char *format, ...); - static void logf(MessageLevel level, const char *format, ...); - static void logf(const char *format, ...); -}; - -} -} - -#endif /* MAD_COMMON_LOGGER_H_ */ diff --git a/src/Common/LoggerBase.h b/src/Common/LoggerBase.h deleted file mode 100644 index 9843d4d..0000000 --- a/src/Common/LoggerBase.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * LoggerBase.h - * - * Copyright (C) 2008 Johannes Thorn - * - * 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 . - */ - -#ifndef MAD_COMMON_LOGGERBASE_H_ -#define MAD_COMMON_LOGGERBASE_H_ - -#include -#include - -namespace Mad { -namespace Common { - -class LoggerBase { - public: - enum MessageLevel { - CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG - }; - - enum MessageCategory { - SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL - }; - - protected: - std::bitset<16> categories; - MessageLevel level; - - LoggerBase() : level(DEFAULT) {setAllCategories();} - virtual ~LoggerBase() {} - - public: - void setCategory(MessageCategory newCategory) { - categories.set(newCategory); - } - - void unsetCategory(MessageCategory oldCategory) { - categories.reset(oldCategory); - } - - void setAllCategories() { - categories.set(); - } - - void unsetAllCategories() { - categories.reset(); - } - - bool isCategorySet(MessageCategory category) const { - return categories.test(category); - } - - MessageLevel getLevel() const { - return level; - } - - void setLevel(MessageLevel newLevel) { - level = newLevel; - } -}; - -} -} - -#endif /* MAD_COMMON_LOGGERBASE_H_ */ diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp index 05a2b73..bec3618 100644 --- a/src/Common/ModuleManager.cpp +++ b/src/Common/ModuleManager.cpp @@ -22,8 +22,8 @@ #include "ModuleManager.h" -#include "ConfigEntry.h" -#include "Logger.h" +#include +#include //extern const lt_dlsymlist lt_preloaded_symbols[]; @@ -58,13 +58,13 @@ void ModuleManager::doDeinit() { lt_dlexit(); } -bool ModuleManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { +bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { if(handled) return false; if(entry[0].getKey().matches("LoadModule")) { if(!loadModule(entry[0][0].c_str())) - Logger::logf(Logger::ERROR, "Can't load module '%s'.", entry[0][0].c_str()); + Core::Logger::logf(Core::Logger::ERROR, "Can't load module '%s'.", entry[0][0].c_str()); return true; } diff --git a/src/Common/ModuleManager.h b/src/Common/ModuleManager.h index fa7316f..de5535f 100644 --- a/src/Common/ModuleManager.h +++ b/src/Common/ModuleManager.h @@ -20,8 +20,8 @@ #ifndef MAD_COMMON_MODULEMANAGER_H_ #define MAD_COMMON_MODULEMANAGER_H_ -#include "Configurable.h" -#include "Initializable.h" +#include +#include #include #include @@ -32,7 +32,7 @@ namespace Mad { namespace Common { -class ModuleManager : public Configurable, public Initializable { +class ModuleManager : public Core::Configurable, public Core::Initializable { private: static ModuleManager moduleManager; @@ -47,7 +47,7 @@ class ModuleManager : public Configurable, public Initializable { virtual void doInit(); virtual void doDeinit(); - virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled); + virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); public: lt_dlhandle loadModule(const std::string &name); diff --git a/src/Common/RemoteLogger.h b/src/Common/RemoteLogger.h deleted file mode 100644 index 579a54b..0000000 --- a/src/Common/RemoteLogger.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * LogRequestLogger.h - * - * Copyright (C) 2008 Johannes Thorn - * - * 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 . - */ - -#ifndef MAD_COMMON_REMOTELOGGER_H_ -#define MAD_COMMON_REMOTELOGGER_H_ - -#include "LoggerBase.h" - -#include - -namespace Mad { -namespace Common { - -class LogManager; - -class RemoteLogger : public LoggerBase { - protected: - friend class LogManager; - - virtual void logMessage(MessageCategory category, MessageLevel level, time_t messageTimestamp, const std::string &message, const std::string &messageSource) = 0; -}; - -} -} - -#endif /* MAD_COMMON_REMOTELOGGER_H_ */ diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp index 723039f..9aafd7f 100644 --- a/src/Common/Request.cpp +++ b/src/Common/Request.cpp @@ -24,11 +24,11 @@ namespace Common { void Request::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { - signalFinished(Net::Exception((*packet)["Where"], (*packet)["ErrorCode"], (*packet)["SubCode"], (*packet)["SubSubCode"])); + signalFinished(Core::Exception((*packet)["Where"], (*packet)["ErrorCode"], (*packet)["SubCode"], (*packet)["SubSubCode"])); return; } else if(packet->getType() != "OK") { - signalFinished(Net::Exception(Net::Exception::UNEXPECTED_PACKET)); + signalFinished(Core::Exception(Core::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } diff --git a/src/Common/Request.h b/src/Common/Request.h index 4698ae5..ac59e45 100644 --- a/src/Common/Request.h +++ b/src/Common/Request.h @@ -21,7 +21,7 @@ #define MAD_COMMON_REQUEST_H_ #include "RequestHandler.h" -#include +#include #include @@ -42,14 +42,14 @@ class Request : public RequestHandler { bool isFinished; boost::shared_ptr packet; - Net::Exception exception; + Core::Exception exception; - Net::Signals::Signal2, Net::Exception> finished; + Core::Signals::Signal2, Core::Exception> finished; protected: Request() : isFinished(false) {} - void signalFinished(boost::shared_ptr pkt, Net::Exception exp) { + void signalFinished(boost::shared_ptr pkt, Core::Exception exp) { { boost::lock_guard lock(mutex); @@ -65,25 +65,25 @@ class Request : public RequestHandler { } void signalFinished(boost::shared_ptr packet) { - signalFinished(packet, Net::Exception()); + signalFinished(packet, Core::Exception()); } - void signalFinished(Net::Exception exp) { + void signalFinished(Core::Exception exp) { signalFinished(boost::shared_ptr(), exp); } void signalFinished() { - signalFinished(boost::shared_ptr(), Net::Exception()); + signalFinished(boost::shared_ptr(), Core::Exception()); } virtual void sendRequest() = 0; virtual void handlePacket(boost::shared_ptr packet); public: - Net::Signals::Connection connectSignalFinished(const Net::Signals::Signal2, Net::Exception>::slot_type &slot) { + Core::Signals::Connection connectSignalFinished(const Core::Signals::Signal2, Core::Exception>::slot_type &slot) { return finished.connect(slot); } - void disconnectSignalFinished(const Net::Signals::Connection &con) { + void disconnectSignalFinished(const Core::Signals::Connection &con) { finished.disconnect(con); } @@ -94,11 +94,11 @@ class Request : public RequestHandler { finishCond.wait(lock); } - std::pair, Net::Exception> getResult() { + std::pair, Core::Exception> getResult() { boost::lock_guard lock(mutex); if(!isFinished) - return std::make_pair(boost::shared_ptr(), Net::Exception(Net::Exception::NOT_FINISHED)); + return std::make_pair(boost::shared_ptr(), Core::Exception(Core::Exception::NOT_FINISHED)); else return std::make_pair(packet, exception); } diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index f01db41..3deb8c0 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -23,7 +23,7 @@ #include "Connection.h" #include "XmlPacket.h" -#include +#include #include #include @@ -41,7 +41,7 @@ class RequestHandler : private boost::noncopyable { boost::mutex mutex; - Net::Signals::Signal0 finished; + Core::Signals::Signal0 finished; protected: RequestHandler() {} @@ -59,10 +59,10 @@ class RequestHandler : private boost::noncopyable { public: virtual ~RequestHandler() {} - Net::Signals::Connection connectSignalFinished(const Net::Signals::Signal0::slot_type &slot) { + Core::Signals::Connection connectSignalFinished(const Core::Signals::Signal0::slot_type &slot) { return finished.connect(slot); } - void disconnectSignalFinished(const Net::Signals::Connection &con) { + void disconnectSignalFinished(const Core::Signals::Connection &con) { finished.disconnect(con); } }; diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index 942da0a..6c89ab2 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -18,8 +18,8 @@ */ #include "DisconnectRequestHandler.h" -#include -#include "../Logger.h" +#include +#include namespace Mad { namespace Common { @@ -27,11 +27,11 @@ namespace RequestHandlers { void DisconnectRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != "Disconnect") { - Logger::log(Logger::ERROR, "Received an unexpected packet."); + Core::Logger::log(Core::Logger::ERROR, "Received an unexpected packet."); XmlPacket ret; ret.setType("Error"); - ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET); + ret.add("ErrorCode", Core::Exception::UNEXPECTED_PACKET); sendPacket(ret); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 0abc484..b6de0f4 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -18,9 +18,9 @@ */ #include "SimpleRequestHandler.h" -#include "../Logger.h" -#include +#include +#include namespace Mad { namespace Common { @@ -28,11 +28,11 @@ namespace RequestHandlers { void SimpleRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { - Logger::log(Logger::ERROR, "Received an unexpected packet."); + Core::Logger::log(Core::Logger::ERROR, "Received an unexpected packet."); XmlPacket ret; ret.setType("Error"); - ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET); + ret.add("ErrorCode", Core::Exception::UNEXPECTED_PACKET); sendPacket(ret); @@ -47,7 +47,7 @@ void SimpleRequestHandler::handlePacket(boost::shared_ptr packe try { handler(packet, &ret); } - catch(Net::Exception e) { + catch(Core::Exception e) { ret.setType("Error"); ret.add("ErrorCode", e.getErrorCode()); ret.add("SubCode", e.getSubCode()); diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp index 25d2f23..95bdd30 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.cpp +++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp @@ -38,7 +38,7 @@ void StatusRequestHandler::handleRequest(boost::shared_ptrgetMemoryInfo(&totalMem, &freeMem, &totalSwap, &freeSwap); SystemManager::get()->getLoadInfo(¤tLoad, &nProcesses, &loadAvg1, &loadAvg5, &loadAvg15); } - catch(Net::Exception e) {} + catch(Core::Exception e) {} ret->setType("OK"); diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index b443292..a8b817f 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -19,7 +19,7 @@ #include "RequestManager.h" #include "RequestHandlers/DisconnectRequestHandler.h" -#include "Logger.h" +#include #include @@ -96,14 +96,14 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr request = requestMap.findRequest(connection, requestId); if(request) { lock.unlock(); - Net::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); + Core::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); return; } if(!requestMap.isConnectionRegistered(connection)) { // TODO: Error - Logger::log(Logger::ERROR, "Received a packet from an unregistered connection."); + Core::Logger::log(Core::Logger::ERROR, "Received a packet from an unregistered connection."); return; } @@ -122,7 +122,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptrpushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); + Core::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); return; } @@ -130,11 +130,11 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptrgetType().c_str()); + Core::Logger::logf(Core::Logger::ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str()); XmlPacket ret; ret.setType("Error"); - ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET); + ret.add("ErrorCode", Core::Exception::UNEXPECTED_PACKET); connection->sendPacket(ret, requestId); } @@ -143,20 +143,20 @@ bool RequestManager::sendRequest(Connection *connection, boost::shared_ptr lock(mutex); if(!requestMap.isConnectionRegistered(connection)) { - Logger::log(Logger::CRITICAL, "Trying to send a request over an unregistered connecion."); + Core::Logger::log(Core::Logger::CRITICAL, "Trying to send a request over an unregistered connecion."); return false; } uint16_t requestId = _getUnusedRequestId(connection); if(request->isFinished || !requestMap.addRequest(connection, requestId, request)) { - Logger::log(Logger::CRITICAL, "Trying resend a request."); + Core::Logger::log(Core::Logger::CRITICAL, "Trying resend a request."); return false; } request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId)); lock.unlock(); - Net::ThreadManager::get()->pushWork(boost::bind(&Request::sendRequest, request)); + Core::ThreadManager::get()->pushWork(boost::bind(&Request::sendRequest, request)); return true; } diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index e66b0c1..2dd892e 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -31,11 +31,6 @@ #include namespace Mad { - -namespace Net { -class Packet; -} - namespace Common { class RequestManager : boost::noncopyable { diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 249bbc1..6c4fa0d 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -32,11 +32,11 @@ void DisconnectRequest::sendRequest() { void DisconnectRequest::handlePacket(boost::shared_ptr packet) { if(packet->getType() == "Error") { - signalFinished(Net::Exception((*packet)["Where"], (*packet)["ErrorCode"], (*packet)["SubCode"], (*packet)["SubSubCode"])); + signalFinished(Core::Exception((*packet)["Where"], (*packet)["ErrorCode"], (*packet)["SubCode"], (*packet)["SubSubCode"])); return; } else if(packet->getType() != "OK") { - signalFinished(Net::Exception(Net::Exception::UNEXPECTED_PACKET)); + signalFinished(Core::Exception(Core::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h index 1543207..418fa2b 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -31,28 +31,28 @@ class SystemBackend { protected: friend class SystemManager; - virtual void getUptimeInfo(unsigned long *uptime _UNUSED_PARAMETER_, unsigned long *idleTime _UNUSED_PARAMETER_) throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void getUptimeInfo(unsigned long *uptime _UNUSED_PARAMETER_, unsigned long *idleTime _UNUSED_PARAMETER_) throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } - virtual void getMemoryInfo(unsigned long *totalMem _UNUSED_PARAMETER_, unsigned long *freeMem _UNUSED_PARAMETER_, unsigned long *totalSwap _UNUSED_PARAMETER_, unsigned long *freeSwap _UNUSED_PARAMETER_) throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void getMemoryInfo(unsigned long *totalMem _UNUSED_PARAMETER_, unsigned long *freeMem _UNUSED_PARAMETER_, unsigned long *totalSwap _UNUSED_PARAMETER_, unsigned long *freeSwap _UNUSED_PARAMETER_) throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } - virtual void getLoadInfo(unsigned long *currentLoad _UNUSED_PARAMETER_, unsigned long *nProcesses _UNUSED_PARAMETER_, float *loadAvg1 _UNUSED_PARAMETER_, float *loadAvg5 _UNUSED_PARAMETER_, float *loadAvg15 _UNUSED_PARAMETER_) throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void getLoadInfo(unsigned long *currentLoad _UNUSED_PARAMETER_, unsigned long *nProcesses _UNUSED_PARAMETER_, float *loadAvg1 _UNUSED_PARAMETER_, float *loadAvg5 _UNUSED_PARAMETER_, float *loadAvg15 _UNUSED_PARAMETER_) throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } - virtual void getFSInfo(std::vector *fsInfo _UNUSED_PARAMETER_) throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void getFSInfo(std::vector *fsInfo _UNUSED_PARAMETER_) throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } - virtual void shutdown() throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void shutdown() throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } - virtual void reboot() throw(Net::Exception) { - throw Net::Exception(Net::Exception::NOT_IMPLEMENTED); + virtual void reboot() throw(Core::Exception) { + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); } virtual int getPriority() const { diff --git a/src/Common/SystemManager.cpp b/src/Common/SystemManager.cpp index e58c2ba..fac50d5 100644 --- a/src/Common/SystemManager.cpp +++ b/src/Common/SystemManager.cpp @@ -34,16 +34,16 @@ bool SystemManager::Compare::operator() (boost::shared_ptr b1, bo } -void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->getUptimeInfo(uptime, idleTime); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } @@ -51,16 +51,16 @@ void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime throw e; } -void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->getMemoryInfo(totalMem, freeMem, totalSwap, freeSwap); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } @@ -68,16 +68,16 @@ void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMe throw e; } -void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->getLoadInfo(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } @@ -85,16 +85,16 @@ void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProc throw e; } -void SystemManager::getFSInfo(std::vector *fsInfo) throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::getFSInfo(std::vector *fsInfo) throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->getFSInfo(fsInfo); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } @@ -102,16 +102,16 @@ void SystemManager::getFSInfo(std::vector *fsInfo) throw(Net::Exception) throw e; } -void SystemManager::shutdown() throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::shutdown() throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->shutdown(); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } @@ -119,16 +119,16 @@ void SystemManager::shutdown() throw(Net::Exception) { throw e; } -void SystemManager::reboot() throw(Net::Exception) { - Net::Exception e(Net::Exception::NOT_IMPLEMENTED); +void SystemManager::reboot() throw(Core::Exception) { + Core::Exception e(Core::Exception::NOT_IMPLEMENTED); for(std::set >::iterator backend = backends.begin(); backend != backends.end(); ++backend) { try { (*backend)->reboot(); return; } - catch(Net::Exception e2) { - if(e.getErrorCode() == Net::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Net::Exception::NOT_IMPLEMENTED) + catch(Core::Exception e2) { + if(e.getErrorCode() == Core::Exception::NOT_IMPLEMENTED && e2.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) e = e2; } } diff --git a/src/Common/SystemManager.h b/src/Common/SystemManager.h index 9252b2b..6870489 100644 --- a/src/Common/SystemManager.h +++ b/src/Common/SystemManager.h @@ -26,7 +26,7 @@ #include -#include +#include namespace Mad { namespace Common { @@ -62,14 +62,14 @@ class SystemManager { backends.erase(backend); } - void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Net::Exception); - void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Net::Exception); - void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Net::Exception); + void getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception); + void getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception); + void getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception); - void getFSInfo(std::vector *fsInfo) throw(Net::Exception); + void getFSInfo(std::vector *fsInfo) throw(Core::Exception); - void shutdown() throw(Net::Exception); - void reboot() throw(Net::Exception); + void shutdown() throw(Core::Exception); + void reboot() throw(Core::Exception); static SystemManager *get() { return &systemManager; diff --git a/src/Common/Tokenizer.cpp b/src/Common/Tokenizer.cpp deleted file mode 100644 index 8b01482..0000000 --- a/src/Common/Tokenizer.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Tokenizer.cpp - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#include "Tokenizer.h" - -namespace Mad { -namespace Common { - -const std::string Tokenizer::delimiters = " \t\n\"'\\"; - - -std::vector Tokenizer::split(const std::string &str) { - std::vector ret; - - for(size_t s = 0; s < str.length();) { - size_t index = str.find_first_of(delimiters, s); - size_t length = (index == std::string::npos) ? std::string::npos : index-s; - - ret.push_back(str.substr(s, length)); - - if(index != std::string::npos) { - size_t index2 = str.find_first_not_of(delimiters, index); - - length = (index2 == std::string::npos) ? std::string::npos : index2-index; - - ret.push_back(str.substr(index, length)); - - if(index2 != std::string::npos) - s = index2; - else - break; - } - else - break; - } - - return ret; -} - -bool Tokenizer::tokenize(const std::string &str, std::vector &out) { - std::vector splitString = split(str); - - bool singleQuotes = false, doubleQuotes = false, escape = false; - std::string token; - bool forceToken = false; - - out.clear(); - - for(std::vector::iterator s = splitString.begin(); s != splitString.end(); ++s) { - token += *s; - escape = false; - - if(++s == splitString.end()) - break; - - for(std::string::iterator c = s->begin(); c != s->end(); ++c) { - if(*c == '\n' && escape) { - escape = false; - - if(doubleQuotes) - continue; - } - - if(escape || (singleQuotes && *c != '\'')) { - token += *c; - - escape = false; - continue; - } - - switch(*c) { - case ' ': - case '\t': - case '\n': - if(doubleQuotes) { - token += *c; - } - else { - if(!token.empty() || forceToken) { - out.push_back(token); - token.clear(); - forceToken = false; - } - } - break; - - case '"': - doubleQuotes = !doubleQuotes; - forceToken = true; - break; - - case '\'': - if(doubleQuotes) { - token += *c; - } - else { - singleQuotes = !singleQuotes; - forceToken = true; - } - break; - - case '\\': - escape = true; - } - } - } - - if(!token.empty() || forceToken) - out.push_back(token); - - return !(singleQuotes || doubleQuotes || escape); -} - -} -} diff --git a/src/Common/Tokenizer.h b/src/Common/Tokenizer.h deleted file mode 100644 index 6b8436b..0000000 --- a/src/Common/Tokenizer.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Tokenizer.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_TOKENIZER_H_ -#define MAD_COMMON_TOKENIZER_H_ - -#include -#include - -namespace Mad { -namespace Common { - -class Tokenizer { - private: - static const std::string delimiters; - - Tokenizer(); - - static std::vector split(const std::string &str); - - public: - static bool tokenize(const std::string &str, std::vector &out); -}; - -} -} - -#endif /* MAD_COMMON_TOKENIZER_H_ */ -- cgit v1.2.3