summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-12-17 21:32:20 +0100
committerMatthias Schiffer <matthias@gamezock.de>2008-12-17 21:32:20 +0100
commit389960211861736ef321df82f6abcb59f6302897 (patch)
treecbf44ddc93736ad8f059b947a08c26a31d242ee7 /src
parente28a9c25c143635ffe8a1f9cee1d377a69a4f923 (diff)
downloadmad-389960211861736ef321df82f6abcb59f6302897.tar
mad-389960211861736ef321df82f6abcb59f6302897.zip
Sinnlose Klassen SharedPtr und SingletonPtr entfernt
Diffstat (limited to 'src')
-rw-r--r--src/Client/InformationManager.cpp6
-rw-r--r--src/Client/InformationManager.h19
-rw-r--r--src/Common/ConfigManager.cpp9
-rw-r--r--src/Common/ConfigManager.h3
-rw-r--r--src/Common/Initializable.cpp9
-rw-r--r--src/Common/Initializable.h5
-rw-r--r--src/Common/LogManager.cpp35
-rw-r--r--src/Common/LogManager.h25
-rw-r--r--src/Common/Makefile.am3
-rw-r--r--src/Common/Makefile.in3
-rw-r--r--src/Common/RequestManager.cpp2
-rw-r--r--src/Common/RequestManager.h9
-rw-r--r--src/Common/SharedPtr.h101
-rw-r--r--src/Common/SingletonPtr.h84
-rw-r--r--src/Core/ConnectionManager.cpp6
-rw-r--r--src/Core/ConnectionManager.h13
-rw-r--r--src/mad.cpp2
-rw-r--r--src/madc.cpp2
18 files changed, 68 insertions, 268 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
index a2f67cb..cef0ce1 100644
--- a/src/Client/InformationManager.cpp
+++ b/src/Client/InformationManager.cpp
@@ -28,7 +28,7 @@
namespace Mad {
namespace Client {
-Common::SingletonPtr<InformationManager> InformationManager::informationManager;
+InformationManager InformationManager::informationManager;
void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
@@ -56,11 +56,11 @@ void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection
}
-InformationManager::InformationManager() : updating(false) {
+void InformationManager::doInit() {
Common::RequestManager::get()->registerPacketType<DaemonStateUpdateRequest>(Net::Packet::DAEMON_STATE_UPDATE);
}
-InformationManager::~InformationManager() {
+void InformationManager::doDeinit() {
Common::RequestManager::get()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE);
}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
index 1464e2f..80dab9f 100644
--- a/src/Client/InformationManager.h
+++ b/src/Client/InformationManager.h
@@ -24,8 +24,8 @@
#include <memory>
#include <Common/HostInfo.h>
+#include <Common/Initializable.h>
#include <Common/Request.h>
-#include <Common/SingletonPtr.h>
namespace Mad {
@@ -40,7 +40,7 @@ class HostListPacket;
namespace Client {
-class InformationManager {
+class InformationManager : public Common::Initializable {
private:
class DaemonStateUpdateRequest : public Common::RequestHandler {
protected:
@@ -50,7 +50,7 @@ class InformationManager {
DaemonStateUpdateRequest() {}
};
- static Common::SingletonPtr<InformationManager> informationManager;
+ static InformationManager informationManager;
std::map<std::string, Common::HostInfo> daemons;
@@ -60,16 +60,19 @@ class InformationManager {
InformationManager(const InformationManager &o);
InformationManager& operator=(const InformationManager &o);
+ InformationManager() : updating(false) {}
+
void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request);
+ protected:
+ virtual void doInit();
+ virtual void doDeinit();
+
public:
- static InformationManager* get() {
- return informationManager.get();
+ static InformationManager *get() {
+ return &informationManager;
}
- InformationManager();
- virtual ~InformationManager();
-
void updateDaemonList(Net::Connection *con);
bool isUpdating() const {
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp
index 6727cc3..3bf0c85 100644
--- a/src/Common/ConfigManager.cpp
+++ b/src/Common/ConfigManager.cpp
@@ -21,6 +21,7 @@
#include "ConfigEntry.h"
#include "Configurable.h"
#include "Logger.h"
+#include "LogManager.h"
#include "Tokenizer.h"
#include <fstream>
@@ -128,5 +129,13 @@ void ConfigManager::finish() {
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
index 036eed7..e7885b8 100644
--- a/src/Common/ConfigManager.h
+++ b/src/Common/ConfigManager.h
@@ -41,7 +41,8 @@ class ConfigManager {
std::set<Configurable*, Compare> configurables;
bool finished;
- ConfigManager() : finished(false) {}
+ ConfigManager();
+ ~ConfigManager();
void handleConfigEntry(const ConfigEntry &entry);
diff --git a/src/Common/Initializable.cpp b/src/Common/Initializable.cpp
index 65893a1..2a9aef3 100644
--- a/src/Common/Initializable.cpp
+++ b/src/Common/Initializable.cpp
@@ -21,24 +21,17 @@
#include "ConfigManager.h"
#include "Configurable.h"
-#include "LogManager.h"
#include "Logger.h"
namespace Mad {
namespace Common {
std::stack<Initializable*> Initializable::initializedObjects;
-bool Initializable::logInit = false;
void Initializable::init() {
if(initialized)
return;
- if(!logInit) {
- logInit = true;
- LogManager::get();
- }
-
if(initializing) {
Logger::log(Logger::CRITICAL, "Fatal initialization error: cyclic dependencies.");
std::terminate();
@@ -70,8 +63,6 @@ void Initializable::deinit() {
initializedObjects.pop();
}
-
- logInit = false;
}
}
diff --git a/src/Common/Initializable.h b/src/Common/Initializable.h
index 9f177da..6f67678 100644
--- a/src/Common/Initializable.h
+++ b/src/Common/Initializable.h
@@ -25,14 +25,9 @@
namespace Mad {
namespace Common {
-template <typename T> class SingletonPtr;
-
class Initializable {
private:
- template <typename T> friend class SingletonPtr;
-
static std::stack<Initializable*> initializedObjects;
- static bool logInit;
bool initializing;
bool initialized;
diff --git a/src/Common/LogManager.cpp b/src/Common/LogManager.cpp
index 5e902fa..5182a97 100644
--- a/src/Common/LogManager.cpp
+++ b/src/Common/LogManager.cpp
@@ -25,7 +25,7 @@
namespace Mad {
namespace Common {
-SingletonPtr<LogManager> LogManager::logManager;
+LogManager LogManager::logManager;
bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
@@ -35,7 +35,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
if(entry[0].getKey().matches("Logger")) {
if(entry[0][0].matches("Console")) {
if(entry[1].empty()) {
- registerLogger(SharedPtr<Logger>(new Backends::ConsoleLogger()));
+ registerLogger(static_cast<Logger*>(&consoleLogger));
return true;
}
}
@@ -49,19 +49,10 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
}
void LogManager::configFinished() {
- SharedPtr<Backends::ConsoleLogger> consoleLogger;
+ if(loggers.empty())
+ registerLogger(static_cast<Logger*>(&consoleLogger));
- if(loggers.empty() || remoteLoggers.empty()) {
- consoleLogger = SharedPtr<Backends::ConsoleLogger>(new Backends::ConsoleLogger());
-
- if(loggers.empty())
- registerLogger(consoleLogger.cast<Logger>());
-
- if(remoteLoggers.empty())
- registerLogger(consoleLogger.cast<RemoteLogger>());
- }
-
- std::auto_ptr<std::queue<Message> > queue = messageQueue;
+ std::auto_ptr<std::queue<Message> > queue = messageQueue;
while(!queue->empty()) {
const Message &message = queue->front();
@@ -85,11 +76,9 @@ void LogManager::log(MessageCategory category, MessageLevel level, time_t timest
return;
}
- for(std::set<SharedPtr<Logger> >::iterator it = loggers.begin(); it != loggers.end(); ++it) {
- SharedPtr<Logger> logger = *it;
-
- if(logger->getLevel() >= level && logger->isCategorySet(category))
- logger->logMessage(category, level, timestamp, message);
+ for(std::set<Logger*>::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) {
+ if((*logger)->getLevel() >= level && (*logger)->isCategorySet(category))
+ (*logger)->logMessage(category, level, timestamp, message);
}
}
@@ -100,11 +89,9 @@ void LogManager::log(MessageCategory category, MessageLevel level, time_t timest
return;
}
- for(std::set<SharedPtr<RemoteLogger> >::iterator it = remoteLoggers.begin(); it != remoteLoggers.end(); ++it) {
- SharedPtr<RemoteLogger> logger = *it;
-
- if(logger->getLevel() >= level && logger->isCategorySet(category))
- logger->logMessage(category, level, timestamp, message, source);
+ for(std::set<RemoteLogger*>::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) {
+ if((*logger)->getLevel() >= level && (*logger)->isCategorySet(category))
+ (*logger)->logMessage(category, level, timestamp, message, source);
}
}
diff --git a/src/Common/LogManager.h b/src/Common/LogManager.h
index 7c0f1e0..5fc3824 100644
--- a/src/Common/LogManager.h
+++ b/src/Common/LogManager.h
@@ -23,8 +23,7 @@
#include "Configurable.h"
#include "Logger.h"
#include "RemoteLogger.h"
-#include "SingletonPtr.h"
-#include "SharedPtr.h"
+#include "Backends/ConsoleLogger.h"
#include <memory>
#include <queue>
@@ -53,42 +52,44 @@ class LogManager : public Configurable {
std::string source;
};
- static SingletonPtr<LogManager> logManager;
+ static LogManager logManager;
- std::set<SharedPtr<Logger> > loggers;
- std::set<SharedPtr<RemoteLogger> > remoteLoggers;
+ Backends::ConsoleLogger consoleLogger;
+
+ std::set<Logger*> loggers;
+ std::set<RemoteLogger*> remoteLoggers;
std::auto_ptr<std::queue<Message> > messageQueue;
std::auto_ptr<std::queue<RemoteMessage> > remoteMessageQueue;
+ LogManager() : messageQueue(new std::queue<Message>()), remoteMessageQueue(new std::queue<RemoteMessage>()) {}
+
protected:
virtual bool handleConfigEntry(const ConfigEntry &entry, bool handled);
virtual void configFinished();
public:
- LogManager() : messageQueue(new std::queue<Message>()), remoteMessageQueue(new std::queue<RemoteMessage>()) {}
-
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(SharedPtr<Logger> logger) {
+ void registerLogger(Logger *logger) {
loggers.insert(logger);
}
- void unregisterLogger(SharedPtr<Logger> logger) {
+ void unregisterLogger(Logger *logger) {
loggers.erase(logger);
}
- void registerLogger(SharedPtr<RemoteLogger> logger) {
+ void registerLogger(RemoteLogger *logger) {
remoteLoggers.insert(logger);
}
- void unregisterLogger(SharedPtr<RemoteLogger> logger) {
+ void unregisterLogger(RemoteLogger *logger) {
remoteLoggers.erase(logger);
}
static LogManager *get() {
- return logManager.get();
+ return &logManager;
}
};
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index 755ab79..4494745 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -7,5 +7,4 @@ libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHa
noinst_HEADERS = ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h Initializable.h \
Logger.h LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
- RequestBase.h RequestHandler.h RequestManager.h SharedPtr.h SingletonPtr.h \
- SystemBackend.h Tokenizer.h
+ RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Tokenizer.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 6f8de60..ed307b0 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -233,8 +233,7 @@ libcommon_la_SOURCES = ConfigEntry.cpp ConfigManager.cpp Exception.cpp Initializ
libcommon_la_LIBADD = Backends/libbackends.la Requests/librequests.la RequestHandlers/librequesthandlers.la
noinst_HEADERS = ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h Initializable.h \
Logger.h LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
- RequestBase.h RequestHandler.h RequestManager.h SharedPtr.h SingletonPtr.h \
- SystemBackend.h Tokenizer.h
+ RequestBase.h RequestHandler.h RequestManager.h SystemBackend.h Tokenizer.h
all: all-recursive
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index cc846c6..d852f5d 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -30,7 +30,7 @@
namespace Mad {
namespace Common {
-SingletonPtr<RequestManager> RequestManager::requestManager;
+RequestManager RequestManager::requestManager;
RequestManager::RequestMap::~RequestMap() {
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index 0bc8080..c2f58d2 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -20,7 +20,6 @@
#ifndef MAD_COMMON_REQUESTMANAGER_H_
#define MAD_COMMON_REQUESTMANAGER_H_
-#include "SingletonPtr.h"
#include <Net/Connection.h>
#include <map>
@@ -65,7 +64,7 @@ class RequestManager {
}
};
- static SingletonPtr<RequestManager> requestManager;
+ static RequestManager requestManager;
std::map<Net::Connection*,RequestMap*> requestMaps;
bool core;
@@ -83,13 +82,13 @@ class RequestManager {
void receiveHandler(Net::Connection *connection, const Net::Packet &packet);
+ RequestManager();
+
public:
static RequestManager* get() {
- return requestManager.get();
+ return &requestManager;
}
- RequestManager();
-
bool isCore() const {return core;}
void setCore(bool newCore) {
core = newCore;
diff --git a/src/Common/SharedPtr.h b/src/Common/SharedPtr.h
deleted file mode 100644
index 3696344..0000000
--- a/src/Common/SharedPtr.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * SharedPtr.h
- *
- * Copyright (C) 2008 Johannes Thorn <dante@g4t3.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/>.
- */
-
-#ifndef MAD_COMMON_SHAREDPTR_H_
-#define MAD_COMMON_SHAREDPTR_H_
-
-namespace Mad {
-namespace Common {
-
-template <typename T>
-class SharedPtr {
- protected:
- class Counter {
- public:
- Counter(T *o) : object(o), refCount(1), cCount(new unsigned int(1)) {}
- Counter(T *o, unsigned int *count) : object(o), refCount(1), cCount(count) {++*cCount;}
-
- virtual ~Counter() {
- if(--cCount)
- return;
-
- if(object)
- delete object;
-
- delete cCount;
- }
-
- T *object;
- unsigned int refCount;
- unsigned int *cCount;
- };
-
- Counter *counter;
-
- template <typename T2>
- class CastPtr : public SharedPtr<T2> {
- public:
- CastPtr(T *o, unsigned int *cCount) : SharedPtr<T2>(o, cCount) {}
- };
-
- SharedPtr(T *o, unsigned int *cCount) : counter(new Counter(o, cCount)) {}
-
- public:
- SharedPtr(T *o = 0) : counter(new Counter(o)) {}
-
- SharedPtr(const SharedPtr<T> &c) : counter(c.counter) {
- ++counter->refCount;
- }
-
- virtual ~SharedPtr() {
- if(--counter->refCount == 0)
- delete counter;
- }
-
- SharedPtr<T>& operator=(const SharedPtr<T>& c) {
- ++c.counter->refCount;
- if(--counter->refCount == 0)
- delete counter;
-
- counter = c.counter;
- return *this;
- }
-
- bool empty() const {
- return counter->object;
- }
-
- T* operator->() {return counter->object;}
- T& operator*() {return *counter->object;}
-
- const T* operator->() const {return counter->object;}
- const T& operator*() const {return *counter->object;}
-
- bool operator<(const SharedPtr<T> &o) const {return counter->object < o.counter->object;}
- bool operator==(const SharedPtr<T> &o) const {return counter->object == o.counter->object;}
-
- template <typename T2> SharedPtr<T2> cast() const {
- return CastPtr<T2>(counter->object, counter->cCount);
- }
-};
-
-}
-}
-
-#endif /*MAD_COMMON_SHAREDPTR_H_*/
diff --git a/src/Common/SingletonPtr.h b/src/Common/SingletonPtr.h
deleted file mode 100644
index 03d0040..0000000
--- a/src/Common/SingletonPtr.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * SingletonPtr.h
- *
- * 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/>.
- */
-
-#ifndef MAD_COMMON_SINGLETONPTR_H_
-#define MAD_COMMON_SINGLETONPTR_H_
-
-#include "Initializable.h"
-#include "Configurable.h"
-#include "ConfigManager.h"
-
-namespace Mad {
-namespace Common {
-
-template <typename T>
-class SingletonPtr : public virtual Initializable {
- private:
- T *ptr;
-
- protected:
- virtual void doInit() {
- ptr = new T();
-
- Initializable *in = dynamic_cast<Initializable*>(ptr);
- if(in) {
- in->initialized = true;
- in->doInit();
- }
-
- Configurable *c = dynamic_cast<Configurable*>(ptr);
- if(c)
- ConfigManager::get()->registerConfigurable(c);
-
- if(in) {
- initializing = false;
- initialized = true;
- }
- }
-
- virtual void doDeinit() {
- Configurable *c = dynamic_cast<Configurable*>(ptr);
- if(c)
- ConfigManager::get()->unregisterConfigurable(c);
-
- Initializable *in = dynamic_cast<Initializable*>(ptr);
- if(in) {
- in->doDeinit();
- in->initialized = false;
- }
-
- delete ptr;
- ptr = 0;
- }
-
- public:
- SingletonPtr() : ptr(0) {}
-
- T *get() {
- if(!ptr)
- init();
-
- return ptr;
- }
-};
-
-}
-}
-
-#endif /* MAD_COMMON_SINGLETONPTR_H_ */
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index 63b29e1..c347e29 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -42,7 +42,7 @@
namespace Mad {
namespace Core {
-Common::SingletonPtr<ConnectionManager> ConnectionManager::connectionManager;
+ConnectionManager ConnectionManager::connectionManager;
void ConnectionManager::updateState(const std::string &name, Common::HostInfo::State state) {
@@ -129,7 +129,7 @@ void ConnectionManager::configFinished() {
}
}
-ConnectionManager::ConnectionManager() {
+void ConnectionManager::doInit() {
Common::RequestManager::get()->setCore(true);
Net::Connection::init();
@@ -146,7 +146,7 @@ ConnectionManager::ConnectionManager() {
Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG);
}
-ConnectionManager::~ConnectionManager() {
+void ConnectionManager::doDeinit() {
for(std::list<Net::ServerConnection*>::iterator con = daemonConnections.begin(); con != daemonConnections.end(); ++con)
delete *con;
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index fdc8a46..4623ab6 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -29,7 +29,6 @@
#include <Common/HostInfo.h>
#include <Common/Initializable.h>
#include <Common/RequestManager.h>
-#include <Common/SingletonPtr.h>
#include <Net/IPAddress.h>
@@ -46,7 +45,7 @@ namespace Core {
class ConnectionManager : public Common::Configurable, public Common::Initializable {
private:
- static Common::SingletonPtr<ConnectionManager> connectionManager;
+ static ConnectionManager connectionManager;
std::string x509TrustFile, x509CrlFile, x509CertFile, x509KeyFile;
@@ -67,16 +66,18 @@ class ConnectionManager : public Common::Configurable, public Common::Initializa
void updateState(const std::string &name, Common::HostInfo::State state);
+ ConnectionManager() {}
+
protected:
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool handled);
virtual void configFinished();
- public:
- ConnectionManager();
- virtual ~ConnectionManager();
+ virtual void doInit();
+ virtual void doDeinit();
+ public:
static ConnectionManager* get() {
- return connectionManager.get();
+ return &connectionManager;
}
void run();
diff --git a/src/mad.cpp b/src/mad.cpp
index ccf4625..f5fcaa6 100644
--- a/src/mad.cpp
+++ b/src/mad.cpp
@@ -64,7 +64,7 @@ int main() {
Common::RequestManager::get()->registerConnection(connection);
- Common::SharedPtr<Common::Logger> networkLogger = new Daemon::Backends::NetworkLogger(connection);
+ Common::Logger *networkLogger = new Daemon::Backends::NetworkLogger(connection);
Common::LogManager::get()->registerLogger(networkLogger);
diff --git a/src/madc.cpp b/src/madc.cpp
index 5dcb6ad..ac3b3a3 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -79,7 +79,7 @@ int main(int argc, char *argv[]) {
Net::Connection::init();
- Common::LogManager::get();
+ Client::InformationManager::get()->init();
Common::ConfigManager::get()->finish();