diff options
Diffstat (limited to 'src/Server/ConnectionManager.cpp')
-rw-r--r-- | src/Server/ConnectionManager.cpp | 81 |
1 files changed, 35 insertions, 46 deletions
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 <Core/ConfigEntry.h> #include <Core/ConfigManager.h> -#include <Core/Logger.h> +#include <Common/RequestManager.h> #include <Common/RequestHandlers/FSInfoRequestHandler.h> #include <Common/RequestHandlers/StatusRequestHandler.h> #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 <Net/Packet.h> @@ -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<Net::Connection> connection0) -: connection(connection0), type(UNKNOWN), hostInfo(0) { +ConnectionManager::ServerConnection::ServerConnection(Core::Application *application, boost::shared_ptr<Net::Connection> 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<boost::shared_ptr<ServerConnection> >::iterator con = connections.begin(); con != connections.end(); ++con) { if((*con)->getConnectionType() == ServerConnection::CLIENT) { - boost::shared_ptr<Requests::DaemonStateUpdateRequest> request(new Requests::DaemonStateUpdateRequest(hostInfo->getName(), state)); - Common::RequestManager::get()->sendRequest(con->get(), request); + boost::shared_ptr<Requests::DaemonStateUpdateRequest> 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<Net::Listener> listener(new Net::Listener(x509CertFile, x509KeyFile)); + boost::shared_ptr<Net::Listener> 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<boost::asio::ip::tcp::endpoint>::const_iterator address = listenerAddresses.begin(); address != listenerAddresses.end(); ++address) { try { - boost::shared_ptr<Net::Listener> listener(new Net::Listener(x509CertFile, x509KeyFile, *address)); + boost::shared_ptr<Net::Listener> 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<Net::Connection> con) { - boost::shared_ptr<ServerConnection> connection(new ServerConnection(con)); + boost::shared_ptr<ServerConnection> 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<ServerConnection> con) { @@ -177,44 +174,36 @@ void ConnectionManager::handleDisconnect(boost::shared_ptr<ServerConnection> 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<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI"); + application->getRequestManager()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); + application->getRequestManager()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("GetStatus"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>("AuthGSSAPI"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonCommandRequestHandler>("DaemonCommand"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonFSInfoRequestHandler>("DaemonFSInfo"); - Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::FSInfoRequestHandler>("FSInfo"); - Common::RequestManager::get()->registerPacketType<Common::RequestHandlers::StatusRequestHandler>("GetStatus"); - //Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonStatusRequestHandler>("GetDaemonStatus"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>("Identify"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::DaemonListRequestHandler>("ListHosts"); - Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>("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<Common::Connection> 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&) { |