diff options
Diffstat (limited to 'src/Common/RequestManager.cpp')
-rw-r--r-- | src/Common/RequestManager.cpp | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index a8b817f..c8b27a2 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -19,16 +19,12 @@ #include "RequestManager.h" #include "RequestHandlers/DisconnectRequestHandler.h" -#include <Core/Logger.h> #include <boost/bind.hpp> namespace Mad { namespace Common { -RequestManager RequestManager::requestManager; - - void RequestManager::RequestMap::unregisterConnection(Connection *connection) { std::map<Connection*, IdMap>::iterator idMap = connectionMap.find(connection); if(idMap == connectionMap.end()) @@ -96,21 +92,21 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co boost::shared_ptr<RequestHandler> request = requestMap.findRequest(connection, requestId); if(request) { lock.unlock(); - Core::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); + application->getThreadManager()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); return; } if(!requestMap.isConnectionRegistered(connection)) { // TODO: Error - Core::Logger::log(Core::Logger::ERROR, "Received a packet from an unregistered connection."); + application->log(Core::LoggerBase::ERROR, "Received a packet from an unregistered connection."); return; } std::map<std::string, boost::shared_ptr<RequestHandlerGroup> >::iterator rgh = requestHandlerGroups.find(packet->getType()); if(rgh != requestHandlerGroups.end()) { - request = rgh->second->createRequestHandler(packet->getType()); + request = rgh->second->createRequestHandler(application, packet->getType()); if(request) { { @@ -122,7 +118,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co } lock.unlock(); - Core::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); + application->getThreadManager()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet)); return; } @@ -130,7 +126,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co lock.unlock(); - Core::Logger::logf(Core::Logger::ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str()); + application->logf(Core::LoggerBase::ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str()); XmlPacket ret; ret.setType("Error"); @@ -143,20 +139,20 @@ bool RequestManager::sendRequest(Connection *connection, boost::shared_ptr<Reque boost::unique_lock<boost::shared_mutex> lock(mutex); if(!requestMap.isConnectionRegistered(connection)) { - Core::Logger::log(Core::Logger::CRITICAL, "Trying to send a request over an unregistered connecion."); + application->log(Core::LoggerBase::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)) { - Core::Logger::log(Core::Logger::CRITICAL, "Trying resend a request."); + application->log(Core::LoggerBase::CRITICAL, "Trying resend a request."); return false; } request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId)); lock.unlock(); - Core::ThreadManager::get()->pushWork(boost::bind(&Request::sendRequest, request)); + application->getThreadManager()->pushWork(boost::bind(&Request::sendRequest, request)); return true; } @@ -176,7 +172,7 @@ void RequestManager::registerConnection(Connection *connection) { connection->connectSignalReceive(boost::bind(&RequestManager::receiveHandler, this, connection, _1, _2)); } -RequestManager::RequestManager() : server(false), lastRequestId(-1) { +RequestManager::RequestManager(Application *application0, bool server) : application(application0), lastRequestId(server ? 0 : -1) { registerPacketType<RequestHandlers::DisconnectRequestHandler>("Disconnect"); } |