summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-11-17 08:25:02 +0100
committerMatthias Schiffer <matthias@gamezock.de>2008-11-17 08:25:02 +0100
commit62ca019532b28527facf6ab133742c2a190f15d6 (patch)
tree2b02963ed8a8a0d21dbe42885c2e284d3c60620c /src
parent2b83ae7c71dc706fb4fd7b4efc4a8ffee8dfe522 (diff)
downloadmad-62ca019532b28527facf6ab133742c2a190f15d6.tar
mad-62ca019532b28527facf6ab133742c2a190f15d6.zip
Configurable von Initializable ableiten; InformationManager ist jetzt auch ein Initializable
Diffstat (limited to 'src')
-rw-r--r--src/Client/InformationManager.cpp33
-rw-r--r--src/Client/InformationManager.h26
-rw-r--r--src/Common/Configurable.h4
-rw-r--r--src/Common/LogManager.cpp8
-rw-r--r--src/Common/LogManager.h2
-rw-r--r--src/Core/ConnectionManager.h2
-rw-r--r--src/madc.cpp5
7 files changed, 51 insertions, 29 deletions
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
index 8a3227c..1d54498 100644
--- a/src/Client/InformationManager.cpp
+++ b/src/Client/InformationManager.cpp
@@ -28,7 +28,7 @@
namespace Mad {
namespace Client {
-std::auto_ptr<InformationManager> InformationManager::informationManager;
+InformationManager InformationManager::informationManager;
void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection *connection, const Net::Packet &packet) {
@@ -44,8 +44,8 @@ void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection
Net::Packets::HostStatePacket hostStatePacket(packet);
- std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find(hostStatePacket.getName());
- if(host != informationManager->daemons.end())
+ std::map<std::string, Common::HostInfo>::iterator host = informationManager.daemons.find(hostStatePacket.getName());
+ if(host != informationManager.daemons.end())
host->second.setState(hostStatePacket.getState());
else
Common::Logger::log(Common::Logger::WARNING, "Received a state update for an unknown host.");
@@ -56,20 +56,29 @@ void InformationManager::DaemonStateUpdateRequest::handlePacket(Net::Connection
}
-InformationManager::InformationManager(Net::Connection *connection) : initFinished(false) {
- Common::RequestManager::getRequestManager()->sendRequest(connection,
- std::auto_ptr<Common::RequestBase>(
- new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished))
- )
- );
+void InformationManager::doInit() {
+ Common::RequestManager::getRequestManager()->init();
Common::RequestManager::getRequestManager()->registerPacketType<DaemonStateUpdateRequest>(Net::Packet::DAEMON_STATE_UPDATE);
}
-InformationManager::~InformationManager() {
+void InformationManager::doUninit() {
Common::RequestManager::getRequestManager()->unregisterPacketType(Net::Packet::DAEMON_STATE_UPDATE);
}
+void InformationManager::updateDaemonList(Net::Connection *con) {
+ if(updating)
+ return;
+
+ Common::RequestManager::getRequestManager()->sendRequest(con,
+ std::auto_ptr<Common::RequestBase>(
+ new Requests::DaemonListRequest(sigc::mem_fun(this, &InformationManager::daemonListRequestFinished))
+ )
+ );
+
+ updating = true;
+}
+
void InformationManager::daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request) {
try {
const std::vector<Common::HostInfo> &hostInfo = request.getResult().getHostInfo();
@@ -78,12 +87,12 @@ void InformationManager::daemonListRequestFinished(const Common::Request<Net::Pa
daemons.clear();
daemons.insert(std::make_pair(daemon->getName(), *daemon));
}
-
- initFinished = true;
}
catch(Common::Exception &e) {
Common::Logger::logf(Common::Logger::CRITICAL, "Host list request failed: %s", e.strerror().c_str());
}
+
+ updating = false;
}
}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
index bf2d67a..739c359 100644
--- a/src/Client/InformationManager.h
+++ b/src/Client/InformationManager.h
@@ -24,6 +24,7 @@
#include <memory>
#include <Common/HostInfo.h>
+#include <Common/Initializable.h>
#include <Common/Request.h>
namespace Mad {
@@ -39,7 +40,7 @@ class HostListPacket;
namespace Client {
-class InformationManager {
+class InformationManager : public Common::Initializable {
private:
class DaemonStateUpdateRequest : public Common::RequestHandler {
protected:
@@ -49,32 +50,33 @@ class InformationManager {
DaemonStateUpdateRequest() {}
};
- static std::auto_ptr<InformationManager> informationManager;
+ static InformationManager informationManager;
std::map<std::string, Common::HostInfo> daemons;
- bool initFinished;
+
+ bool updating;
// Prevent shallow copy
InformationManager(const InformationManager &o);
InformationManager& operator=(const InformationManager &o);
- InformationManager(Net::Connection *connection);
+ InformationManager() : updating(false) {}
void daemonListRequestFinished(const Common::Request<Net::Packets::HostListPacket> &request);
- public:
- ~InformationManager();
+ protected:
+ virtual void doInit();
+ virtual void doUninit();
+ public:
static InformationManager* getInformationManager() {
- return informationManager.get();
+ return &informationManager;
}
- static void init(Net::Connection *connection) {
- informationManager = std::auto_ptr<InformationManager>(new InformationManager(connection));
- }
+ void updateDaemonList(Net::Connection *con);
- bool isInitialised() const {
- return initFinished;
+ bool isUpdating() const {
+ return updating;
}
const std::map<std::string, Common::HostInfo>& getDaemons() const {
diff --git a/src/Common/Configurable.h b/src/Common/Configurable.h
index 47f919d..90641a0 100644
--- a/src/Common/Configurable.h
+++ b/src/Common/Configurable.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_CONFIGURABLE_H_
#define MAD_COMMON_CONFIGURABLE_H_
+#include "Initializable.h"
+
namespace Mad {
namespace Common {
class ConfigEntry;
class ConfigManager;
-class Configurable {
+class Configurable : virtual public Initializable {
public:
virtual ~Configurable() {}
diff --git a/src/Common/LogManager.cpp b/src/Common/LogManager.cpp
index 7b4e898..d974d7c 100644
--- a/src/Common/LogManager.cpp
+++ b/src/Common/LogManager.cpp
@@ -69,6 +69,14 @@ void LogManager::configFinished() {
log(message.category, message.level, message.timestamp, message.message);
queue->pop();
}
+
+ std::auto_ptr<std::queue<RemoteMessage> > queue2 = remoteMessageQueue;
+
+ while(!queue2->empty()) {
+ const RemoteMessage &message = queue2->front();
+ log(message.category, message.level, message.timestamp, message.message, message.source);
+ queue2->pop();
+ }
}
void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) {
diff --git a/src/Common/LogManager.h b/src/Common/LogManager.h
index c1bba9f..846bc95 100644
--- a/src/Common/LogManager.h
+++ b/src/Common/LogManager.h
@@ -33,7 +33,7 @@
namespace Mad {
namespace Common {
-class LogManager : public Initializable, public Configurable {
+class LogManager : public Configurable {
private:
typedef LoggerBase::MessageCategory MessageCategory;
typedef LoggerBase::MessageLevel MessageLevel;
diff --git a/src/Core/ConnectionManager.h b/src/Core/ConnectionManager.h
index e9565f9..888255a 100644
--- a/src/Core/ConnectionManager.h
+++ b/src/Core/ConnectionManager.h
@@ -43,7 +43,7 @@ class Packet;
namespace Core {
-class ConnectionManager : public Common::Initializable, public Common::Configurable {
+class ConnectionManager : public Common::Configurable {
private:
static ConnectionManager connectionManager;
diff --git a/src/madc.cpp b/src/madc.cpp
index 8e1c4cd..f74f925 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -103,9 +103,10 @@ int main(int argc, char *argv[]) {
std::cerr << "Receiving host list..." << std::flush;
- Client::InformationManager::init(connection);
+ Client::InformationManager::getInformationManager()->init();
+ Client::InformationManager::getInformationManager()->updateDaemonList(connection);
- while(!Client::InformationManager::getInformationManager()->isInitialised())
+ while(Client::InformationManager::getInformationManager()->isUpdating())
Net::FdManager::getFdManager()->run();
std::cerr << " done." << std::endl << std::endl;