diff options
Diffstat (limited to 'src/Core')
-rw-r--r-- | src/Core/RequestHandlers/DaemonListRequestHandler.h | 5 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp | 12 | ||||
-rw-r--r-- | src/Core/RequestHandlers/DaemonStatusRequestHandler.h | 8 | ||||
-rw-r--r-- | src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h | 5 | ||||
-rw-r--r-- | src/Core/RequestHandlers/IdentifyRequestHandler.h | 5 | ||||
-rw-r--r-- | src/Core/Requests/DaemonStatusRequest.cpp | 25 | ||||
-rw-r--r-- | src/Core/Requests/DaemonStatusRequest.h | 17 |
7 files changed, 32 insertions, 45 deletions
diff --git a/src/Core/RequestHandlers/DaemonListRequestHandler.h b/src/Core/RequestHandlers/DaemonListRequestHandler.h index 1aabe5b..205ad02 100644 --- a/src/Core/RequestHandlers/DaemonListRequestHandler.h +++ b/src/Core/RequestHandlers/DaemonListRequestHandler.h @@ -27,10 +27,11 @@ namespace Core { namespace RequestHandlers { class DaemonListRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + public: DaemonListRequestHandler() {} - - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp index bb5d45f..efdf3ea 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.cpp @@ -48,15 +48,21 @@ void DaemonStatusRequestHandler::handlePacket(Net::Connection *connection, const try { Net::Connection *daemonCon = ConnectionManager::getConnectionManager()->getDaemonConnection(daemonName); - Requests::DaemonStatusRequest::send(daemonCon, sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)); + Common::RequestManager::getRequestManager()->sendRequest(daemonCon, std::auto_ptr<Common::RequestBase>(new Requests::DaemonStatusRequest(sigc::mem_fun(this, &DaemonStatusRequestHandler::requestFinished)))); } catch(Common::Exception &e) { connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), e)); } } -void DaemonStatusRequestHandler::requestFinished(const Net::Packets::HostStatusPacket &packet) { - con->send(Net::Packet(Net::Packet::OK, requestId, packet.getData(), packet.getLength())); +void DaemonStatusRequestHandler::requestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request) { + try { + const Net::Packet &packet = request.getResult(); + con->send(Net::Packet(Net::Packet::OK, requestId, packet.getData(), packet.getLength())); + } + catch(Common::Exception &e) { + con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, requestId, e)); + } signalFinished().emit(); } diff --git a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h index 916a3ec..d8edc41 100644 --- a/src/Core/RequestHandlers/DaemonStatusRequestHandler.h +++ b/src/Core/RequestHandlers/DaemonStatusRequestHandler.h @@ -21,6 +21,7 @@ #define MAD_CORE_REQUESTHANDLERS_DAEMONSTATUSREQUESTHANDLER_H_ #include <Common/RequestHandler.h> +#include <Common/Request.h> #include <stdint.h> namespace Mad { @@ -42,12 +43,13 @@ class DaemonStatusRequestHandler : public Common::RequestHandler { Net::Connection *con; uint16_t requestId; - void requestFinished(const Net::Packets::HostStatusPacket &packet); + void requestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request); + + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); public: DaemonStatusRequestHandler() {} - - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h index 2a7884b..e222fef 100644 --- a/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h +++ b/src/Core/RequestHandlers/GSSAPIAuthRequestHandler.h @@ -33,10 +33,11 @@ class GSSAPIAuthRequestHandler : public Common::RequestHandler { bool gssContinue, sentSignature; + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + public: GSSAPIAuthRequestHandler() : gssContext(GSS_C_NO_CONTEXT), gssContinue(true), sentSignature(false) {} - - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Core/RequestHandlers/IdentifyRequestHandler.h b/src/Core/RequestHandlers/IdentifyRequestHandler.h index 74ffd54..58f10ba 100644 --- a/src/Core/RequestHandlers/IdentifyRequestHandler.h +++ b/src/Core/RequestHandlers/IdentifyRequestHandler.h @@ -27,10 +27,11 @@ namespace Core { namespace RequestHandlers { class IdentifyRequestHandler : public Common::RequestHandler { + protected: + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); + public: IdentifyRequestHandler() {} - - virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); }; } diff --git a/src/Core/Requests/DaemonStatusRequest.cpp b/src/Core/Requests/DaemonStatusRequest.cpp index 86ef3c6..1741731 100644 --- a/src/Core/Requests/DaemonStatusRequest.cpp +++ b/src/Core/Requests/DaemonStatusRequest.cpp @@ -25,34 +25,17 @@ namespace Mad { namespace Core { namespace Requests { -bool DaemonStatusRequest::send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback) { - DaemonStatusRequest *request = new DaemonStatusRequest(); - - request->finished.connect(callback); - - if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) - return true; - - delete request; - return false; -} - -bool DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { - if(!connection->send(Net::Packet(Net::Packet::STATUS, requestId))) - return false; - - return true; +void DaemonStatusRequest::sendRequest(Net::Connection *connection, uint16_t requestId) { + connection->send(Net::Packet(Net::Packet::STATUS, requestId)); } void DaemonStatusRequest::handlePacket(Net::Connection*, const Net::Packet &packet) { if(packet.getType() != Net::Packet::OK) { - signalFinished().emit(); + finishWithError(Common::Exception(Common::Exception::UNEXPECTED_PACKET)); return; // TODO Logging } - finished(Net::Packets::HostStatusPacket(packet)); - - signalFinished().emit(); + finish(Net::Packets::HostStatusPacket(packet)); } } diff --git a/src/Core/Requests/DaemonStatusRequest.h b/src/Core/Requests/DaemonStatusRequest.h index ce6e4f7..baeb847 100644 --- a/src/Core/Requests/DaemonStatusRequest.h +++ b/src/Core/Requests/DaemonStatusRequest.h @@ -22,9 +22,6 @@ #include <Common/Request.h> -#include <string> -#include <sigc++/signal.h> - namespace Mad { namespace Net { @@ -36,17 +33,13 @@ class HostStatusPacket; namespace Core { namespace Requests { -class DaemonStatusRequest : public Common::Request { - private: - sigc::signal<void,const Net::Packets::HostStatusPacket&> finished; - - DaemonStatusRequest() {} +class DaemonStatusRequest : public Common::Request<Net::Packets::HostStatusPacket> { + protected: + virtual void sendRequest(Net::Connection *connection, uint16_t requestId); + virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet); public: - static bool send(Net::Connection *connection, const sigc::slot<void,const Net::Packets::HostStatusPacket&> &callback); - - virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); - virtual void handlePacket(Net::Connection*, const Net::Packet &packet); + DaemonStatusRequest(slot_type slot) : Common::Request<Net::Packets::HostStatusPacket>(slot) {} }; } |