From 7234fe326d16d6bf9f4374a09ddc6ef790e6723f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Jun 2009 22:03:02 +0200 Subject: Globale Variablen durch Application-Klasse ersetzt --- src/Server/ConnectionManager.cpp | 81 +++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 46 deletions(-) (limited to 'src/Server/ConnectionManager.cpp') diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index a15a516..bbf7ab1 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -18,16 +18,15 @@ */ #include "ConnectionManager.h" +#include "Application.h" #include #include -#include +#include #include #include #include "Requests/DaemonStateUpdateRequest.h" -#include "RequestHandlers/DaemonListRequestHandler.h" //#include "RequestHandlers/GSSAPIAuthRequestHandler.h" -#include "RequestHandlers/IdentifyRequestHandler.h" -#include "RequestHandlers/LogRequestHandler.h" +#include "RequestHandlers/ConnectionRequestHandlerGroup.h" #include "RequestHandlers/DaemonRequestHandlerGroup.h" #include "RequestHandlers/UserRequestHandlerGroup.h" #include @@ -39,14 +38,12 @@ namespace Mad { namespace Server { -ConnectionManager ConnectionManager::connectionManager; - bool ConnectionManager::ServerConnection::send(const Net::Packet &packet) { return connection->send(packet); } -ConnectionManager::ServerConnection::ServerConnection(boost::shared_ptr connection0) -: connection(connection0), type(UNKNOWN), hostInfo(0) { +ConnectionManager::ServerConnection::ServerConnection(Core::Application *application, boost::shared_ptr connection0) +: Common::Connection(application), connection(connection0), type(UNKNOWN), hostInfo(0) { connection->connectSignalReceive(boost::bind(&ServerConnection::receive, this, _1)); } @@ -80,8 +77,8 @@ void ConnectionManager::updateState(Common::HostInfo *hostInfo, Common::HostInfo for(std::set >::iterator con = connections.begin(); con != connections.end(); ++con) { if((*con)->getConnectionType() == ServerConnection::CLIENT) { - boost::shared_ptr request(new Requests::DaemonStateUpdateRequest(hostInfo->getName(), state)); - Common::RequestManager::get()->sendRequest(con->get(), request); + boost::shared_ptr request(new Requests::DaemonStateUpdateRequest(application, hostInfo->getName(), state)); + application->getRequestManager()->sendRequest(con->get(), request); } } } @@ -141,7 +138,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h void ConnectionManager::configFinished() { if(listenerAddresses.empty()) { try { - boost::shared_ptr listener(new Net::Listener(x509CertFile, x509KeyFile)); + boost::shared_ptr listener(new Net::Listener(application, x509CertFile, x509KeyFile)); listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); listeners.push_back(listener); } @@ -152,7 +149,7 @@ void ConnectionManager::configFinished() { else { for(std::vector::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { try { - boost::shared_ptr listener(new Net::Listener(x509CertFile, x509KeyFile, *address)); + boost::shared_ptr listener(new Net::Listener(application, x509CertFile, x509KeyFile, *address)); listener->connectSignalNewConnection(boost::bind(&ConnectionManager::handleNewConnection, this, _1)); listeners.push_back(listener); } @@ -164,11 +161,11 @@ void ConnectionManager::configFinished() { } void ConnectionManager::handleNewConnection(boost::shared_ptr con) { - boost::shared_ptr connection(new ServerConnection(con)); + boost::shared_ptr connection(new ServerConnection(application, con)); con->connectSignalDisconnected(boost::bind(&ConnectionManager::handleDisconnect, this, connection)); connections.insert(connection); - Common::RequestManager::get()->registerConnection(connection.get()); + application->getRequestManager()->registerConnection(connection.get()); } void ConnectionManager::handleDisconnect(boost::shared_ptr con) { @@ -177,44 +174,36 @@ void ConnectionManager::handleDisconnect(boost::shared_ptr con connections.erase(con); - Common::RequestManager::get()->unregisterConnection(con.get()); + application->getRequestManager()->unregisterConnection(con.get()); } -void ConnectionManager::doInit() { - Common::RequestManager::get()->setServer(true); - - daemonRequestHandlerGroup.reset(new RequestHandlers::DaemonRequestHandlerGroup); - userRequestHandlerGroup.reset(new RequestHandlers::UserRequestHandlerGroup); +ConnectionManager::ConnectionManager(Application *application0) : application(application0), +connectionRequestHandlerGroup(new RequestHandlers::ConnectionRequestHandlerGroup(application)), +daemonRequestHandlerGroup(new RequestHandlers::DaemonRequestHandlerGroup), +userRequestHandlerGroup(new RequestHandlers::UserRequestHandlerGroup(application)) { + //requestManager->registerPacketType("AuthGSSAPI"); + application->getRequestManager()->registerPacketType("FSInfo"); + application->getRequestManager()->registerPacketType("GetStatus"); - //Common::RequestManager::get()->registerPacketType("AuthGSSAPI"); - //Common::RequestManager::get()->registerPacketType("DaemonCommand"); - //Common::RequestManager::get()->registerPacketType("DaemonFSInfo"); - Common::RequestManager::get()->registerPacketType("FSInfo"); - Common::RequestManager::get()->registerPacketType("GetStatus"); - //Common::RequestManager::get()->registerPacketType("GetDaemonStatus"); - Common::RequestManager::get()->registerPacketType("Identify"); - Common::RequestManager::get()->registerPacketType("ListHosts"); - Common::RequestManager::get()->registerPacketType("Log"); + application->getRequestManager()->registerRequestHandlerGroup(connectionRequestHandlerGroup); + application->getRequestManager()->registerRequestHandlerGroup(daemonRequestHandlerGroup); + application->getRequestManager()->registerRequestHandlerGroup(userRequestHandlerGroup); - Common::RequestManager::get()->registerRequestHandlerGroup(daemonRequestHandlerGroup); - Common::RequestManager::get()->registerRequestHandlerGroup(userRequestHandlerGroup); + application->getConfigManager()->registerConfigurable(this); } -void ConnectionManager::doDeinit() { +ConnectionManager::~ConnectionManager() { + application->getConfigManager()->unregisterConfigurable(this); + connections.clear(); - Common::RequestManager::get()->unregisterRequestHandlerGroup(userRequestHandlerGroup); - Common::RequestManager::get()->unregisterRequestHandlerGroup(daemonRequestHandlerGroup); - - //Common::RequestManager::get()->unregisterPacketType("AuthGSSAPI"); - //Common::RequestManager::get()->unregisterPacketType("DaemonCommand"); - //Common::RequestManager::get()->unregisterPacketType("DaemonFSInfo"); - Common::RequestManager::get()->unregisterPacketType("FSInfo"); - Common::RequestManager::get()->unregisterPacketType("GetStatus"); - //Common::RequestManager::get()->unregisterPacketType("GetDaemonStatus"); - Common::RequestManager::get()->unregisterPacketType("Identify"); - Common::RequestManager::get()->unregisterPacketType("ListHosts"); - Common::RequestManager::get()->unregisterPacketType("Log"); + application->getRequestManager()->unregisterRequestHandlerGroup(userRequestHandlerGroup); + application->getRequestManager()->unregisterRequestHandlerGroup(daemonRequestHandlerGroup); + application->getRequestManager()->unregisterRequestHandlerGroup(connectionRequestHandlerGroup); + + //requestManager->unregisterPacketType("AuthGSSAPI"); + application->getRequestManager()->unregisterPacketType("FSInfo"); + application->getRequestManager()->unregisterPacketType("GetStatus"); } boost::shared_ptr ConnectionManager::getDaemonConnection(const std::string &name) const throw (Core::Exception&) { @@ -266,7 +255,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const if(hostInfo->getState() != Common::HostInfo::INACTIVE) { try { getDaemonConnection(name)->disconnect(); - Core::Logger::log(Core::Logger::WARNING, "Disconnecting old connection."); + application->log(Core::LoggerBase::WARNING, "Disconnecting old connection."); } catch(Core::Exception&) {} } @@ -274,7 +263,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const connection->identify(hostInfo); updateState(hostInfo, Common::HostInfo::RUNNING); - Core::Logger::logf("Identified as '%s'.", name.c_str()); + application->logf("Identified as '%s'.", name.c_str()); } void ConnectionManager::identifyClientConnection(Common::Connection *con) throw (Core::Exception&) { -- cgit v1.2.3