summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-03-04 22:53:02 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-03-04 22:53:02 +0100
commitc316a3115bf790fb623f0765dd6b04f781af5b51 (patch)
treeb757067dcd2495bf8aa5d3ca6f42886eb55c93fa /src/Common
parentd88e4d0da7ff801b0c58b5043ade0743547cfb90 (diff)
downloadmad-c316a3115bf790fb623f0765dd6b04f781af5b51.tar
mad-c316a3115bf790fb623f0765dd6b04f781af5b51.zip
Alte Request-Klassen entfernt
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/Makefile.am2
-rw-r--r--src/Common/Makefile.in2
-rw-r--r--src/Common/Request.h92
-rw-r--r--src/Common/RequestBase.h39
-rw-r--r--src/Common/RequestHandler.h60
-rw-r--r--src/Common/RequestManager.cpp137
-rw-r--r--src/Common/RequestManager.h42
-rw-r--r--src/Common/XmlPacket.cpp2
8 files changed, 15 insertions, 361 deletions
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index 5d4fb09..79bc0b1 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -8,5 +8,5 @@ libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandler
noinst_HEADERS = ActionManager.h 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 \
+ RemoteLogger.h RequestManager.h \
SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h XmlRequest.h XmlRequestHandler.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 948343c..1f7bca5 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -245,7 +245,7 @@ libcommon_la_SOURCES = ActionManager.cpp ConfigEntry.cpp ConfigManager.cpp Excep
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
noinst_HEADERS = ActionManager.h 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 \
+ RemoteLogger.h RequestManager.h \
SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h XmlRequest.h XmlRequestHandler.h
all: all-recursive
diff --git a/src/Common/Request.h b/src/Common/Request.h
deleted file mode 100644
index 2317d5a..0000000
--- a/src/Common/Request.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Request.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_REQUEST_H_
-#define MAD_COMMON_REQUEST_H_
-
-#include "RequestBase.h"
-#include "Exception.h"
-
-#include <memory>
-#include <sigc++/adaptors/hide.h>
-
-namespace Mad {
-namespace Common {
-
-template<typename T = void> class Request : public RequestBase {
- private:
- sigc::signal<void,const Request<T>&> finished;
-
- std::auto_ptr<T> res;
- Exception exp;
-
- public:
- typedef sigc::slot<void,const Request<T>&> slot_type;
-
- protected:
- Request(slot_type slot) : exp(Exception::NOT_FINISHED) {
- finished.connect(slot);
- finished.connect(sigc::hide(signalFinished().make_slot()));
- }
-
- void finish(std::auto_ptr<T> result) {res = result; finished(*this);}
- void finish(const T& result) {res.reset(new T(result)); finished(*this);}
- void finishWithError(const Exception &e) {exp = e; finished(*this);}
-
- public:
- const T& getResult() const throw(Exception) {
- if(res.get())
- return *res;
-
- throw exp;
- }
-};
-
-template<> class Request<void> : public RequestBase {
- private:
- sigc::signal<void,const Request<void>&> finished;
-
- bool isFinished;
- Exception exp;
-
- public:
- typedef sigc::slot<void,const Request<void>&> slot_type;
-
- protected:
- Request(slot_type slot) : isFinished(false), exp(Exception::NOT_FINISHED) {
- finished.connect(slot);
- finished.connect(sigc::hide(signalFinished().make_slot()));
- }
-
- void finish() {isFinished = true; finished(*this);}
- void finishWithError(const Exception &e) {exp = e; finished(*this);}
-
- public:
- void getResult() const throw(Exception) {
- if(isFinished)
- return;
-
- throw exp;
- }
-};
-
-}
-}
-
-#endif /* MAD_COMMON_REQUEST_H_ */
diff --git a/src/Common/RequestBase.h b/src/Common/RequestBase.h
deleted file mode 100644
index 535f6d0..0000000
--- a/src/Common/RequestBase.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * RequestBase.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_REQUESTBASE_H_
-#define MAD_COMMON_REQUESTBASE_H_
-
-#include "RequestHandler.h"
-#include <stdint.h>
-
-namespace Mad {
-namespace Common {
-
-class RequestBase : public RequestHandler {
- protected:
- virtual void sendRequest(Net::Connection *connection, uint16_t requestId) = 0;
-
- friend class RequestManager;
-};
-
-}
-}
-
-#endif /* MAD_COMMON_REQUESTBASE_H_ */
diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h
deleted file mode 100644
index 434f969..0000000
--- a/src/Common/RequestHandler.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * RequestHandler.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_REQUESTHANDLER_H_
-#define MAD_COMMON_REQUESTHANDLER_H_
-
-#include <sigc++/signal.h>
-
-namespace Mad {
-
-namespace Net {
-class Connection;
-class Packet;
-}
-
-namespace Common {
-
-class RequestManager;
-
-class RequestHandler {
- private:
- sigc::signal<void> finished;
-
- // Prevent shallow copy
- RequestHandler(const RequestHandler &o);
- RequestHandler& operator=(const RequestHandler &o);
-
- protected:
- RequestHandler() {}
-
- sigc::signal<void> signalFinished() {return finished;}
-
- virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet) = 0;
-
- public:
- virtual ~RequestHandler() {}
-
- friend class RequestManager;
-};
-
-}
-}
-
-#endif /* MAD_COMMON_REQUESTHANDLER_H_ */
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index b5acc5c..de4f2ca 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -18,7 +18,6 @@
*/
#include "RequestManager.h"
-#include "Request.h"
#include "XmlRequest.h"
#include "XmlPacket.h"
#include "RequestHandlers/DisconnectRequestHandler.h"
@@ -33,40 +32,6 @@ namespace Common {
RequestManager RequestManager::requestManager;
-RequestManager::RequestMap::~RequestMap() {
- for(iterator it = begin(); it != end(); ++it)
- delete it->second;
-}
-
-bool RequestManager::RequestMap::addRequest(uint16_t id, RequestHandler *info) {
- if(!insert(std::make_pair(id, info)).second)
- return false;
-
- info->signalFinished().connect(sigc::hide_return(sigc::bind(sigc::mem_fun(this, &RequestManager::RequestMap::deleteRequest), id)));
-
- return true;
-}
-
-RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) {
- iterator it = find(id);
- if(it == end())
- return 0;
-
- return it->second;
-}
-
-bool RequestManager::RequestMap::deleteRequest(uint16_t id) {
- iterator it = find(id);
- if(it == end())
- return false;
-
- delete it->second;
-
- erase(it);
- return true;
-}
-
-
RequestManager::XmlRequestMap::~XmlRequestMap() {
for(iterator it = begin(); it != end(); ++it)
delete it->second;
@@ -102,60 +67,29 @@ bool RequestManager::XmlRequestMap::deleteRequest(uint16_t id) {
void RequestManager::receiveHandler(Net::Connection *connection, const Net::Packet &packet) {
- std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
-
- if(it == requestMaps.end()) {
- // TODO: Error
- Logger::log(Logger::ERROR, "Received a packet from an unregistered connection.");
-
- return;
- }
-
- RequestMap *requestMap = it->second;
- RequestHandler *request = requestMap->findRequest(packet.getRequestId());
+ XmlPacket xmlPacket(packet);
- if(request) {
- request->handlePacket(connection, packet);
-
- return;
- }
-
- std::map<Net::Connection*,XmlRequestMap*>::iterator it2 = xmlRequestMaps.find(connection);
- if(it2 == xmlRequestMaps.end()) {
+ std::map<Net::Connection*,XmlRequestMap*>::iterator it = xmlRequestMaps.find(connection);
+ if(it == xmlRequestMaps.end()) {
// TODO: Error
Logger::log(Logger::ERROR, "Received a packet from an unregistered connection.");
return;
}
- XmlRequestMap *xmlRequestMap = it2->second;
+ XmlRequestMap *xmlRequestMap = it->second;
XmlRequestHandler *xmlRequest = xmlRequestMap->findRequest(packet.getRequestId());
if(xmlRequest) {
- XmlPacket xmlPacket(packet);
xmlRequest->handlePacket(connection, packet.getRequestId(), xmlPacket);
-
return;
}
- if(packet.getType() == Net::Packet::XML) {
- XmlPacket xmlPacket(packet);
-
- std::map<std::string,XmlRequestHandlerFactory*>::iterator factoryIt = xmlRequestHandlerFactories.find(xmlPacket.getType());
- if(factoryIt != xmlRequestHandlerFactories.end()) {
- xmlRequest = factoryIt->second->createRequestHandler();
- xmlRequestMap->addRequest(packet.getRequestId(), xmlRequest);
- xmlRequest->handlePacket(connection, packet.getRequestId(), xmlPacket);
-
- return;
- }
- }
-
- std::map<Net::Packet::Type,RequestHandlerFactory*>::iterator factoryIt = requestHandlerFactories.find(packet.getType());
- if(factoryIt != requestHandlerFactories.end()) {
- request = factoryIt->second->createRequestHandler();
- requestMap->addRequest(packet.getRequestId(), request);
- request->handlePacket(connection, packet);
+ std::map<std::string,XmlRequestHandlerFactory*>::iterator factoryIt = xmlRequestHandlerFactories.find(xmlPacket.getType());
+ if(factoryIt != xmlRequestHandlerFactories.end()) {
+ xmlRequest = factoryIt->second->createRequestHandler();
+ xmlRequestMap->addRequest(packet.getRequestId(), xmlRequest);
+ xmlRequest->handlePacket(connection, packet.getRequestId(), xmlPacket);
return;
}
@@ -169,28 +103,6 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack
connection->send(ret.encode(requestId));
}
-bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<RequestBase> request) {
- std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
-
- if(it == requestMaps.end()) {
- Logger::log(Logger::CRITICAL, "Trying to send a request over an unregistered connecion.");
- return false;
- }
-
- RequestMap *requestMap = it->second;
-
- uint16_t id;
- do {
- id = getRequestId();
- } while(requestMap->findRequest(id));
-
- request->sendRequest(connection, id);
-
- requestMap->addRequest(id, request.release());
-
- return true;
-}
-
bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<XmlRequest> request) {
std::map<Net::Connection*,XmlRequestMap*>::iterator it = xmlRequestMaps.find(connection);
@@ -214,37 +126,18 @@ bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr<XmlR
}
void RequestManager::registerConnection(Net::Connection *connection) {
- requestMaps.insert(std::make_pair(connection, new RequestMap()));
xmlRequestMaps.insert(std::make_pair(connection, new XmlRequestMap()));
connection->signalReceive().connect(sigc::mem_fun(this, &RequestManager::receiveHandler));
}
void RequestManager::unregisterConnection(Net::Connection *connection) {
- std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
+ std::map<Net::Connection*,XmlRequestMap*>::iterator it = xmlRequestMaps.find(connection);
- if(it != requestMaps.end()) {
+ if(it != xmlRequestMaps.end()) {
delete it->second;
- requestMaps.erase(it);
+ xmlRequestMaps.erase(it);
}
-
- std::map<Net::Connection*,XmlRequestMap*>::iterator it2 = xmlRequestMaps.find(connection);
-
- if(it2 != xmlRequestMaps.end()) {
- delete it2->second;
- xmlRequestMaps.erase(it2);
- }
-}
-
-void RequestManager::unregisterPacketType(Net::Packet::Type type) {
- std::map<Net::Packet::Type,RequestHandlerFactory*>::iterator it = requestHandlerFactories.find(type);
-
- if(it == requestHandlerFactories.end())
- return;
-
- delete it->second;
-
- requestHandlerFactories.erase(it);
}
void RequestManager::unregisterPacketType(const std::string &type) {
@@ -265,15 +158,9 @@ RequestManager::RequestManager() : core(false), requestId(-1) {
RequestManager::~RequestManager() {
unregisterPacketType("Disconnect");
- for(std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it)
- delete it->second;
-
for(std::map<Net::Connection*,XmlRequestMap*>::iterator it = xmlRequestMaps.begin(); it != xmlRequestMaps.end(); ++it)
delete it->second;
- for(std::map<Net::Packet::Type,RequestHandlerFactory*>::iterator it = requestHandlerFactories.begin(); it != requestHandlerFactories.end(); ++it)
- delete it->second;
-
for(std::map<std::string,XmlRequestHandlerFactory*>::iterator it = xmlRequestHandlerFactories.begin(); it != xmlRequestHandlerFactories.end(); ++it)
delete it->second;
}
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index f4ad208..8a3d151 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -28,28 +28,11 @@
namespace Mad {
namespace Common {
-class RequestBase;
-class RequestHandler;
class XmlRequest;
class XmlRequestHandler;
class RequestManager {
private:
- class RequestMap : private std::map<uint16_t,RequestHandler*> {
- private:
- // Prevent shallow copy
- RequestMap(const RequestMap &o);
- RequestMap& operator=(const RequestMap &o);
-
- public:
- RequestMap() {}
- ~RequestMap();
-
- bool addRequest(uint16_t id, RequestHandler *info);
- RequestHandler* findRequest(uint16_t id);
- bool deleteRequest(uint16_t id);
- };
-
class XmlRequestMap : private std::map<uint16_t,XmlRequestHandler*> {
private:
// Prevent shallow copy
@@ -65,22 +48,6 @@ class RequestManager {
bool deleteRequest(uint16_t id);
};
- class RequestHandlerFactory {
- protected:
- RequestHandlerFactory() {}
-
- public:
- virtual RequestHandler* createRequestHandler() = 0;
- virtual ~RequestHandlerFactory() {}
- };
-
- template<class T> class SpecificRequestHandlerFactory : public RequestHandlerFactory {
- public:
- virtual RequestHandler* createRequestHandler() {
- return new T();
- }
- };
-
class XmlRequestHandlerFactory {
protected:
XmlRequestHandlerFactory() {}
@@ -99,12 +66,10 @@ class RequestManager {
static RequestManager requestManager;
- std::map<Net::Connection*,RequestMap*> requestMaps;
std::map<Net::Connection*,XmlRequestMap*> xmlRequestMaps;
bool core;
uint16_t requestId;
- std::map<Net::Packet::Type,RequestHandlerFactory*> requestHandlerFactories;
std::map<std::string,XmlRequestHandlerFactory*> xmlRequestHandlerFactories;
uint16_t getRequestId() {
@@ -137,19 +102,12 @@ class RequestManager {
void registerConnection(Net::Connection *connection);
void unregisterConnection(Net::Connection *connection);
- template <class T> void registerPacketType(Net::Packet::Type type) {
- requestHandlerFactories.insert(std::make_pair(type, new SpecificRequestHandlerFactory<T>()));
- }
-
- void unregisterPacketType(Net::Packet::Type type);
-
template <class T> void registerPacketType(const std::string &type) {
xmlRequestHandlerFactories.insert(std::make_pair(type, new SpecificXmlRequestHandlerFactory<T>()));
}
void unregisterPacketType(const std::string &type);
- bool sendRequest(Net::Connection *connection, std::auto_ptr<RequestBase> request);
bool sendRequest(Net::Connection *connection, std::auto_ptr<XmlRequest> request);
virtual ~RequestManager();
diff --git a/src/Common/XmlPacket.cpp b/src/Common/XmlPacket.cpp
index 87045a8..73dd87d 100644
--- a/src/Common/XmlPacket.cpp
+++ b/src/Common/XmlPacket.cpp
@@ -294,7 +294,7 @@ Net::Packet XmlPacket::encode(uint16_t requestId) const {
xmlDocDumpMemory(doc, &buf, &length);
- Net::Packet packet(Net::Packet::XML, requestId, buf, length);
+ Net::Packet packet(requestId, buf, length);
xmlFree(buf);