From de5fa3867791bf4bf84a52de8cd09821f9ce28ab Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 4 Mar 2009 23:14:34 +0100 Subject: XmlRequest{,Handler} in Request{,Handler} umbenannt --- src/Common/Makefile.am | 4 +- src/Common/Makefile.in | 4 +- src/Common/Request.h | 69 ++++++++++++++++++++++ src/Common/RequestHandler.h | 61 +++++++++++++++++++ .../RequestHandlers/DisconnectRequestHandler.h | 4 +- src/Common/RequestHandlers/FSInfoRequestHandler.h | 4 +- src/Common/RequestHandlers/StatusRequestHandler.h | 4 +- src/Common/RequestManager.cpp | 60 +++++++++---------- src/Common/RequestManager.h | 38 ++++++------ src/Common/Requests/DisconnectRequest.h | 6 +- src/Common/Requests/FSInfoRequest.h | 6 +- src/Common/Requests/GSSAPIAuthRequest.h | 6 +- src/Common/Requests/StatusRequest.h | 6 +- src/Common/Requests/UserListRequest.h | 6 +- src/Common/XmlRequest.h | 69 ---------------------- src/Common/XmlRequestHandler.h | 61 ------------------- 16 files changed, 204 insertions(+), 204 deletions(-) create mode 100644 src/Common/Request.h create mode 100644 src/Common/RequestHandler.h delete mode 100644 src/Common/XmlRequest.h delete mode 100644 src/Common/XmlRequestHandler.h (limited to 'src/Common') diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am index 79bc0b1..e1c22b9 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 RequestManager.h \ - SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h XmlRequest.h XmlRequestHandler.h + RemoteLogger.h Request.h RequestHandler.h RequestManager.h \ + SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in index 1f7bca5..d70edc7 100644 --- a/src/Common/Makefile.in +++ b/src/Common/Makefile.in @@ -245,8 +245,8 @@ 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 RequestManager.h \ - SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h XmlRequest.h XmlRequestHandler.h + RemoteLogger.h Request.h RequestHandler.h RequestManager.h \ + SystemBackend.h Tokenizer.h UserInfo.h XmlPacket.h all: all-recursive diff --git a/src/Common/Request.h b/src/Common/Request.h new file mode 100644 index 0000000..b0e6777 --- /dev/null +++ b/src/Common/Request.h @@ -0,0 +1,69 @@ +/* + * Request.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_COMMON_XMLREQUEST_H_ +#define MAD_COMMON_XMLREQUEST_H_ + +#include "XmlPacket.h" +#include "RequestHandler.h" +#include "Exception.h" + +#include +#include + +namespace Mad { +namespace Common { + +class Request : public RequestHandler { + private: + friend class RequestManager; + + sigc::signal finished; + + std::auto_ptr res; + Exception exp; + + public: + typedef sigc::slot 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 result) {res = result; finished(*this);} + void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished(*this);} + void finishWithError(const Exception &e) {exp = e; finished(*this);} + + virtual void sendRequest(Net::Connection *connection, uint16_t requestId) = 0; + + public: + const XmlPacket& getResult() const throw(Exception) { + if(res.get()) + return *res; + + throw exp; + } +}; + +} +} + +#endif /* MAD_COMMON_XMLREQUEST_H_ */ diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h new file mode 100644 index 0000000..b909e81 --- /dev/null +++ b/src/Common/RequestHandler.h @@ -0,0 +1,61 @@ +/* + * RequestHandler.h + * + * Copyright (C) 2008 Matthias Schiffer + * + * 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 . + */ + +#ifndef MAD_COMMON_XMLREQUESTHANDLER_H_ +#define MAD_COMMON_XMLREQUESTHANDLER_H_ + +#include +#include + +namespace Mad { + +namespace Net { +class Connection; +} + +namespace Common { + +class RequestManager; +class XmlPacket; + +class RequestHandler { + private: + sigc::signal finished; + + // Prevent shallow copy + RequestHandler(const RequestHandler &o); + RequestHandler& operator=(const RequestHandler &o); + + protected: + RequestHandler() {} + + sigc::signal signalFinished() {return finished;} + + virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) = 0; + + public: + virtual ~RequestHandler() {} + + friend class RequestManager; +}; + +} +} + +#endif /* MAD_COMMON_XMLREQUESTHANDLER_H_ */ diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h index 23d07dc..7544fd8 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.h +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h @@ -20,13 +20,13 @@ #ifndef MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_ #define MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_ -#include "../XmlRequestHandler.h" +#include "../RequestHandler.h" namespace Mad { namespace Common { namespace RequestHandlers { -class DisconnectRequestHandler : public XmlRequestHandler { +class DisconnectRequestHandler : public RequestHandler { protected: virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet); diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h index 32e7a08..a9ee120 100644 --- a/src/Common/RequestHandlers/FSInfoRequestHandler.h +++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h @@ -20,7 +20,7 @@ #ifndef MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_ #define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_ -#include "../XmlRequestHandler.h" +#include "../RequestHandler.h" #include "../SystemBackend.h" #include @@ -29,7 +29,7 @@ namespace Mad { namespace Common { namespace RequestHandlers { -class FSInfoRequestHandler : public XmlRequestHandler { +class FSInfoRequestHandler : public RequestHandler { private: Net::Connection *connection; uint16_t requestId; diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h index 0b53db0..ce7ae6d 100644 --- a/src/Common/RequestHandlers/StatusRequestHandler.h +++ b/src/Common/RequestHandlers/StatusRequestHandler.h @@ -20,14 +20,14 @@ #ifndef MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_ #define MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_ -#include "../XmlRequestHandler.h" +#include "../RequestHandler.h" #include namespace Mad { namespace Common { namespace RequestHandlers { -class StatusRequestHandler : public XmlRequestHandler { +class StatusRequestHandler : public RequestHandler { private: Net::Connection *connection; uint16_t rid; diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index de4f2ca..ac1909b 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -18,7 +18,7 @@ */ #include "RequestManager.h" -#include "XmlRequest.h" +#include "Request.h" #include "XmlPacket.h" #include "RequestHandlers/DisconnectRequestHandler.h" #include "Logger.h" @@ -32,21 +32,21 @@ namespace Common { RequestManager RequestManager::requestManager; -RequestManager::XmlRequestMap::~XmlRequestMap() { +RequestManager::RequestMap::~RequestMap() { for(iterator it = begin(); it != end(); ++it) delete it->second; } -bool RequestManager::XmlRequestMap::addRequest(uint16_t id, XmlRequestHandler *info) { +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::XmlRequestMap::deleteRequest), id))); + info->signalFinished().connect(sigc::hide_return(sigc::bind(sigc::mem_fun(this, &RequestManager::RequestMap::deleteRequest), id))); return true; } -XmlRequestHandler* RequestManager::XmlRequestMap::findRequest(uint16_t id) { +RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) { iterator it = find(id); if(it == end()) return 0; @@ -54,7 +54,7 @@ XmlRequestHandler* RequestManager::XmlRequestMap::findRequest(uint16_t id) { return it->second; } -bool RequestManager::XmlRequestMap::deleteRequest(uint16_t id) { +bool RequestManager::RequestMap::deleteRequest(uint16_t id) { iterator it = find(id); if(it == end()) return false; @@ -69,27 +69,27 @@ bool RequestManager::XmlRequestMap::deleteRequest(uint16_t id) { void RequestManager::receiveHandler(Net::Connection *connection, const Net::Packet &packet) { XmlPacket xmlPacket(packet); - std::map::iterator it = xmlRequestMaps.find(connection); - if(it == xmlRequestMaps.end()) { + std::map::iterator it = requestMaps.find(connection); + if(it == requestMaps.end()) { // TODO: Error Logger::log(Logger::ERROR, "Received a packet from an unregistered connection."); return; } - XmlRequestMap *xmlRequestMap = it->second; - XmlRequestHandler *xmlRequest = xmlRequestMap->findRequest(packet.getRequestId()); + RequestMap *requestMap = it->second; + RequestHandler *request = requestMap->findRequest(packet.getRequestId()); - if(xmlRequest) { - xmlRequest->handlePacket(connection, packet.getRequestId(), xmlPacket); + if(request) { + request->handlePacket(connection, packet.getRequestId(), xmlPacket); return; } - std::map::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); + std::map::iterator factoryIt = requestHandlerFactories.find(xmlPacket.getType()); + if(factoryIt != requestHandlerFactories.end()) { + request = factoryIt->second->createRequestHandler(); + requestMap->addRequest(packet.getRequestId(), request); + request->handlePacket(connection, packet.getRequestId(), xmlPacket); return; } @@ -103,15 +103,15 @@ void RequestManager::receiveHandler(Net::Connection *connection, const Net::Pack connection->send(ret.encode(requestId)); } -bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr request) { - std::map::iterator it = xmlRequestMaps.find(connection); +bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptr request) { + std::map::iterator it = requestMaps.find(connection); - if(it == xmlRequestMaps.end()) { + if(it == requestMaps.end()) { Logger::log(Logger::CRITICAL, "Trying to send a request over an unregistered connecion."); return false; } - XmlRequestMap *requestMap = it->second; + RequestMap *requestMap = it->second; uint16_t id; do { @@ -126,29 +126,29 @@ bool RequestManager::sendRequest(Net::Connection *connection, std::auto_ptrsignalReceive().connect(sigc::mem_fun(this, &RequestManager::receiveHandler)); } void RequestManager::unregisterConnection(Net::Connection *connection) { - std::map::iterator it = xmlRequestMaps.find(connection); + std::map::iterator it = requestMaps.find(connection); - if(it != xmlRequestMaps.end()) { + if(it != requestMaps.end()) { delete it->second; - xmlRequestMaps.erase(it); + requestMaps.erase(it); } } void RequestManager::unregisterPacketType(const std::string &type) { - std::map::iterator it = xmlRequestHandlerFactories.find(type); + std::map::iterator it = requestHandlerFactories.find(type); - if(it == xmlRequestHandlerFactories.end()) + if(it == requestHandlerFactories.end()) return; delete it->second; - xmlRequestHandlerFactories.erase(it); + requestHandlerFactories.erase(it); } RequestManager::RequestManager() : core(false), requestId(-1) { @@ -158,10 +158,10 @@ RequestManager::RequestManager() : core(false), requestId(-1) { RequestManager::~RequestManager() { unregisterPacketType("Disconnect"); - for(std::map::iterator it = xmlRequestMaps.begin(); it != xmlRequestMaps.end(); ++it) + for(std::map::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it) delete it->second; - for(std::map::iterator it = xmlRequestHandlerFactories.begin(); it != xmlRequestHandlerFactories.end(); ++it) + for(std::map::iterator it = requestHandlerFactories.begin(); it != requestHandlerFactories.end(); ++it) delete it->second; } diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index 8a3d151..ee4f4d1 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -28,49 +28,49 @@ namespace Mad { namespace Common { -class XmlRequest; -class XmlRequestHandler; +class Request; +class RequestHandler; class RequestManager { private: - class XmlRequestMap : private std::map { + class RequestMap : private std::map { private: // Prevent shallow copy - XmlRequestMap(const XmlRequestMap &o); - XmlRequestMap& operator=(const XmlRequestMap &o); + RequestMap(const RequestMap &o); + RequestMap& operator=(const RequestMap &o); public: - XmlRequestMap() {} - ~XmlRequestMap(); + RequestMap() {} + ~RequestMap(); - bool addRequest(uint16_t id, XmlRequestHandler *info); - XmlRequestHandler* findRequest(uint16_t id); + bool addRequest(uint16_t id, RequestHandler *info); + RequestHandler* findRequest(uint16_t id); bool deleteRequest(uint16_t id); }; - class XmlRequestHandlerFactory { + class RequestHandlerFactory { protected: - XmlRequestHandlerFactory() {} + RequestHandlerFactory() {} public: - virtual XmlRequestHandler* createRequestHandler() = 0; - virtual ~XmlRequestHandlerFactory() {} + virtual RequestHandler* createRequestHandler() = 0; + virtual ~RequestHandlerFactory() {} }; - template class SpecificXmlRequestHandlerFactory : public XmlRequestHandlerFactory { + template class SpecificRequestHandlerFactory : public RequestHandlerFactory { public: - virtual XmlRequestHandler* createRequestHandler() { + virtual RequestHandler* createRequestHandler() { return new T(); } }; static RequestManager requestManager; - std::map xmlRequestMaps; + std::map requestMaps; bool core; uint16_t requestId; - std::map xmlRequestHandlerFactories; + std::map requestHandlerFactories; uint16_t getRequestId() { return requestId+=2; @@ -103,12 +103,12 @@ class RequestManager { void unregisterConnection(Net::Connection *connection); template void registerPacketType(const std::string &type) { - xmlRequestHandlerFactories.insert(std::make_pair(type, new SpecificXmlRequestHandlerFactory())); + requestHandlerFactories.insert(std::make_pair(type, new SpecificRequestHandlerFactory())); } void unregisterPacketType(const std::string &type); - bool sendRequest(Net::Connection *connection, std::auto_ptr request); + bool sendRequest(Net::Connection *connection, std::auto_ptr request); virtual ~RequestManager(); }; diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index 4f2cdf5..af7cca5 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -20,19 +20,19 @@ #ifndef MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_ #define MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_ -#include "../XmlRequest.h" +#include "../Request.h" namespace Mad { namespace Common { namespace Requests { -class DisconnectRequest : public XmlRequest { +class DisconnectRequest : public Request { protected: virtual void sendRequest(Net::Connection *connection, uint16_t requestId); virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet); public: - DisconnectRequest(slot_type slot) : XmlRequest(slot) {} + DisconnectRequest(slot_type slot) : Request(slot) {} }; } diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h index 9a6ba14..39759ab 100644 --- a/src/Common/Requests/FSInfoRequest.h +++ b/src/Common/Requests/FSInfoRequest.h @@ -20,19 +20,19 @@ #ifndef MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ #define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_ -#include "../XmlRequest.h" +#include "../Request.h" namespace Mad { namespace Common { namespace Requests { -class FSInfoRequest : public XmlRequest { +class FSInfoRequest : public Request { protected: virtual void sendRequest(Net::Connection *connection, uint16_t requestId); virtual void handlePacket(Net::Connection*, uint16_t, const Common::XmlPacket &packet); public: - FSInfoRequest(slot_type slot) : XmlRequest(slot) {} + FSInfoRequest(slot_type slot) : Request(slot) {} }; } diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h index d9f5c9c..ca6195b 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.h +++ b/src/Common/Requests/GSSAPIAuthRequest.h @@ -20,7 +20,7 @@ #ifndef MAD_COMMON_REQUESTS_GSSAPIAUTHREQUEST_H_ #define MAD_COMMON_REQUESTS_GSSAPIAUTHREQUEST_H_ -#include "../XmlRequest.h" +#include "../Request.h" #include #include @@ -30,7 +30,7 @@ namespace Requests { // TODO Logging & error handling! -class GSSAPIAuthRequest : public XmlRequest { +class GSSAPIAuthRequest : public Request { private: std::string serviceName; gss_name_t gssServiceName; @@ -43,7 +43,7 @@ class GSSAPIAuthRequest : public XmlRequest { public: GSSAPIAuthRequest(const std::string &serviceName0, slot_type slot) - : XmlRequest(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {} + : Request(slot), serviceName(serviceName0), gssServiceName(GSS_C_NO_NAME), gssContext(GSS_C_NO_CONTEXT), gssContinue(true) {} virtual ~GSSAPIAuthRequest(); }; diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h index e9c8a4c..eb24305 100644 --- a/src/Common/Requests/StatusRequest.h +++ b/src/Common/Requests/StatusRequest.h @@ -20,19 +20,19 @@ #ifndef MAD_COMMON_REQUESTS_STATUSREQUEST_H_ #define MAD_COMMON_REQUESTS_STATUSREQUEST_H_ -#include "../XmlRequest.h" +#include "../Request.h" namespace Mad { namespace Common { namespace Requests { -class StatusRequest : public XmlRequest { +class StatusRequest : public Request { protected: virtual void sendRequest(Net::Connection *connection, uint16_t requestId); virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet); public: - StatusRequest(slot_type slot) : XmlRequest(slot) {} + StatusRequest(slot_type slot) : Request(slot) {} }; } diff --git a/src/Common/Requests/UserListRequest.h b/src/Common/Requests/UserListRequest.h index 9702a42..bcd9578 100644 --- a/src/Common/Requests/UserListRequest.h +++ b/src/Common/Requests/UserListRequest.h @@ -20,19 +20,19 @@ #ifndef MAD_COMMON_REQUESTS_USERLISTREQUEST_H_ #define MAD_COMMON_REQUESTS_USERLISTREQUEST_H_ -#include "../XmlRequest.h" +#include "../Request.h" namespace Mad { namespace Common { namespace Requests { -class UserListRequest : public XmlRequest { +class UserListRequest : public Request { protected: virtual void sendRequest(Net::Connection *connection, uint16_t requestId); virtual void handlePacket(Net::Connection *connection, uint16_t, const XmlPacket &packet); public: - UserListRequest(slot_type slot) : XmlRequest(slot) {} + UserListRequest(slot_type slot) : Request(slot) {} }; } diff --git a/src/Common/XmlRequest.h b/src/Common/XmlRequest.h deleted file mode 100644 index 66635c2..0000000 --- a/src/Common/XmlRequest.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Request.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_XMLREQUEST_H_ -#define MAD_COMMON_XMLREQUEST_H_ - -#include "XmlPacket.h" -#include "XmlRequestHandler.h" -#include "Exception.h" - -#include -#include - -namespace Mad { -namespace Common { - -class XmlRequest : public XmlRequestHandler { - private: - friend class RequestManager; - - sigc::signal finished; - - std::auto_ptr res; - Exception exp; - - public: - typedef sigc::slot slot_type; - - protected: - XmlRequest(slot_type slot) : exp(Exception::NOT_FINISHED) { - finished.connect(slot); - finished.connect(sigc::hide(signalFinished().make_slot())); - } - - void finish(std::auto_ptr result) {res = result; finished(*this);} - void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished(*this);} - void finishWithError(const Exception &e) {exp = e; finished(*this);} - - virtual void sendRequest(Net::Connection *connection, uint16_t requestId) = 0; - - public: - const XmlPacket& getResult() const throw(Exception) { - if(res.get()) - return *res; - - throw exp; - } -}; - -} -} - -#endif /* MAD_COMMON_XMLREQUEST_H_ */ diff --git a/src/Common/XmlRequestHandler.h b/src/Common/XmlRequestHandler.h deleted file mode 100644 index 30438b7..0000000 --- a/src/Common/XmlRequestHandler.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * RequestHandler.h - * - * Copyright (C) 2008 Matthias Schiffer - * - * 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 . - */ - -#ifndef MAD_COMMON_XMLREQUESTHANDLER_H_ -#define MAD_COMMON_XMLREQUESTHANDLER_H_ - -#include -#include - -namespace Mad { - -namespace Net { -class Connection; -} - -namespace Common { - -class RequestManager; -class XmlPacket; - -class XmlRequestHandler { - private: - sigc::signal finished; - - // Prevent shallow copy - XmlRequestHandler(const XmlRequestHandler &o); - XmlRequestHandler& operator=(const XmlRequestHandler &o); - - protected: - XmlRequestHandler() {} - - sigc::signal signalFinished() {return finished;} - - virtual void handlePacket(Net::Connection *connection, uint16_t requestId, const XmlPacket &packet) = 0; - - public: - virtual ~XmlRequestHandler() {} - - friend class RequestManager; -}; - -} -} - -#endif /* MAD_COMMON_XMLREQUESTHANDLER_H_ */ -- cgit v1.2.3